1+ # Base image
2+ FROM node:20-alpine AS base
3+
4+ # ## Dependencies ###
5+ FROM base AS deps
6+ RUN apk add --no-cache libc6-compat git curl
7+
8+ # Setup pnpm environment
9+ ENV PNPM_HOME="/pnpm"
10+ ENV PATH="$PNPM_HOME:$PATH"
11+ RUN corepack enable
12+ RUN corepack prepare pnpm@latest --activate
13+
14+ WORKDIR /app
15+
16+ COPY package.json pnpm-lock.yaml ./
17+ RUN pnpm install --frozen-lockfile --prefer-frozen-lockfile
18+
19+ # Builder
20+ FROM base AS builder
21+
22+ WORKDIR /app
23+
24+ COPY . ./
25+ COPY --from=deps /app/node_modules ./node_modules
26+ RUN pnpm build
27+
128# ## Production image runner ###
229FROM base AS runner
330
4- # Install curl for healthcheck
5- RUN apk add --no-cache curl
31+ # Copy curl from deps stage
32+ COPY --from=deps /usr/bin/curl /usr/bin/ curl
633
734# Disable Next.js telemetry
835ENV NEXT_TELEMETRY_DISABLED 1
@@ -13,7 +40,7 @@ RUN adduser -SDH nextjs
1340RUN mkdir .next
1441RUN chown nextjs:nodejs .next
1542
16- # Automatically leverage output traces to reduce image size
43+ # Copy built app from builder stage
1744COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
1845COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
1946COPY --from=builder --chown=nextjs:nodejs /app/public ./public
@@ -24,7 +51,7 @@ USER nextjs
2451EXPOSE 3000
2552ENV PORT 3000
2653ENV HOSTNAME "0.0.0.0"
27- HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 CMD [ "curl" , "-f" , "http://localhost:3000/health" ]
54+ HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 CMD ["curl" , "-f" , "http://localhost:3000/health" ]
2855
29- # Run the nextjs app
56+ # Run the next.js app
3057CMD ["node" , "server.js" ]
0 commit comments