feat: replace Node.js production server with NGINX for static file serving

This commit is contained in:
greg 2025-05-21 23:31:44 +02:00
parent 9e7409c281
commit 858846ad2e

View File

@ -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;"]