# Stage 1: Install dependencies FROM node:20-alpine AS deps WORKDIR /app COPY package.json package-lock.json* ./ RUN npm ci --prefer-offline 2>/dev/null || npm install # Stage 2: Build the static export FROM node:20-alpine AS builder WORKDIR /app COPY --from=deps /app/node_modules ./node_modules COPY . . # Build environment variables (Stripe checkout URLs) ARG NEXT_PUBLIC_STRIPE_STARTER_URL ARG NEXT_PUBLIC_STRIPE_PRO_URL ENV NEXT_PUBLIC_STRIPE_STARTER_URL=$NEXT_PUBLIC_STRIPE_STARTER_URL ENV NEXT_PUBLIC_STRIPE_PRO_URL=$NEXT_PUBLIC_STRIPE_PRO_URL RUN npm run build # Stage 3: Serve with nginx FROM nginx:alpine AS runner COPY --from=builder /app/out /usr/share/nginx/html # Custom nginx config for SPA routing RUN printf 'server {\n\ listen 80;\n\ server_name _;\n\ root /usr/share/nginx/html;\n\ index index.html;\n\ \n\ location / {\n\ try_files $uri $uri.html $uri/ /index.html;\n\ }\n\ \n\ # Cache static assets\n\ location /_next/static/ {\n\ expires 1y;\n\ add_header Cache-Control "public, immutable";\n\ }\n\ \n\ # Security headers\n\ add_header X-Frame-Options "SAMEORIGIN" always;\n\ add_header X-Content-Type-Options "nosniff" always;\n\ add_header Referrer-Policy "strict-origin-when-cross-origin" always;\n\ }\n' > /etc/nginx/conf.d/default.conf EXPOSE 80 CMD ["nginx", "-g", "daemon off;"]