|
| 1 | +# Use a minimal Node.js Alpine base |
| 2 | +FROM node:lts-alpine AS base |
1 | 3 |
|
2 | | -FROM node:lts-alpine3.19 AS frontend |
3 | | - |
4 | | -FROM frontend AS frontend-deps |
5 | | - |
| 4 | +# Dependencies Layer |
| 5 | +FROM base AS frontend-deps |
6 | 6 | WORKDIR /app |
7 | 7 | RUN apk add --no-cache libc6-compat |
8 | 8 |
|
9 | 9 | COPY package.json package-lock.json ./ |
10 | | -RUN npm ci -f |
11 | | - |
12 | | -FROM frontend AS frontend-builder |
| 10 | +RUN npm ci --only=production --no-audit --no-fund |
13 | 11 |
|
| 12 | +# Build Layer |
| 13 | +FROM base AS frontend-builder |
14 | 14 | WORKDIR /app |
15 | 15 | COPY --from=frontend-deps /app/node_modules ./node_modules |
16 | | -COPY . . |
| 16 | +COPY . . |
17 | 17 |
|
| 18 | +ENV NODE_ENV=production |
18 | 19 | ENV NEXT_PUBLIC_API_URL=$API_URL |
19 | 20 | ENV NEXT_PUBLIC_TYPST_COMPILER_URL=/typst-compiler.wasm |
20 | 21 | ENV NEXT_PUBLIC_TYPST_RENDERER_URL=/typst-renderer.wasm |
21 | | - |
22 | | -ENV NODE_ENV=production |
23 | 22 | ENV NEXT_TELEMETRY_DISABLED=1 |
24 | | -RUN npm run build |
25 | 23 |
|
26 | 24 |
|
27 | | -FROM node:22-alpine AS runner |
| 25 | +RUN npm run build |
28 | 26 |
|
| 27 | +# Final Runner Stage (Minimal Size) |
| 28 | +FROM base AS runner |
29 | 29 | WORKDIR /app |
30 | 30 |
|
31 | | -# 8. Copy the built application from the builder stage |
32 | | -COPY --from=frontend-builder /app/.next ./.next |
| 31 | +# Copy only necessary files to avoid rebuilds |
| 32 | +# COPY --from=frontend-builder /app/.next ./.next |
| 33 | +# COPY --from=frontend-builder /app/public ./public |
| 34 | +# COPY --from=frontend-builder /app/package.json ./package.json |
| 35 | + |
33 | 36 | COPY --from=frontend-builder /app/public ./public |
34 | | -COPY --from=frontend-builder /app/package.json /app/package-lock.json ./ |
| 37 | +COPY --from=frontend-builder /app/.next/standalone ./ |
| 38 | +COPY --from=frontend-builder /app/.next/static ./.next/static |
35 | 39 |
|
36 | | -RUN npm install --only=production --force |
37 | | -# 9. Expose the port Next.js runs on |
38 | | -EXPOSE 3000 |
| 40 | +# RUN npm i next@15.2 |
| 41 | +# COPY --from=frontend-deps /app/node_modules ./node_modules |
39 | 42 |
|
40 | | -# 10. Run the Next.js application |
41 | | -CMD ["npm", "run", "start"] |
| 43 | +# Ensure we don't rebuild on start |
| 44 | +ENV NODE_ENV=production |
| 45 | + |
| 46 | +EXPOSE 3000 |
| 47 | +CMD ["node", "server.js"] |
0 commit comments