Build multi arch docker image

I’m actually trying to build docker images on gitlab-ci and I’d like to build multi arch docker images.

That for, I’m using the following gitlab-ci.yml :

stages:
  - build

build_amd64:
  image: docker:stable
  stage: build
  services:
    - docker:dind
  variables:
    DOCKER_DRIVER: overlay2
  script:
    - docker build --build-arg IMAGE_ARCH=amd64 -t amd64/multiarch-ci:$CI_COMMIT_SHA .

build_arm64v8:
  image: docker:stable
  stage: build
  services:
    - docker:dind
  variables:
    DOCKER_DRIVER: overlay2
  before_script:
    - docker run --rm --privileged multiarch/qemu-user-static:register --reset
  script:
    - docker build --build-arg IMAGE_ARCH=arm64v8 -t arm64v8/multiarch-ci:$CI_COMMIT_SHA

My project is a dummy node project with just a console log. For the amd64 build. Everything goes fine.

For the arm build, I get the following error

Status: Downloaded newer image for arm64v8/node:latest
 ---> b7d3ee2eb758
Step 3/7 : ENV PORT 80
 ---> Running in 34b155b682b9
Removing intermediate container 34b155b682b9
 ---> a0fbafb8698b
Step 4/7 : COPY . /code
 ---> 258e18cc5a7c
Step 5/7 : WORKDIR /code
 ---> Running in 8f4de48ee080
Removing intermediate container 8f4de48ee080
 ---> 2167dc4d8bea
Step 6/7 : RUN /usr/local/bin/npm install
 ---> Running in 1d5d97046cd9
standard_init_linux.go:207: exec user process caused "no such file or directory"
The command '/bin/sh -c /usr/local/bin/npm install' returned a non-zero code: 1
ERROR: Job failed: exit code 1

Did anyone try to do that ?
Here is a public repo I made for that https://gitlab.com/jeremie.drouet/multiarch-ci

3 Likes

Did you solve your issue? Would you mind sharing some information please?
I’m interested as well but I don’t get the whole picture, as far as I understand I’d need a special runner on ARM and that can achieved with qemu-user-static, but that’s all I’ve got :stuck_out_tongue:

Thanks!

Official ARM support for gitlab-runner is not available, yet.

There is a Merge Request open where you can track the development progress.
Please feel free to contribute to the MR or add feedback to the relevant issues: #2076, #2137. You can also subscribe for updates.

Hi @jeremie.drouet, I used your blog post as inspiration for my attempt at multiarch, but it seems that something has changed recently in the GitLab runner code that causes your example to stop working.

After busting my head against the wall for a while, I had to add the following lines to my .gitlab-ci.yml to properly register the binfmt headers:

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

Without this, I kept getting the following error:

failed to solve: rpc error: code = Unknown desc = failed to load LLB: runtime execution on platform linux/arm/v7 not supported

Now my multiarch build completes successfully for armv6, armv7, and aarch64 on public runners.
Here is my full multiarch .gitlab-ci.yml for reference:
https://github.com/oofnikj/nuttssh/blob/multiarch/.gitlab-ci.yml