-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDockerfile
More file actions
59 lines (47 loc) · 1.99 KB
/
Copy pathDockerfile
File metadata and controls
59 lines (47 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# syntax=docker/dockerfile:1.7
# Production Docker image for this Next.js app.
#
# Uses Next.js standalone output to produce a minimal runtime image (~100 MB
# instead of ~500 MB). The standalone server.js bundles only the dependencies
# it actually imports, so the prod-deps stage is no longer needed.
#
# Recommended build/run path:
# docker compose up -d --build
#
# Direct Docker build:
# docker build --secret id=app_env,src=.env -t sast-homepage-next .
# ---------------------------------------------------------------------------
# Stage 1 – install all dependencies (needed by the builder)
# ---------------------------------------------------------------------------
FROM node:22-alpine AS deps
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci
# ---------------------------------------------------------------------------
# Stage 2 – build the Next.js app (standalone output)
# ---------------------------------------------------------------------------
FROM node:22-alpine AS builder
WORKDIR /app
ENV NEXT_TELEMETRY_DISABLED=1
COPY --from=deps /app/node_modules ./node_modules
COPY . .
# .env is mounted as a BuildKit secret because /activities fetches Lark
# calendar data during `next build`.
RUN --mount=type=secret,id=app_env,target=/app/.env,required=true npm run build
# ---------------------------------------------------------------------------
# Stage 3 – minimal runtime image
# ---------------------------------------------------------------------------
FROM node:22-alpine AS runner
WORKDIR /app
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1
ENV HOSTNAME=0.0.0.0
ENV PORT=3000
# standalone/ contains server.js + an auto-traced minimal node_modules tree.
COPY --chown=node:node --from=builder /app/.next/standalone ./
# Static files are NOT bundled into standalone — copy them explicitly.
COPY --chown=node:node --from=builder /app/.next/static ./.next/static
COPY --chown=node:node --from=builder /app/public ./public
USER node
EXPOSE 3000
CMD ["node", "server.js"]