# ---- Stage 1: Build Next.js static export ---- FROM node:22-slim AS frontend-builder WORKDIR /app # Install pnpm RUN corepack enable # Install build essentials for native deps RUN apt-get update -qq && apt-get install -y -qq --no-install-recommends \ python3 make g++ && rm -rf /var/lib/apt/lists/* # Copy dependency manifests first for layer caching COPY services/frontend/package.json services/frontend/pnpm-lock.yaml* ./services/frontend/ COPY services/frontend/tsconfig.json ./services/frontend/tsconfig.json # Install frontend dependencies (standalone, no shared workspace dep) RUN --mount=type=cache,id=pnpm-store,target=/root/.local/share/pnpm/store \ cd services/frontend && pnpm install --no-frozen-lockfile # Copy source code COPY services/frontend/ ./services/frontend/ # Pass API/WS URLs as build args ARG VITE_BE_API_URL ARG VITE_BE_WS_URL ENV VITE_BE_API_URL=${VITE_BE_API_URL} ENV VITE_BE_WS_URL=${VITE_BE_WS_URL} # Build frontend static export RUN --mount=type=cache,id=pnpm-store,target=/root/.local/share/pnpm/store \ cd services/frontend && pnpm run build # ---- Stage 2: Nginx ---- FROM nginx:alpine # Nginx config (API/WS proxy + static file serving) COPY infra/docker/nginx/nginx.conf /etc/nginx/conf.d/default.conf # Static export from frontend builder COPY --from=frontend-builder /app/services/frontend/out/ /usr/share/nginx/html/ EXPOSE 80 HEALTHCHECK --interval=30s --timeout=3s --start-period=10s --retries=3 \ CMD wget -qO- http://localhost:80/ || exit 1 CMD ["nginx", "-g", "daemon off;"]