This commit is contained in:
2025-09-10 11:46:57 -07:00
parent 1c69424fff
commit ca8798848e
33 changed files with 887 additions and 1467 deletions

View File

@@ -1,39 +1,60 @@
# Build stage
FROM node:20-alpine AS build
# Stage 1: Build application
FROM node:20-alpine AS builder
# Set working directory
WORKDIR /app
# Copy package.json and package-lock.json
COPY package*.json ./
# Copy package manifests first for optimal caching
COPY package.json package-lock.json* ./
# Install all dependencies including devDependencies
RUN npm install --include=dev
# Clean cache and install dependencies
RUN npm cache clean --force && \
export NODE_OPTIONS="--max-old-space-size=1024" && \
npm install --include=dev
# Copy source code
# Copy source files
COPY . .
# Build application
RUN npm run build
# Build application with production settings
RUN export NODE_OPTIONS="--max-old-space-size=1024" && \
npm run build
# Production stage
FROM node:20-alpine AS production
# Stage 2: Production runtime
FROM nginx:1.25-alpine
# Set working directory
WORKDIR /app
# Install curl for healthchecks
RUN apk add --no-cache curl
# Copy build artifacts and dependencies
COPY --from=build /app/package*.json ./
COPY --from=build /app/.next ./.next
COPY --from=build /app/node_modules ./node_modules
COPY --from=build /app/public ./public
# Create necessary directories and set permissions
RUN mkdir -p /var/cache/nginx/client_temp && \
mkdir -p /var/run/nginx && \
chown -R nginx:nginx /usr/share/nginx/html && \
chown -R nginx:nginx /var/cache/nginx && \
chown -R nginx:nginx /var/run/nginx && \
chmod -R 755 /usr/share/nginx/html
# Create non-root user
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
USER appuser
# Copy build artifacts
COPY --from=builder /app/.next /usr/share/nginx/html/_next
# Expose application port
EXPOSE 3000
# Copy nginx configuration
COPY nginx.conf /etc/nginx/nginx.conf
# Run application
CMD ["npm", "start"]
# Copy Next.js routes manifest for proper routing
COPY --from=builder /app/.next/routes-manifest.json /usr/share/nginx/html/_next/
# Copy main HTML files to root
COPY --from=builder /app/.next/server/pages/index.html /usr/share/nginx/html/index.html
COPY --from=builder /app/.next/server/pages/404.html /usr/share/nginx/html/404.html
# Modify nginx config to use custom PID path
RUN sed -i 's|pid /var/run/nginx.pid;|pid /var/run/nginx/nginx.pid;|' /etc/nginx/nginx.conf
# Healthcheck
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD curl --fail http://localhost:80 || exit 1
# Run as root to avoid permission issues
# USER nginx
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]