Skip to content

Commit 3ce748f

Browse files
committed
docs(images): a RUN in a runtime stage runs emulated on arm64 (MAG-5366)
Both Dockerfiles, the build workflow and CLAUDE.md said a RUN in a runtime stage fails on arm64 with "exec format error". The zlib upgrade is such a RUN and the arm64 half of each image built with it: BuildKit's image carries buildkit-qemu-aarch64 and runs the step under it, in 1.4 s and 2.2 s against 0.4 s and 0.6 s on amd64. The four places now say what happens and what the rule is for: build work stays in the build stage because it runs several times slower emulated.
1 parent c97498e commit 3ce748f

4 files changed

Lines changed: 17 additions & 12 deletions

File tree

‎.github/workflows/build-and-push.yml‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,10 @@ jobs:
130130
echo "version=$VERSION" >> $GITHUB_OUTPUT
131131
echo "major_minor=$MAJOR_MINOR" >> $GITHUB_OUTPUT
132132
133-
# No QEMU: both Dockerfiles build on $BUILDPLATFORM and keep their runtime
134-
# stages free of RUN. A RUN added to a runtime stage fails here on arm64
135-
# with "exec format error".
133+
# No QEMU step: both Dockerfiles do their build work on $BUILDPLATFORM.
134+
# A RUN in a runtime stage runs once per architecture, the arm64 one
135+
# under the emulator this BuildKit image carries (buildkit-qemu-aarch64),
136+
# several times slower than native.
136137
- name: Set up Docker Buildx
137138
uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1
138139
# Pinned to what the runner image shipped (buildx) and what the

