solo-io / packer-plugin-arm-image

Packer plugin for ARM images
Apache License 2.0
425 stars 104 forks source link

Error running in gitlab-ci docker in docker: open /proc/sys/fs/binfmt_misc/register: no such file or directory #138

Closed jseparovic closed 2 years ago

jseparovic commented 2 years ago

I'm seeing the following error when running in gitlab-ci with docker in docker.

$ packer build packer-pi.json
arm-image: output will be in this color.
==> arm-image: Image type: raspberrypi
==> arm-image: Retrieving Image
==> arm-image: Trying /images/2022-04-04-raspios-bullseye-armhf-lite.img
==> arm-image: Trying /images/2022-04-04-raspios-bullseye-armhf-lite.img?checksum=sha256%3Ada9d8cecd132cb630bee2f2b744c136f3a6ba260fb51e027bb11b17dfed2cca5
==> arm-image: /images/2022-04-04-raspios-bullseye-armhf-lite.img?checksum=sha256%3Ada9d8cecd132cb630bee2f2b744c136f3a6ba260fb51e027bb11b17dfed2cca5 => /images/2022-04-04-raspios-bullseye-armhf-lite.img
==> arm-image: Copying source image.
==> arm-image: Growing partition to 4096 M (4294967296 bytes)
    arm-image: mapping output-arm-image/image
==> arm-image: losetup --show -f -P output-arm-image/image
==> arm-image: partitions: [/dev/loop3p1 /dev/loop3p2]
==> arm-image: partitions: [/dev/loop3p1 /dev/loop3p2]
    arm-image: Mounting: /dev/loop3p2
    arm-image: Mounting: /dev/loop3p1
==> arm-image: Mounting additional paths within the chroot...
    arm-image: Mounting: /proc
    arm-image: Mounting: /sys
    arm-image: Mounting: /dev
    arm-image: Mounting: /dev/pts
    arm-image: Mounting: /proc/sys/fs/binfmt_misc
==> arm-image: Installing qemu-user-static (/usr/bin/qemu-arm-static) in the chroot
==> arm-image: Registering /qemu-arm-static with binfmt_misc
==> arm-image: open /proc/sys/fs/binfmt_misc/register: no such file or directory
==> arm-image: open /proc/sys/fs/binfmt_misc/packer-plugin-arm-image: no such file or directory

My .gitlab-ci.yml for ref:

image:
    name: ghcr.io/solo-io/packer-plugin-arm-image
    entrypoint:
        - '/usr/bin/env'
        - 'PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'

stages:
    - packer

packer-build:
    stage: packer
    script:
        - cd packer
        - packer build packer-pi.json

Any ideas what this issue with /proc/sys/fs/binfmt_misc might be?

jseparovic commented 2 years ago

I found a different way to do this for gitlab-ci. You run the qemu-user-static register in the before_script, and use dind instead of packer-plugin-arm-image directly. Then you can just use the same docker run command from the docs.

Sharing my config if anyway else has the same issue I did:

variables:
    GIT_STRATEGY: clone

services:
    - docker:19.03.12-dind

stages:
    - packer

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

packer-build:
    stage: packer
    script:
        - docker run
            --rm
            --privileged
            -v /dev:/dev
            -v /images:/images
            -v `pwd`:/build:ro
            -v `pwd`/packer_cache:/build/packer_cache
            -v `pwd`/output-arm-image:/build/output-arm-image
            ghcr.io/solo-io/packer-plugin-arm-image build pi.json