Spaces:
No application file
No application file
| # ============================================================== | |
| # OPTIM AI BRE Engine — Frontend Dockerfile | |
| # Next.js 14 standalone multi-stage production build | |
| # ============================================================== | |
| # ---- STAGE 1: BASE ------------------------------------------- | |
| FROM node:20-alpine AS base | |
| RUN apk add --no-cache libc6-compat | |
| WORKDIR /app | |
| # ---- STAGE 2: DEPENDENCIES ----------------------------------- | |
| FROM base AS deps | |
| COPY package.json package-lock.json* ./ | |
| # Install ALL deps (including dev) — needed for build | |
| RUN npm ci --ignore-scripts && \ | |
| npm cache clean --force | |
| # ---- STAGE 3: BUILD ------------------------------------------ | |
| FROM base AS builder | |
| WORKDIR /app | |
| COPY --from=deps /app/node_modules ./node_modules | |
| COPY . . | |
| # NEXT_PUBLIC_API_URL is baked at build time. | |
| # /api/v1 is a relative URL — Nginx proxies it to the backend container. | |
| # This means the same Docker image works for any domain or server IP. | |
| ARG NEXT_PUBLIC_API_URL=/api/v1 | |
| ENV NEXT_PUBLIC_API_URL=$NEXT_PUBLIC_API_URL \ | |
| NEXT_TELEMETRY_DISABLED=1 \ | |
| NODE_ENV=production | |
| RUN npm run build | |
| # ---- STAGE 4: RUNNER ----------------------------------------- | |
| FROM node:20-alpine AS runner | |
| WORKDIR /app | |
| RUN apk add --no-cache wget | |
| ENV NODE_ENV=production \ | |
| NEXT_TELEMETRY_DISABLED=1 \ | |
| PORT=3000 \ | |
| HOSTNAME="0.0.0.0" | |
| RUN addgroup --system --gid 1001 nodejs && \ | |
| adduser --system --uid 1001 nextjs | |
| # Copy Next.js standalone output | |
| COPY --from=builder /app/public ./public | |
| RUN mkdir -p .next && chown nextjs:nodejs .next | |
| COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ | |
| COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static | |
| USER nextjs | |
| EXPOSE 3000 | |
| HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \ | |
| CMD wget -qO- http://localhost:3000/api/health || exit 1 | |
| CMD ["node", "server.js"] | |