GoogleContainerTools / jib

🏗 Build container images for your Java applications.
Apache License 2.0
13.52k stars 1.42k forks source link

How can I pass --from-platforms using plain Jib CLI? #4201

Open artemptushkin opened 4 months ago

artemptushkin commented 4 months ago

In Gradle it's possible:

./gradlew -Djib.from.platforms="linux/amd64,linux/arm64"

But when I use CLI (I really use CLI in one of the projects):

jib ... --from-platforms="linux/amd64,linux/arm64"

this fails with

Unknown option: '--from-platforms=linux/amd64,linux/arm64'
Possible solutions: --from-credential-helper, --from-username, --from-password, --from
Usage: jib jar [-hV] [--allow-insecure-registries]
               [--send-credentials-over-http]
               [--base-image-cache=<cache-directory>] [--console=<type>]
               [--creation-time=<creation-time>] [--from=<base-image>]
               [--image-format=<image-format>]
               [--image-metadata-out=<path-to-json>] [--mode=<mode>]
               [--name=<image-reference>] [--project-cache=<cache-directory>]
               -t=<target-image> [-u=<user>] [--verbosity=<level>]
               [--additional-tags=<tag>[,<tag>...]]...
               [--entrypoint=<entrypoint>[\s+<entrypoint>...]]...
               [--environment-variables=<key>=<value>[,<key>=<value>...]]...
               [--expose=<port>[,<port>...]]... [--jvm-flags=<jvm-flag>[,
               <jvm-flag>...]]... [--labels=<key>=<value>[,
               <key>=<value>...]]... [--program-args=<program-argument>[,
               <program-argument>...]]... [--volumes=<volume>[,<volume>...]]...
               [--credential-helper=<credential-helper> |
               [--username=<username> --password[=<password>]] |
               [[--to-credential-helper=<credential-helper> |
               [--to-username=<username> --to-password[=<password>]]]
               [--from-credential-helper=<credential-helper> |
               [--from-username=<username> --from-password[=<password>]]]]]
               [@<filename>...] <jarFile>
chanseokoh commented 4 months ago

Looking at CommonContainerConfigCliOptions, jib-cli doesn't seem to have a command-line parameter for it.

Unfortunately, the only workaround I can think of is to use the jib build command and specify platforms in jib.yaml.

from:
  image: "ubuntu"
  # set platforms for multi architecture builds, defaults to `linux/amd64`
  platforms:
    - architecture: "arm"
      os: "linux"
    - architecture: "amd64"
      os: "darwin"
artemptushkin commented 4 months ago

@chanseokoh thank you for the quick response, I thought so according to the documentation, and I will try the yaml approach. I will close the issue with this resolution, but I have just a question maybe you know

Do you have any defaults in jib.yaml to set? Let's say I have my CLI command with N parameters, if I set all of them as yaml fields will it be enough, or should I default something else? I could reverse but frankly, I don't have time for this

artemptushkin commented 4 months ago

I just realized that I use jar command and not build and the first doesn't support the jib.yaml file. So I have to either use build command or get back to the Gradle plugin here

artemptushkin commented 4 months ago

@chanseokoh can we implement a feature in the scope of this issue to pass platforms from the CLI parameters? I see it's possible, we can replace here emptySet with a parameter