Multi arch docker image, rust and GitHub Actions: a Love story

A rusty lock on a rusty bar, with the beach behind
Photo by Alex Martinez / Unsplash

I struggled a lot time to build my RSS Api docker images for several architecture (mainly amd64/x86_64 and arm64/aarch64, why are architecture names so complicated).

I quickly tried something called `docker buildx` with qemu which is described here and yay, it works! It's pretty simple to put in place. If you docker image is "general" enough, it does the trick and you finish with a multi arch docker image. Of course it takes times, but with my machine (AMD Ryzen 9 5950x with 16 cores of pure bliss) I had my images in 20 minutes (and I know it's a lot, but at this time, I was fine with it).

So, satisfied with this, I use this method in my GitHub Actions workflow. How boy. The mistake. I am a free tier user of GitHub, so I use the free GitHub provided runners and let's say they are not particularly powerful. My 20 minutes became... a time out on GitHub Actions. That's it. The build took more than 6 hours.

Stubborn, I try to install my own self-hosted GitHub runner on my computer and use it in my workflow. Sadly, for a unknown reason, my build just stop to work at some point. No errors, no logs, nothing, just the Void, eternal.

While I was complaining about this on Discord, a wise man said to me "You know, you can cross compile stuff before you create your docker image". So, that's what I did!

I now have a job (with a matrix strategy) building my binaries for my target architectures and then, I create the docker images using the already produced binaries.

Now my build on GitHub takes 12 minutes for three arch (amd64, arm64 and arm/v7)  and as a bonus, I can make a GitHub release with just the binaries, for those for are interested.

For the curious, the link to the build script.

Of course it's far from perfect, and there is a lot of room for improvements but I really happy with this outcome!

If you have remarks or comments please do it in the threads on Mastodon