Multi-arch is the new future!

Sneha Gaonkar
3 min readDec 15, 2021

What is Multi-arch?

Multi-arch is the new approach that is being adopted to ease cross-compiling and distribution of various opensource software packages/tools. The idea is to update the software itself or change the way its built to enable support for multiple architectures instead of just one. There are many ways in which multi-arch support can be added to software packages. In this blog, I will be talking about my experience of working on adding multi-arch support to opensource tools/packages and various approaches to achieve the same.

Multi-arch image manifests

Building container images is one of the most used method for packaging and distributing software. A manifest list is created from images that are identical in function for different os/arch combinations. For this reason, manifest lists are often referred to as multi-arch images. “Build once, deploy anywhere” is basically the idea behind using multi-arch image manifests.

If you are using Docker for building container images, then a manifest can be created by using below command:

docker manifest create MANIFEST_LIST <List of images seperated with space character>

Docker buildx and Qemu static user

qemu-user-static is a fast processor emulator that uses the current operating system to run other architectures. Docker Buildx is a CLI plugin that extends the docker command with the full support of the features provided by Moby BuildKit builder toolkit. It provides the same user experience as docker build with many new features like building os/arch specific images. With the help of qemu-user-static emulator and docker buildx, we can build arch specific images on the single machine.

Command to enable qemu-user-static:

docker run --rm --privileged multiarch/qemu-user-static --reset -p yes

Docker buildx command for building arch specific images:

docker buildx build --platform "${OS}/${ARCH}" \
-f <Dockerfile path> \
-t <Image:Tag> .

After building images for all the required architectures, you will have to create the multi-arch manifest image.

GitHub Actions and Buildah

GitHub Actions is a continuous integration and continuous delivery (CI/CD) platform that allows you to automate your build, test, and deployment pipeline. You can create workflows that build and test every pull request to your repository, or deploy merged pull requests to production. Buildah is an open-source, Linux-based tool that can build Docker- and Kubernetes-compatible images.

Here is a simple GitHub Actions workflow for building multi-arch images with the help of Buildah tool. You can refer this blog to create your own workflow for building multi-arch images for required architectures. Similarly, you can use other CICD tools like Travis, Tekton, GitLab to create your own pipeline for building multi-arch images.

GitHub Actions and QEMU

Here’s a simple approach for building multi-arch images/binaries for Opensource packages. You can refer this blog to create your own workflow for building multi-arch artifacts using GitHub Actions.

Cross-compiling with Go

The Go programming language comes with a rich toolchain that makes obtaining packages and building executables incredibly easy. One of Go’s most powerful features is the ability to cross-build executables for any Go-supported foreign platform. This makes testing and package distribution much easier, because you don’t need to have access to a specific platform in order to distribute your package for it.

All you have to do is set OS and Arch value before building the executable:

env GOOS=<target-OS> GOARCH=<target-arch> go build <package>

Many opensource software packages/tools are now moving to multi-arch approach. It is good to have multi-arch images, rather then having to manage separate images for each architecture. Also, having a dedicated pipeline for building multi-arch images, will make it simpler for integrating support to new architectures.

Thanks for reading! I hope you found this tutorial helpful :)

--

--