question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is it possible to Build Image for a certain Platform Architecture

See original GitHub issue

Environment:

  • com.google.cloud.tools.jib: 3.2.1
  • Gradle 7.4.2

JVM: 18.0.1.1 (Oracle Corporation 18.0.1.1+2-6) OS: Mac OS X 12.4 x86_64

Description of the issue: Cant find any method to build image for a certain platform architecture

Steps to reproduce:

jib-gradle-plugin Configuration:

jib.to {
  image = 'localhost:5000/nginx_new'
  platforms {
    platform {
      architecture = 's390x'
      os = 'linux'
    }
  }  
}

Log output:

* What went wrong:
A problem occurred evaluating root project
> Could not find method platforms() for arguments [build_e470sv26omxhc01p0di2zc0og$_run_closure3$_closure6@2920b0ff] on object of type com.google.cloud.tools.jib.gradle.TargetImageParameters.

Additional info:

Looking for similar features with docker buildx Example

docker buildx build --push --platform linux/arm/v7,linux/arm64/v8,linux/amd64 

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:13 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
chanseokohcommented, Jun 7, 2022

Our java base image only supports amd64 platform, I did the similar thing like this by just adding the arm64 platform.

Let’s say you have a java.exe executable binary on your Windows laptop. It’s a Windows binary compiled on Windows to be able to run on Windows. If you copy that java.exe file into a Linux laptop and try to execute it there, obviously, it won’t run. Likewise, the JVM you have in your base image is an amd64 binary. The java binary is compiled on amd64 to be able to run on amd64. The JVM cannot run on arm64, because it’s just a different platform. To build an arm64 image with Jib, you need to supply a base image where there is an arm64 JVM.

the configured platform (arm64/linux) doesn't match the platform (amd64/linux) of the base image.

The warning means that you showed Jib the intention to build an arm64 image, but the JVM base image you supplied is an amd64 image. The resulting image built by Jib is unquestionably an amd64 image. It will run fine on amd64, but it won’t run on arm64. Jib doesn’t allow you to forcibly and falsely marking the resulting image as an arm64 image, because it is not an arm64 image and it simply doesn’t make sense.

Also I did the same thing like this by adding both arm64 and amd64, it gave another warning:

This time, you showed the intention to create two images: one for arm64 and the other for amd64. However, as I said, to be able to build them, you need to provide two base images for the two different platforms: one for arm64 and the other for amd64. Apparently, the base image ***/java-13-base is a single image whose JVM is an amd64 binary. Therefore, the base image reference in this case should be a manifest list (it’s just a small JSON file listing pointers to multiple images) that contains at least both arm64 and amd64.

Almost all popular JDK/JRE images referenced by tags on Docker Hub are manifest lists. For example, you can see below that openjdk:17-oracle is a manifest list containing pointers to two images for amd64 and arm64.

image

So, if you specify openjdk:17-oracle as a base image and configure both arm64 and amd64, Jib will build both arm64 and amd64 images, create a manifest list pointing to those two built images, and upload the two images as well as the manifest list to the target registry. I suggest you to try out this kind of manifest list just to see how it works out.

jenkins/jenkins is a manifest list, but the list does not contain an image for architecture=amd64, os=windows.

You showed the intention to create a Windows image. Therefore, there should be a Windows base image containing a Windows JVM to begin with. jenkins/jenkins is a manifest list, but it doesn’t contain a pointer to a Windows image. There is no way Jib can build a Windows image. (BTW, even if the manifest list had a Windows image, Jib doesn’t yet support building a Windows image, so it would fail to build anyway.)

So How we could add a new architecture into target image manifest.

To sum up, if you want to build an arm64 (or Windows) image, you need to supply an arm64 (or Windows) base image to Jib. If you only supply an amd64 base image, what you can build is only an amd64 image. Jib won’t allow you to arbitrarily call the amd64 image an arm64 (or Windows) image, because it doesn’t make sense and won’t work anyway on arm64 (or Windows). That’s why you specify platforms under jib.from.

1reaction
eldo26commented, Jun 8, 2022

It worked !! 👍

@chanseokoh much appreciate your support and guidelines.

For reference attaching build.gradle and respective results.

plugins {
  id 'java'
  id 'com.google.cloud.tools.jib' version '3.2.1'
}

repositories {
  mavenCentral()
}

jib.container.mainClass = 'nginx'
jib.allowInsecureRegistries = true
jib.from {
  image = 'nginx'
  auth {
    username = 'eldo26'
    password = '**************'
  }
  platforms {
    platform {
      architecture = 'amd64'
      os = 'linux'
    }
    platform {
      architecture = 'arm64'
      os = 'linux'
    }
    platform {
      architecture = 's390x'
      os = 'linux'
    }       
    platform {
      architecture = '386'
      os = 'linux'
    }      
  }
}


jib.container {
  environment = [
    'var1' : 'abc'
  ]
}

jib.to {
  image = 'eldo26/nginx_1:v2'
  auth {
    username = 'eldo26'
    password = '**************'
  }  
}

Output indicates architectures available with the new Image.

➜  nginx docker manifest inspect eldo26/nginx_1:v2 |jq '.manifests'
[
  {
    "mediaType": "application/vnd.docker.distribution.manifest.v2+json",
    "size": 1395,
    "digest": "sha256:e961bf0158231f145599755ebfc619d5ce8546265dfceda78b3ec1236d294b04",
    "platform": {
      "architecture": "amd64",
      "os": "linux"
    }
  },
  {
    "mediaType": "application/vnd.docker.distribution.manifest.v2+json",
    "size": 1395,
    "digest": "sha256:15570c5379c89eaadd9ee4b5a17bfff75a523097073cc79d5a9ae9a57387fe09",
    "platform": {
      "architecture": "arm64",
      "os": "linux"
    }
  },
  {
    "mediaType": "application/vnd.docker.distribution.manifest.v2+json",
    "size": 1395,
    "digest": "sha256:c025c9d0185ba6054f2c364295a47ff2162e0b9fc3b99e63bad99caa89380fdc",
    "platform": {
      "architecture": "s390x",
      "os": "linux"
    }
  },
  {
    "mediaType": "application/vnd.docker.distribution.manifest.v2+json",
    "size": 1395,
    "digest": "sha256:de30beba1eefc7780be2728dae88c4024cb9a7dbf485bbaf77cd3512c5394219",
    "platform": {
      "architecture": "386",
      "os": "linux"
    }
  }
]
➜  nginx
Read more comments on GitHub >

github_iconTop Results From Across the Web

Multi-platform images | Docker Documentation
Docker images can support multiple platforms, which means that a single image may contain variants for different architectures, and sometimes for different ...
Read more >
Building Multiplatform Container Images the Easy Way
This post will show how with just a little work we were able to create Trow images for both ARM and Intel platforms....
Read more >
Building Docker images for multiple operating system ...
In this post I'll discuss how to build Docker images within CI pipelines that target multiple processor architectures such as linux/amd64, ...
Read more >
Easily Making Container Images for Multiple Platforms - Medium
The first thing I needed was the ability to create container images for multiple platforms in one location. Doing some research, I discovered ......
Read more >
Building Multi-CPU Architecture Docker Images for ARM and ...
As `buildx/buildkit` will build docker images for all target platforms simultaneously using one single Dockerfile. Your Dockerfile is required to be able to ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found