FROM node:20-alpine AS base # --- Dependencies --- FROM base AS deps WORKDIR /app COPY package.json package-lock.json* ./ # Use `npm install` (not `npm ci`) — gitgram/web is an npm-workspace member, so its # standalone lockfile can drift from package.json; install tolerates that and resolves # the full dependency tree for the isolated image build. RUN npm install --ignore-scripts --no-audit --no-fund # --- Builder --- FROM base AS builder WORKDIR /app COPY --from=deps /app/node_modules ./node_modules COPY . . ENV NEXT_TELEMETRY_DISABLED=1 RUN npm run build # --- Production --- FROM base AS runner WORKDIR /app ENV NODE_ENV=production ENV NEXT_TELEMETRY_DISABLED=1 ENV PORT=3000 ENV HOSTNAME="0.0.0.0" RUN addgroup --system --gid 1001 nodejs && \ adduser --system --uid 1001 nextjs COPY --from=builder /app/public ./public 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=5s --start-period=10s --retries=3 \ CMD wget -qO- http://localhost:3000/ || exit 1 CMD ["node", "server.js"]