4

I'm currently building my docker image declaratively in a Jenkinsfile by:

app = docker.build("...")

Now I need to generate a platform specific build for ARM64. For this purpose

docker buildx build --platform linux/arm64 ...

must be used.

I there a way to keep using the docker.build() syntax and still generate a platform specific image?

Or do I have to rewrite the syntax, if then how?

Sam
  • 141
  • 2

2 Answers2

2

The Jenkins Docker Pipeline plugin does not support buildx (yet?). Voting may help, so add yours to the issue if so inclined.

Jeremie Drouet wrote a great post "Multi-arch build and images, the simple way" which covers the underlying ways you can do it by building images first, then create a manifest to link them together.

bgulla on Github has a gist that does as much of the build as possible with pipeline using docker.withRegistry(). Then uses sh to create and push the manifest.

8None1
  • 121
  • 4
0

Here's how to do it in Jenkins only using the plugin for image naming:

  script {
    docker.withRegistry('my.registry.com', 'my_creds') {
      def image = docker.image("my_image:my_tag")
      sh "docker buildx create --use --name multiarch"
      sh """
      docker buildx build \
        --platform linux/amd64,linux/arm64 \
        -t ${image.imageName()} \
        --push .
      """
    }
  }

For this to work the Jenkins agent needs to have the QEMU binary formats registered with binfmt so the builder it creates will have all the emulators it needs. This docker container will do it:

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

This command needs to be be run on every reboot of the agent. In AWS EC-2 you can put it in an executable script in /var/lib/cloud/scripts/per-boot/ and see the output in /var/log/cloud-init-output.log.

Noumenon
  • 101
  • 2