‎CLAUDE.md‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,8 +1241,10 @@ Compose / Makefile knobs:
12411241
`$BUILDPLATFORM` (plain-JS output; the api has no native module, and the
12421242
web never loads sharp, which `images.unoptimized` in `next.config.mjs`
12431243
pins and the web Dockerfile removes from the standalone output) and keeps
1244-
its runtime stage free of `RUN`, so a `linux/amd64,linux/arm64` build
1245-
compiles once and the workflow sets up no QEMU. Layers go lockfile +
1244+
build work out of its runtime stage, so a `linux/amd64,linux/arm64` build
1245+
compiles once, natively, and the workflow sets up no QEMU. The runtime
1246+
stage's one `RUN`, the zlib upgrade, runs on arm64 under the emulator
1247+
BuildKit's image carries, in a second or two. Layers go lockfile +
12461248
package manifests → `pnpm install` → sources, so a code-only commit
12471249
reuses the install layer. The layer cache lives on GHCR
12481250
(`type=registry`): main writes `…/<image>:buildcache`, a branch writes
@@ -1289,6 +1291,6 @@ Compose / Makefile knobs:
12891291
| Endpoint URLs | `localhost:<port>` comes from SR_CONFIG's listen ports, gateway hostnames from helm values' `publicUrls` — a mount never has both. Anything that renders or dials an endpoint address must resolve public → local → `—` (`epHttpUrl` / `epWsUrl` in `components/endpoints/bits.tsx`), never hardcode `localhost`. |
12901292
| Health words | `HealthState` has exactly four states and exactly one wording — `lib/health.ts` / `<HealthTag>`. A panel that maps health to its own labels/colours is a bug, even when the words look nicer locally: the same upstream is read across panels. |
12911293
| BuildKit cache | `make build*` targets use the isolated `srdash-builder` (see Docker / images / isolation). Plain `docker compose up --build` is fine for the stack itself. |
1292-
| `RUN` in a runtime stage | CI builds the arm64 half of each image without QEMU, so a `RUN` in a Dockerfile's runtime stage fails there with `exec format error`. Do the work in the build stage and `COPY --from=builder`. A runtime break on arm64 (a dependency that loads a native binding at boot) shows up in the `smoke-arm64` job instead. |
1294+
| `RUN` in a runtime stage | It runs once per architecture, the arm64 one under the emulator BuildKit's image carries (the workflow sets up no QEMU), several times slower than native: `next build` takes about five minutes there against under one. Do build work in the build stage and `COPY --from=builder`; a `RUN` in a runtime stage is for a package step of a second or two, like the zlib upgrade. A runtime break on arm64 (a dependency that loads a native binding at boot) shows up in the `smoke-arm64` job instead. |
12931295
| Pinned versions | Every version is exact: package.json, `overrides` in `pnpm-workspace.yaml`, actions by commit SHA, and images by tag plus digest. pnpm is pinned by `packageManager` (CI's `pnpm/setup` reads it; the lockfile's first document records each platform binary's sha512) and by the `ghcr.io/pnpm/pnpm` stage in the three Dockerfiles. A Docker build fails when those two differ (`pnpm_config_pm_on_fail=error`), so move them together. The quality gate's "pins agree" step (`apps/web/scripts/check-pins.mjs`) fails when `.nvmrc` or `packageManager` disagrees with any Dockerfile FROM: Dependabot moves only the Dockerfiles (one PR per image across all three), so its Node or pnpm PR goes green once the same PR moves `.nvmrc` or `packageManager`. It proposes no major of Node, the pnpm image or `@types/node` (`ignore` in `.github/dependabot.yml`); those are migrations done by hand. No corepack: Node 26 does not ship it, and pnpm does not use it. pnpm only reads its settings from `pnpm-workspace.yaml` (the `pnpm` field in package.json and non-auth `.npmrc` keys are ignored), and a package with an install script that is not listed in `allowBuilds` fails the install. There is no minimum release age (`minimumReleaseAge: 0`; Dependabot has no cooldown). `pnpm install` refuses a release published with weaker evidence than the package's earlier releases (`ERR_PNPM_TRUST_DOWNGRADE`). Don't get around that with a `^` range or a `--config` flag: add the package to `trustPolicyExclude` in `pnpm-workspace.yaml` with its reason. A new override or dependency goes in as an exact version, and a new `uses:` or image as a SHA or digest. See README → Testing & CI. |
12941296
| Image `files` whitelist | The api image ships only what each package's `files` lists (`apps/api`: `dist`; `packages/db`: `dist` + `migrations`; `packages/shared`: `dist`). A runtime asset anywhere else (a template, a file read with `fs`) works in dev and fails only in the published image — put it under `dist` or add it to `files`. |

‎apps/api/Dockerfile‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,10 @@ RUN pnpm --filter @sr/shared build && \
4242
# No devDependencies, so NODE_ENV=development (pino-pretty transport) can't boot.
4343
RUN pnpm --filter @sr/api deploy --prod /app/deploy
4444

45-
# Runtime stage, built once per target architecture. Keep it free of RUN:
46-
# the CI builder has no QEMU, so a RUN here fails on arm64 with "exec format
47-
# error". COPY, ENV, USER and CMD need no emulation.
45+
# Runtime stage, built once per target architecture. A RUN here runs on
46+
# arm64 under the emulator BuildKit's image carries, several times slower
47+
# than native, so build work belongs in the build stage. COPY, ENV, USER and
48+
# CMD need no emulation.
4849
FROM node:26.13.1-alpine@sha256:6bd9ab43c0ec0190ca7b2d193906cb8b7edf6e7f4afa43ddeccd6452710bffb5
4950
WORKDIR /app
5051
# zlib 1.4-r0 fixes CVE-2026-4738. The base image still ships 1.3.2-r1 and

‎apps/web/Dockerfile‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,10 @@ RUN pnpm --filter @sr/shared build && \
4444
RUN cd apps/web/.next/standalone/node_modules/.pnpm && \
4545
rm -rf sharp@* @img+* node_modules/sharp node_modules/@img next@*/node_modules/sharp
4646

47-
# Runtime stage, built once per target architecture. Keep it free of RUN:
48-
# the CI builder has no QEMU, so a RUN here fails on arm64 with "exec format
49-
# error". COPY, ENV, USER and CMD need no emulation.
47+
# Runtime stage, built once per target architecture. A RUN here runs on
48+
# arm64 under the emulator BuildKit's image carries, several times slower
49+
# than native, so build work belongs in the build stage. COPY, ENV, USER and
50+
# CMD need no emulation.
5051
FROM node:26.13.1-alpine@sha256:6bd9ab43c0ec0190ca7b2d193906cb8b7edf6e7f4afa43ddeccd6452710bffb5
5152
WORKDIR /app
5253
# zlib 1.4-r0 fixes CVE-2026-4738. The base image still ships 1.3.2-r1 and

0 commit comments

Comments
 (0)