Refactor Docker setup for Astro SSR application and Nginx reverse proxy
- Updated docker-compose.yml to define services for the Astro SSR application and Nginx reverse proxy, including health checks and environment variables. - Modified Dockerfile to implement a multi-stage build process, optimizing dependency installation and production setup. - Enhanced nginx.conf with improved proxy settings, security headers, and caching strategies for static assets, ensuring better performance and security.
This commit is contained in:
35
Dockerfile
35
Dockerfile
@@ -1,17 +1,40 @@
|
||||
# Multi-stage build for Astro SSR application
|
||||
FROM node:lts AS base
|
||||
WORKDIR /app
|
||||
|
||||
# Install dependencies
|
||||
FROM base AS deps
|
||||
COPY package*.json ./
|
||||
RUN npm install
|
||||
RUN npm ci --only=production
|
||||
|
||||
# Build stage
|
||||
FROM base AS build
|
||||
COPY --from=deps /app/node_modules ./node_modules
|
||||
COPY package*.json ./
|
||||
RUN npm ci
|
||||
COPY . .
|
||||
RUN npm run build
|
||||
|
||||
FROM nginx:stable-alpine AS deploy
|
||||
COPY --from=build /app/dist /usr/share/nginx/html
|
||||
COPY ./nginx/nginx.conf /etc/nginx/nginx.conf
|
||||
# Production stage
|
||||
FROM node:lts-alpine AS production
|
||||
WORKDIR /app
|
||||
|
||||
EXPOSE 8080
|
||||
# Copy necessary files
|
||||
COPY --from=deps /app/node_modules ./node_modules
|
||||
COPY --from=build /app/dist ./dist
|
||||
COPY --from=build /app/server.js ./server.js
|
||||
COPY --from=build /app/package.json ./package.json
|
||||
COPY --from=build /app/.env ./.env
|
||||
|
||||
# Set environment
|
||||
ENV NODE_ENV=production
|
||||
ENV PORT=3000
|
||||
|
||||
# Expose port
|
||||
EXPOSE 3000
|
||||
|
||||
# Health check
|
||||
HEALTHCHECK --interval=30s --timeout=3s --start-period=40s \
|
||||
CMD node -e "require('http').get('http://localhost:3000/', (r) => {if (r.statusCode !== 200) throw new Error(r.statusCode)})"
|
||||
|
||||
# Start server
|
||||
CMD ["node", "server.js"]
|
||||
|
||||
Reference in New Issue
Block a user