Skip to content

build(docker): build JavaScript natively, only the runtime image per target - #212

Merged
clbotdev merged 1 commit into
mainfrom
build/docker-native-js
Nov 21, 2026
Merged

clbotdev merged 1 commit into
mainfrom
build/docker-native-js

Conversation

@clbotdev

Copy link
Copy Markdown
Contributor

What

The install and build stages now run on $BUILDPLATFORM (FROM --platform=$BUILDPLATFORM): the web builder and the API packages stage. Before, the release workflow's linux/amd64,linux/arm64 build ran them under QEMU for the non-native platform. Their output is JavaScript, the same for every target. These still run as the target platform:

  • the web runtime stage
  • the API runner, including its production bun install (msgpackr-extract, sharp)

sharp is the one native module in the web app's standalone output. The build stage fetches its binaries for the target platform at the lockfile's version (bun install --os=linux --libc=musl --cpu=<x64|arm64>). The runtime stage copies them beside each traced copy of sharp. musl is needed because the runner is node:24-alpine and the builder is Debian: without --libc=musl, bun fetches only the glibc arm64 binary and sharp fails to load.

Verification (local, x86_64 host, --no-cache)

Image arm64 before arm64 after
web 912 s 95 s
api 441 s 110 s
  • In the arm64 web image, the traced sharp loads under node and renders a PNG.
  • In the amd64 web image, the same check passes.
  • The arm64 API image has arm64 native modules from its target-platform production install.
  • publish-docker-image.yaml needs no change. buildx sets BUILDPLATFORM/TARGETARCH, and the build stages are shared by both platforms.

Not verified: an actual push through the GitHub Actions workflow (no images were published), or booting the API against a database.

…target

Cross-platform images were built entirely under QEMU emulation, so an
arm64 image built on an x86 machine (or the reverse) ran every install and
build emulated. Install and build stages now run on $BUILDPLATFORM: their
output is JavaScript, identical for every target. Only the runtime stages,
and the API's production install, run as the target platform.

sharp is the one native module in Next's standalone output: the web build
stage fetches its binaries for the target (bun install --os/--cpu/--libc, at
the lockfile's version; musl because the runner is Alpine) and the runtime
stage places them beside each traced copy of sharp.
@clbotdev
clbotdev merged commit 77dbf94 into main Nov 21, 2026
5 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants