-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
72 lines (56 loc) · 2.33 KB
/
Copy pathDockerfile
File metadata and controls
72 lines (56 loc) · 2.33 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
60
61
62
63
64
65
66
67
68
69
70
71
72
# Stage 0: Base
FROM node:20 AS base
WORKDIR /app
ENV NODE_OPTIONS="--max-old-space-size=4096"
# Install Node 25.3.0 (download official binary; the `n` npm package was
# replaced by a security-holding placeholder and no longer works)
RUN wget -qO- https://nodejs.org/dist/v25.3.0/node-v25.3.0-linux-x64.tar.gz | tar xz -C /usr/local --strip-components=1 \
&& node --version
# Enable Corepack and activate pnpm
RUN corepack enable && corepack prepare pnpm@latest --activate
# Copy package manifests first (for layer caching)
COPY package.json .
COPY pnpm-lock.yaml .
COPY pnpm-workspace.yaml .
# Install dependencies
RUN pnpm install --frozen-lockfile
# Stage 1: Builder
FROM base AS builder
ARG APP_VERSION
# Immutable static hosting: when NEXT_PUBLIC_ASSET_CDN is passed, /_next/* assets
# are emitted under <cdn>/apps/<NEXT_PUBLIC_APP_NAME>/<APP_VERSION>/. Unset → the
# build is unchanged (assets served from the app as before).
ARG NEXT_PUBLIC_ASSET_CDN
ARG NEXT_PUBLIC_APP_NAME
ENV NEXT_PUBLIC_ASSET_CDN=$NEXT_PUBLIC_ASSET_CDN
ENV NEXT_PUBLIC_APP_NAME=$NEXT_PUBLIC_APP_NAME
ENV APP_VERSION=$APP_VERSION
ENV NODE_OPTIONS="--max-old-space-size=4096"
COPY . .
# Override version in package.json if APP_VERSION is provided
RUN if [ -n "$APP_VERSION" ]; then \
sed -i "s/\"version\": \"[^\"]*\"/\"version\": \"$APP_VERSION\"/" package.json; \
fi
RUN pnpm run build
# Stage 2: Runner
FROM node:20-alpine AS runner
WORKDIR /app
# Install Node 25.3.0 (download official musl binary for Alpine)
RUN apk add --no-cache libstdc++ \
&& wget -qO- https://unofficial-builds.nodejs.org/download/release/v25.3.0/node-v25.3.0-linux-x64-musl.tar.gz | tar xz -C /usr/local --strip-components=1 \
&& node --version
# Enable Corepack and activate pnpm
RUN corepack enable && corepack prepare pnpm@latest --activate
# Copy built app artifacts
COPY --from=builder /app/.next .next
COPY --from=builder /app/public ./public
COPY --from=builder /app/package.json ./package.json
COPY --from=builder /app/next.config.mjs ./next.config.mjs
COPY --from=builder /app/entrypoint.sh ./entrypoint.sh
# Ensure Next.js and dependencies are available during runtime
COPY --from=builder /app/node_modules ./node_modules
# Make entrypoint executable
RUN chmod +x ./entrypoint.sh
EXPOSE 5000
ENTRYPOINT ["./entrypoint.sh"]
CMD ["pnpm", "exec", "next", "start", "-p", "5000"]