jib icon indicating copy to clipboard operation
jib copied to clipboard

Investigate what to do for `jib:dockerBuild` and `jib:buildTar` for multi-platform image building

Open chanseokoh opened this issue 5 years ago • 10 comments

The Docker daemon probably won't accept a manifest list (or may require a different archive format).

chanseokoh avatar Sep 03 '20 16:09 chanseokoh

this looks closely related to issue #2751

tom-haines avatar Aug 06 '21 07:08 tom-haines

Thanks for the info in #2751. That's great!

Just for more clarification:

These two are related, but also largely orthogonal. This issue is about what how to push multi-arch images to a local Docker daemon or create a tar in which format. It's only relevant with the jib:dockerBuild and jib:buildTar the goals, where multi-arch image building is simply not possible.

#2751 is only about how to better record all the information about the built images in multi-arch image building. (Currently, Jib is recording only the information about the manifest list push result). #2751 is independent of which target storage to use (whether a remote registry, local Docker daemon, or tar on a filesystem).

chanseokoh avatar Aug 06 '21 15:08 chanseokoh

I've just come across this issue. We're looking to add arm64 images to our builds, but doing so breaks local development processes that use jib:dockerBuild.

From our perspective we'd like this to continue working, and since docker doesn't support storing multiple architectures for an image (from what I can see), and images in the local docker instance are almost always there to be run, it would make sense for jib:dockerBuild to pick the native platform of the docker instance. This should probably be accompanied by a warning saying it's only building for a single platform.

At least this way, dockerBuild is still somewhat useful, unlike at the moment where adding platforms renders it useless.

elFarto avatar Sep 30 '21 13:09 elFarto

That's a good idea. For now, please use the workaround of having two profiles, e.g., a default prod profile that defines multiple platforms and dev or local that defines only the platform that matches your local environment.

chanseokoh avatar Sep 30 '21 14:09 chanseokoh

~~Regarding building a tar there should also be an option to build an OCI tar which can store multi-arch images (https://github.com/opencontainers/image-spec/blob/main/image-layout.md). Similar to docker buildx build --output=type=oci,dest=image.tar ...~~ Sorry, found out that it should already be possible (https://github.com/GoogleContainerTools/jib/pull/2181)

SgtSilvio avatar Jun 16 '22 21:06 SgtSilvio

Thanks for the clarification and link @SgtSilvio

mpeddada1 avatar Jun 29 '22 22:06 mpeddada1

This might be a better solution for some than requiring defining a command line property (which I always forget 😏).

jib {
  to {
    image = "..."
    auth {...}
  }
  from {
    image = "openjdk:17-jdk"
  }
}

gradle.taskGraph.addTaskExecutionGraphListener {
  if (!it.hasTask(":jibDockerBuild")) {
    logger.info("JIB: Enabling Multi-Platform Images")
    jib.from.platforms {
      platform {
        os = "linux"
        architecture = "arm64"
      }
      platform {
        os = "linux"
        architecture = "amd64"
      }
    }
  }
}

The only sticking point is that the param to hasTask (:jibDockerBuild in the above) needs to be the complete path to your jibDockerBuild task. For example, if your task is in a subproject named cli, you'd need :cli:jibDockerBuild, for single module projects :jibDockerBuild works.

kdubb avatar Feb 17 '23 16:02 kdubb

This issue is closed but I think it's not resolved (just ran into the issue/error that multi-platform is not supported). I think that @elFarto suggestion:

From our perspective we'd like this to continue working, and since docker doesn't support storing multiple architectures for an image (from what I can see), and images in the local docker instance are almost always there to be run, it would make sense for jib:dockerBuild to pick the native platform of the docker instance.

seems very reasonable.

woj-tek avatar Mar 17 '23 20:03 woj-tek

@ddixit14 this issue is still not fixed.... we still get errors from jib when trying to build (without pushing) multi-platform images here are the two methods that leads to failure

I get multi-platform image building not supported when pushing to Docker engine or multi-platform image building not supported when building a local tar image when trying to build the image without pushing it.

clembo590 avatar Feb 16 '24 11:02 clembo590

I don't think this issue should have been closed. As noted above, the problem still persists. It does have a workaround however, so in the meantime please use different maven profiles as recommended previously.

dangazineu avatar May 14 '24 16:05 dangazineu

jib-maven-plugin:3.4.3, jib-gradle-plugin:3.4.3 and jib-core:0.27.1 have been released with a fix for this! When building to the local docker daemon, Jib now selects the image with os and architecture matching the local docker environment.

mpeddada1 avatar May 31 '24 16:05 mpeddada1