feat: replace Node.js production server with NGINX for static file serving
This commit is contained in:
parent
9e7409c281
commit
858846ad2e
35
Dockerfile
35
Dockerfile
@ -1,5 +1,5 @@
|
|||||||
# Dockerfile for Astro webapp
|
# Dockerfile for Astro webapp with NGINX for production
|
||||||
# Use official Node.js image as the base
|
# Stage 1: Build the Astro application
|
||||||
FROM node:20-alpine as build
|
FROM node:20-alpine as build
|
||||||
|
|
||||||
# Set working directory
|
# Set working directory
|
||||||
@ -15,20 +15,25 @@ COPY . .
|
|||||||
# Build the Astro project
|
# Build the Astro project
|
||||||
RUN npm run build
|
RUN npm run build
|
||||||
|
|
||||||
# Production image
|
# Stage 2: Serve with NGINX
|
||||||
FROM node:20-alpine as prod
|
FROM nginx:alpine
|
||||||
WORKDIR /app
|
|
||||||
|
|
||||||
# Install only production dependencies
|
# Copy built static files from build stage to NGINX html directory
|
||||||
COPY package.json package-lock.json ./
|
COPY --from=build /app/dist /usr/share/nginx/html
|
||||||
RUN npm ci --omit=dev
|
|
||||||
|
|
||||||
# Copy built files from build stage
|
# Add custom NGINX configuration if needed
|
||||||
COPY --from=build /app/dist ./dist
|
RUN echo 'server {\
|
||||||
COPY public ./public
|
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 port 80
|
||||||
EXPOSE 4321
|
EXPOSE 80
|
||||||
|
|
||||||
# Start the Astro preview server
|
# Start NGINX
|
||||||
CMD ["npx", "astro", "preview", "--host"]
|
CMD ["nginx", "-g", "daemon off;"]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user