Skip to content

Support / documentation for building multi-arch images (e.g. amd64, arm64) #1502

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
tfactor2 opened this issue Nov 3, 2021 · 4 comments · Fixed by #1544
Closed

Support / documentation for building multi-arch images (e.g. amd64, arm64) #1502

tfactor2 opened this issue Nov 3, 2021 · 4 comments · Fixed by #1544

Comments

@tfactor2
Copy link

tfactor2 commented Nov 3, 2021

Description

Last versions of docker support multi-arch images (see https://docs.docker.com/engine/reference/commandline/buildx_build/).
For us, multi-arch images become very relevant as developers more and more start to use Apple Silicon (e.g. M1) machines due to their high-performance capabilities.

I was not able to find a way to build the images using the plugin.

Would be good to either add support or if it's possible already now, document it in official docs.

Notes

Tried the following configuration:

<plugin>
        <groupId>io.fabric8</groupId>
        <artifactId>docker-maven-plugin</artifactId>
        <extensions>true</extensions>
        <configuration>
          <images>
            <image>
              <name>${docker.push.registry}/myservice:${project.version}</name>
              <build>
                <buildOptions>
                  <platform>linux/arm64,linux/amd64</platform>
                </buildOptions>
                <dockerFile>${project.basedir}/src/main/docker/Dockerfile</dockerFile>
                <assembly>
                  <inline>
...

The error that I've got is:

DOCKER> Unable to build image [docker-repo.crxmarkets.tech/payables:22.3.0-SNAPSHOT] : {"message":""arm64,linux" is > an invalid component of "linux/arm64,linux/amd64": platform specifier component must match "^[A-Za-z0-9_-]+$": invalid argument"} (Bad Request: 400) [{"message":""arm64,linux" is an invalid component of "linux/arm64,linux/amd64": platform specifier component must match "^[A-Za-z0-9_-]+$": invalid argument"} (Bad Request: 400)

The builds using docker buildx build or docker build with BuildKit enabled, succeeded:
DOCKER_BUILDKIT=1 docker build --platform=linux/amd64,linux/arm64 -t myservice .

docker buildx ls
NAME/NODE        DRIVER/ENDPOINT      STATUS  PLATFORMS
buildxbuilder *  docker-container             
  buildxbuilder0 tcp://localhost:2375 running linux/amd64*, linux/arm64*, linux/riscv64, linux/ppc64le, linux/386, linux/mips64le, linux/mips64, linux/arm/v7, linux/arm/v6, linux/s390x
default          docker                       
  default        default              running linux/amd64, linux/arm64, linux/riscv64, linux/ppc64le, linux/s390x, linux/386, linux/arm/v7, linux/arm/v6

Environment

  • docker-maven-plugin version : 0.37.0
  • Maven version (mvn -v) : 3.6.3, Java version: 11.0.11, vendor: Ubuntu, runtime: /usr/lib/jvm/java-11-openjdk-amd64
  • Docker version : 20.10.10, build b485636
@tfactor2
Copy link
Author

tfactor2 commented Nov 5, 2021

After diving into the topic I've got the following:

  1. Multiplatform builds are supported by the new build engine called BuildKit.
  2. The engine is built-in into the docker engine (mobi).
  3. The build engine is not only available via CLI ( docker buildx) but via REST API.
  4. The REST API has an attribute version - see https://github.com/docker/engine/blob/c09789c1140a3b2e399b0c77c449b34d000e2362/api/types/client.go#L207.
  5. By passing version 2 the client instructs Docker to use BuildKit engine.
  6. fabric8 uses a legacy build engine, naive switching to the latest version (2) brought exceptions while building.
<plugin>
        <groupId>io.fabric8</groupId>
        <artifactId>docker-maven-plugin</artifactId>
        <extensions>true</extensions>
        <configuration>
          <images>
            <image>
              <name>${docker.push.registry}/myservice:${project.version}</name>
              <build>
                <buildOptions>
                  <platforms>linux/amd64,linux/arm64</platforms> <!-- notice platformS here, the API accepts this parameter, in opposite to `docker buildx` that accepts multiple platform in the `platform` parameter`
                  <version>2</version> <!-- doesn't work -->
                </buildOptions>

The following exception happens while trying to run the plugin with <version>2</version> build argument:

[ERROR] Failed to execute goal io.fabric8:docker-maven-plugin:0.34.1:build (default-build) on project docker: Unable to build image [....] : "failed to solve with frontend dockerfile.v0: failed to create LLB definition: dockerfile parse error line 1: unknown instruction: ./PAXHEADERS.X/MAVEN_\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u00000100644"  -> [Help 1]

Found the ticket #1267 that is a blocker for the problem described.
Think that this ticket can be closed in favor of #1267.

@stoerr
Copy link

stoerr commented Apr 7, 2022

I'd like to support that. :-) Since we are working with Intel and M1 Macs, and amd64 architecture docker images are pretty much unusable on my M1 Max, we need to build for both architectures, and that seems to be a serious pain at the moment.

@rvbaron
Copy link

rvbaron commented Apr 26, 2022

are the following mvn buildOptions supposed to be working in 0.39.1 now:
platform: linux/arm64,linux/amd64
version: 2
Thanks!

@asad-awadia
Copy link

asad-awadia commented Aug 30, 2022

@rvbaron how do i build the image for arm using mvn docker:build ? if i have a list of platforms in the pom will it create multiple images?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants