From 858846ad2e31ed09cfbd60fa4d36cbfa39fa6277 Mon Sep 17 00:00:00 2001 From: greg Date: Wed, 21 May 2025 23:31:44 +0200 Subject: [PATCH] feat: replace Node.js production server with NGINX for static file serving --- Dockerfile | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/Dockerfile b/Dockerfile index 9779fba..c770ee8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ -# Dockerfile for Astro webapp -# Use official Node.js image as the base +# Dockerfile for Astro webapp with NGINX for production +# Stage 1: Build the Astro application FROM node:20-alpine as build # Set working directory @@ -15,20 +15,25 @@ COPY . . # Build the Astro project RUN npm run build -# Production image -FROM node:20-alpine as prod -WORKDIR /app +# Stage 2: Serve with NGINX +FROM nginx:alpine -# Install only production dependencies -COPY package.json package-lock.json ./ -RUN npm ci --omit=dev +# Copy built static files from build stage to NGINX html directory +COPY --from=build /app/dist /usr/share/nginx/html -# Copy built files from build stage -COPY --from=build /app/dist ./dist -COPY public ./public +# Add custom NGINX configuration if needed +RUN echo 'server {\ + listen 80;\ + server_name _;\ + root /usr/share/nginx/html;\ + index index.html;\ + location / {\ + try_files $uri $uri/ /index.html;\ + }\ +}' > /etc/nginx/conf.d/default.conf -# Expose Astro's default port -EXPOSE 4321 +# Expose port 80 +EXPOSE 80 -# Start the Astro preview server -CMD ["npx", "astro", "preview", "--host"] +# Start NGINX +CMD ["nginx", "-g", "daemon off;"]