Skip to content

Commit e2d5742

Browse files
committed
fix(showcase/shell-docs): Dockerfile hygiene (ARG scope, npm ci, .dockerignore, direct next binary)
- Re-declare COMMIT_SHA and BRANCH ARGs in the runner stage so ENV interpolation resolves (ARGs do not cross stages in multi-stage builds). - Declare NEXT_PUBLIC_BASE_URL as a build-time ARG/ENV so CI can pass it via --build-arg for the production `next build` (next.config.ts requires it). - Copy lockfile for shell-docs and switch to `npm ci` for reproducible installs. scripts/ has no committed lockfile yet, so keep `npm install` there. - Add .dockerignore so local .next/, node_modules/, .git, logs, and .env* are not slurped into the build context. - Invoke next via node_modules/.bin/next (both build and CMD) instead of npx to avoid runtime network-fallback risk. - Document the required build context at the top of the Dockerfile. - Note the libc6-compat discussion: the slim base is Debian (glibc), so no compat shim is required; note how to enable it if we ever move to node:20-alpine.
1 parent 9ed2f9f commit e2d5742

2 files changed

Lines changed: 39 additions & 7 deletions

File tree

showcase/shell-docs/.dockerignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
node_modules
2+
.next
3+
.git
4+
dist
5+
build
6+
coverage
7+
*.log
8+
.env
9+
.env.local
10+
.env.*.local
11+
.DS_Store

showcase/shell-docs/Dockerfile

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,30 @@
1+
# Build from repo root: docker build -f showcase/shell-docs/Dockerfile .
2+
# The build context MUST be the repository root; this Dockerfile copies from
3+
# showcase/scripts, showcase/shared, showcase/packages, and showcase/shell-docs.
4+
15
FROM node:20-slim AS builder
26
ARG COMMIT_SHA=unknown
37
ARG BRANCH=unknown
8+
# NEXT_PUBLIC_BASE_URL is required at `next build` time (see next.config.ts).
9+
# Pass it via: docker build --build-arg NEXT_PUBLIC_BASE_URL=https://...
10+
ARG NEXT_PUBLIC_BASE_URL
11+
ENV NEXT_PUBLIC_BASE_URL=${NEXT_PUBLIC_BASE_URL}
412
WORKDIR /app
513

6-
# Copy only what shell-docs + scripts need
7-
COPY showcase/scripts/package.json ./scripts/package.json
8-
COPY showcase/shell-docs/package.json ./shell-docs/package.json
14+
# NOTE on SWC native bindings: Next.js recommends installing `libc6-compat`
15+
# on Alpine-based images so @next/swc-* native binaries load. We use
16+
# `node:20-slim` (Debian bookworm), which ships with glibc, so no compat
17+
# shim is required. If we ever switch to `node:20-alpine`, add:
18+
# RUN apk add --no-cache libc6-compat
19+
20+
# Copy manifests + lockfiles first for cached, reproducible installs.
21+
# showcase/scripts/ does not currently ship a lockfile; use `npm install`
22+
# there and `npm ci` for shell-docs, which does.
23+
COPY showcase/scripts/package.json ./scripts/
24+
COPY showcase/shell-docs/package.json showcase/shell-docs/package-lock.json ./shell-docs/
925

10-
# Install deps for both (standalone, no workspace)
11-
RUN cd scripts && npm install --silent && cd ../shell-docs && npm install --silent
26+
RUN cd scripts && npm install --silent \
27+
&& cd ../shell-docs && npm ci --silent
1228

1329
# Copy source
1430
COPY showcase/shared/ ./shared/
@@ -24,9 +40,13 @@ ENV NEXT_PUBLIC_BRANCH=${BRANCH}
2440
RUN cd scripts && node node_modules/tsx/dist/cli.mjs generate-registry.ts \
2541
&& node node_modules/tsx/dist/cli.mjs bundle-demo-content.ts \
2642
&& node node_modules/tsx/dist/cli.mjs generate-search-index.ts \
27-
&& cd ../shell-docs && npx next build
43+
&& cd ../shell-docs && node_modules/.bin/next build
2844

2945
FROM node:20-slim AS runner
46+
# Re-declare build args in this stage so ENV interpolation below resolves.
47+
# ARGs do not cross stages in multi-stage builds.
48+
ARG COMMIT_SHA=unknown
49+
ARG BRANCH=unknown
3050
WORKDIR /app
3151
ENV NODE_ENV=production
3252
ENV PORT=10000
@@ -40,4 +60,5 @@ COPY --from=builder /app/shell-docs/public ./public
4060
COPY --from=builder /app/shell-docs/src/content ./src/content
4161

4262
EXPOSE 10000
43-
CMD ["npx", "next", "start", "-p", "10000"]
63+
# Invoke next directly (no npx) to avoid runtime network fallback
64+
CMD ["node_modules/.bin/next", "start", "-p", "10000"]

0 commit comments

Comments
 (0)