Consumer: Build and publish multi-arch Docker images
This task is to re-engineer our Docker image build process to produce and publish multi-platform images, ensuring native performance and compatibility for users on different CPU architectures.
The Problem
Our current build process, orchestrated by scripts/build_sandbox.js, creates a Docker image for a single architecture (the architecture of the machine running the build). This creates a significant problem for the growing number of users on non-x86 hardware, particularly developers using Apple Silicon (ARM64) machines.
When an amd64 image is run on an arm64 host, Docker must use QEMU for emulation, which is often slow and can introduce subtle bugs. This results in a poor user experience for a large segment of our developer community.
Why Multi-Arch Images Matter
A multi-arch image (also known as a "fat manifest") is a single image tag (e.g., my-image:latest) that points to a list of platform-specific image layers. When a user runs docker pull my-image:latest, Docker automatically selects and pulls the image variant that matches their native architecture. This provides:
- Native Performance: No emulation is required, so the container runs at full speed.
- Seamless User Experience: Users don't need to think about architectures or use special tags. It just works.
- Future-Proofing: As more hardware moves to ARM, having a multi-arch build process is essential.
Recommended Approach
We will use docker buildx, the official Docker tool for multi-platform builds.
- Integrate
docker buildx: Thescripts/build_sandbox.jsscript (or the CI workflow that calls it) must be updated to usedocker buildx buildinstead of the standarddocker build. - Specify Target Platforms: The build command must include the
--platformflag to specify all target architectures. We should start withlinux/amd64andlinux/arm64. - Push the Manifest: The
buildxcommand must include the--pushflag, which builds the images for all platforms and pushes them to the registry under a single manifest list.
Example Command:
docker buildx build \
--platform linux/amd64,linux/arm64 \
-t my-registry/my-image:latest \
--push .
This change will make our sandbox feature faster, more reliable, and accessible to all of our users, regardless of their hardware.
Further Reading: