|
| 1 | +# syntax=docker.io/docker/dockerfile:1 |
| 2 | + |
| 3 | +FROM node:22-alpine AS base |
| 4 | + |
| 5 | +# Install dependencies only when needed |
| 6 | +FROM base AS deps |
| 7 | +# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed. |
| 8 | +RUN apk add --no-cache libc6-compat |
| 9 | +WORKDIR /app |
| 10 | + |
| 11 | +# Install dependencies based on the preferred package manager |
| 12 | +COPY package.json package-lock.json* .npmrc* source.config.ts ./ |
| 13 | +RUN npm ci |
| 14 | + |
| 15 | +# Rebuild the source code only when needed |
| 16 | +FROM base AS builder |
| 17 | +WORKDIR /app |
| 18 | +COPY --from=deps /app/node_modules ./node_modules |
| 19 | +COPY . . |
| 20 | + |
| 21 | +# Next.js collects completely anonymous telemetry data about general usage. |
| 22 | +# Learn more here: https://nextjs.org/telemetry |
| 23 | +# Uncomment the following line in case you want to disable telemetry during the build. |
| 24 | +ENV NEXT_TELEMETRY_DISABLED=1 |
| 25 | + |
| 26 | +RUN npm run genapi |
| 27 | +# Build the Next.js app |
| 28 | +RUN npm run build |
| 29 | + |
| 30 | +# Production image, copy all the files and run next |
| 31 | +FROM base AS runner |
| 32 | +WORKDIR /app |
| 33 | + |
| 34 | +ENV NODE_ENV=production |
| 35 | +ENV NEXT_TELEMETRY_DISABLED=1 |
| 36 | + |
| 37 | +RUN addgroup --system --gid 1001 nodejs |
| 38 | +RUN adduser --system --uid 1001 nextjs |
| 39 | + |
| 40 | +COPY --from=builder /app/public ./public |
| 41 | + |
| 42 | +# Automatically leverage output traces to reduce image size |
| 43 | +# https://nextjs.org/docs/advanced-features/output-file-tracing |
| 44 | +COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ |
| 45 | +COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static |
| 46 | + |
| 47 | +USER nextjs |
| 48 | + |
| 49 | +EXPOSE 3500 |
| 50 | + |
| 51 | +ENV PORT=3500 |
| 52 | + |
| 53 | +# server.js is created by next build from the standalone output |
| 54 | +# https://nextjs.org/docs/pages/api-reference/config/next-config-js/output |
| 55 | +ENV HOSTNAME="0.0.0.0" |
| 56 | +CMD ["node", "server.js"] |
0 commit comments