Skip to content

Instantly share code, notes, and snippets.

@pepyakin
Created January 3, 2024 16:05
Show Gist options
  • Save pepyakin/618fddce266f8dfd1c99d16c14967ec9 to your computer and use it in GitHub Desktop.
Save pepyakin/618fddce266f8dfd1c99d16c14967ec9 to your computer and use it in GitHub Desktop.
Multiarch risc0 container builds

We need to have risc0 available in docker containers. Modern macs are aarch64 machines. When you run docker on mac, a aarch64 VM will be used. It's possible to use x86-64, but those would run slower.

Unfortunately, risc0 binaries are not built for aarch64 linux. risc0/risc0#1286

There are two general approaches that I found.

Qemu system emulation

It's possible to use qemu for system emulation. I managed to build both on macOS and on nixOS.

docker buildx create --name builder-arm64-amd64 --use
# ↓ only required on nixOS to register qemu
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes

Then build the images with:

docker buildx build --platform linux/amd64,linux/arm64 -t ghcr.io/pepyakin/risczero --push -f docker/risczero.Dockerfile .

The downsides of this approach are:

  1. Obviously emulation is not the fastest,
  2. --mount=type=cache is not that useful since it will be shared between the both builds and a really coarse grained lock will be used. Although may be worked around with different assigning different paths.

Build two different images "natively" and then stitch the images together.

Another approach is to build the images on the native machines (arm64/linux on macOS and amd64/linux on linux), push those two images and then stitch them together.

docker manifest create ghcr.io/pepyakin/risczero:latest \
  ghcr.io/pepyakin/risczero:latest-arm64 \
  ghcr.io/pepyakin/risczero:latest-amd64

docker manifest annotate ghcr.io/pepyakin/risczero:latest \
  ghcr.io/pepyakin/risczero:latest-arm64 --arch arm64

docker manifest annotate ghcr.io/pepyakin/risczero:latest \
  ghcr.io/pepyakin/risczero:latest-amd64 --arch amd64

docker manifest push ghcr.io/pepyakin/risczero:latest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment