Is Multi Platform Build Automation possible?

You can’t build multiarch images by default on Docker Hub, but you can use build hooks to do that:

Note that it says it will run your build on Amazon Linux machines which was not true in my case, but I reported this issue on Github

The idea is to create a folder called “hooks”, save your hooks there and use these commands somwhere in those hooks:

docker buildx create --name multiarch --use
docker buildx build . -t <your_image_name> -f Dockerfile --platform linux/arm64/v8,linux/amd64 --push

It will immediately push your images so you can’t run build and push in separate hooks unless you do what I did. I used the build hook to build an image with a one tag, then tested every architecture in a loop in the test hook, and I ran docker buildx again with different parameters where I set new tags following semantic versioning.

You can see environment variables in the documentation. You can use those to tag your image based on the build rules you set on Docker Hub, or you can use completey different tags.

Since it is running in one build process, the second build will use the cache and just tag the images quickly.

The first line in my example is necessary to have an emulated build environment for different platforms.