dockerx86-64github-actionsarm64multiarch

How to use Github Actions with a Docker container with a different architecture


I would like to automate the building of an application I am writing. I want to build it for ARM64/v8 (aarch64) and amd64 (x86). I successfully created a Github workflow for the x86 case.

name: Build

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

env:
  CARGO_TERM_COLOR: always

jobs:
  build:
    runs-on: ubuntu-latest
    container:
      image: ubuntu:jammy

    steps:
        - name: Check architecture
          run: uname -m
        - name: Check release version
          run: cat /etc/lsb-release

Now I would like to do the same for aarch64. I tried using the SHA to select the aarch64 container and adding the --platform option.

container:
  image: ubuntu:jammy@sha256:2166a543cffd7180cb98ed58bb6a99b0e4b57ecae8859c2a8ee5aa4f5e0a4fda
  options: --platform linux/arm64/v8

However the workflow fails at the uname -m command with the error message Error response from daemon: Container cb276d55aaf4a3f1cc50d308788233ee50fee29f80c05d6e557a76ec99916951 is not running.

If I want to run a docker container for a different architecture on my own machine, I have to first run docker run --rm --privileged multiarch/qemu-user-static --reset -p yes. I assume this is what's missing in my GitHub workflow. Unfortunately I was unable to find anything describing how this is done on GitHub Actions.


Solution

  • I found this action here that is simple to use. It works good enough for me for now.