multiarch / qemu-user-static

:earth_africa: `/usr/bin/qemu-*-static`
https://hub.docker.com/r/multiarch/qemu-user-static/
MIT License
2.48k stars 230 forks source link

document how to use multiarch docker image with CI #106

Open zhangyoufu opened 4 years ago

zhangyoufu commented 4 years ago

Is this a bug report, feature (enhancement) request or question? (leave only one on its own line)

/kind enhancement

Description:

I think it worth mention in README, that Docker Hub and QEMU have different notion of architecture. And I found that by abusing docker volume, I can register a single qemu-user-static binfmt_misc entry easily.

I came up with GitHub Actions workflow like this:

on: push

jobs:
  build:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        docker_arch: [amd64, i386, arm32v6, arm32v7, arm64v8, ppc64le, s390x] # arm32v5 is not supported by alpine
    steps:
    - name: Register binfmt_misc entry for qemu-user-static 
      env:
        DOCKER_ARCH: ${{ matrix.docker_arch }}
      run: |
        case ${DOCKER_ARCH} in
            amd64|i386)
                QEMU_ARCH=
                ;;
            arm32*)
                QEMU_ARCH=arm
                ;;
            arm64*)
                QEMU_ARCH=aarch64
                ;;
            *)
                QEMU_ARCH=${DOCKER_ARCH}
                ;;
        esac
        if [ -n "${QEMU_ARCH}" ]; then
            docker rm $(docker create --volume qemu-user-static:/usr/bin multiarch/qemu-user-static:${QEMU_ARCH} dummy)
            docker run --rm --privileged --volume qemu-user-static:/usr/bin:ro multiarch/qemu-user-static:register --persistent yes
        fi
    - name: Build
      env:
        DOCKER_ARCH: ${{ matrix.docker_arch }}
      run: |
        docker run --rm --interactive "${DOCKER_ARCH}/alpine:latest" <<-'EOF'
            echo 'Hello World!'
        EOF

image

junaruga commented 4 years ago

HI @zhangyoufu Thank you for showing the suggestion and the example with GitHub Actions.

Currently, there are following some documents about the images with (Travis) CI. How can we improve it? The pull-request is welcome.

I think adding your GitHub Actions example to the examples.md 's links improves it. Do you have a GitHub repository to test multiarch docker image with GitHub Actions CI?

In README.md,

Please see the example - junaruga/ci-multi-arch-test i386 case on Travis CI. ... In See Examples & articles.

In examples.md linked from the "Examples & articles".

junaruga/ci-multi-arch-test and the Travis CI

umarcor commented 4 years ago

FTR, in dbhi/qus, ~15 different procedures to use these resources in CI are explained and tested, both on GitHub Actions and on Travis. See the complete list of tests: https://github.com/dbhi/qus/blob/master/docs/tests.md

For a more straightforward and easier to understand example, in repo dbhi/docker, qus is used to build and publish multiarch/manifest images. See https://github.com/dbhi/docker/blob/master/.github/workflows/push.yml (L44-L45 and L66-L67).

I think it worth mention in README, that Docker Hub and QEMU have different notion of architecture.

This is not only related to Docker and QEMU, but different distributions use different names too. Unlike this repo, where static binaries from Fedora are used, in qus binaries from Debian or Fedora are available. Some architecture names do not match or only a subset is available on one of the distributions. See https://github.com/dbhi/qus/blob/master/run.sh#L66-L116 for a glimpse of what is considered equivalent in the context of qus.

martin-g commented 4 years ago

Here is how I use multiarch/qemu-user-static on GitHub Actions: https://github.com/martin-g/haproxy/blob/feature/test-aarch64-on-github-actions/.github/workflows/aarch64.yml and here is on CircleCI: https://github.com/varnishcache/varnish-cache/tree/master/.circleci

umarcor commented 4 years ago

@martin-g, note that you don't need sudo on GHA. The runner seems to be in group docker. See https://github.com/dbhi/docker/blob/master/.github/workflows/push.yml#L67 and https://github.com/dbhi/docker/runs/789862140?check_suite_focus=true#step:3:36.