From 8d1f3f4bbdc660060ad35f129a255cba6bad7fa7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Svantesson?= Date: Mon, 2 Sep 2024 16:47:23 +0200 Subject: [PATCH] feat: support for tagging platform specific images in maven plugin also adjusting description of property for gradle --- jib-gradle-plugin/README.md | 2 +- jib-maven-plugin/README.md | 1 + .../jib/maven/BuildImageMojoIntegrationTest.java | 11 ++++++++++- .../cloud/tools/jib/maven/JibPluginConfiguration.java | 9 +++++++++ .../cloud/tools/jib/maven/MavenRawConfiguration.java | 5 +++++ .../tools/jib/plugins/common/RawConfiguration.java | 4 +--- 6 files changed, 27 insertions(+), 5 deletions(-) diff --git a/jib-gradle-plugin/README.md b/jib-gradle-plugin/README.md index f1991a68a6..3655600c75 100644 --- a/jib-gradle-plugin/README.md +++ b/jib-gradle-plugin/README.md @@ -225,7 +225,7 @@ Property | Type | Default | Description `auth` | [`auth`](#auth-closure) | *None* | Specifies credentials directly (alternative to `credHelper`). `credHelper` | `String` | *None* | Specifies a credential helper that can authenticate pushing the target image. This parameter can either be configured as an absolute path to the credential helper executable or as a credential helper suffix (following `docker-credential-`). `tags` | `List` | *None* | Additional tags to push to. -`enablePlatformTags` | `boolean` | `false` | When creating multi-platform images takes the tags, suffixes them with the platform, and tags the image. +`enablePlatformTags` | `boolean` | `false` | Sets whether to automatically add architecture suffix to tags for platform-specific images when building multi-platform images. For example, when building amd64 and arm64 images for a given tag, the final tags will be `-amd64` and `-arm64`. `auth` is a closure with the following properties (see [Using Specific Credentials](#using-specific-credentials)): diff --git a/jib-maven-plugin/README.md b/jib-maven-plugin/README.md index 622d6bfc75..cab9fb7c08 100644 --- a/jib-maven-plugin/README.md +++ b/jib-maven-plugin/README.md @@ -274,6 +274,7 @@ Property | Type | Default | Description `auth` | [`auth`](#auth-object) | *None* | Specifies credentials directly (alternative to `credHelper`). `credHelper` | string | *None* | Specifies a credential helper that can authenticate pushing the target image. This parameter can either be configured as an absolute path to the credential helper executable or as a credential helper suffix (following `docker-credential-`). `tags` | list | *None* | Additional tags to push to. +`enablePlatformTags` | `boolean` | `false` | Sets whether to automatically add architecture suffix to tags for platform-specific images when building multi-platform images. For example, when building amd64 and arm64 images for a given tag, the final tags will be `-amd64` and `-arm64`. `auth` is an object with the following properties (see [Using Specific Credentials](#using-specific-credentials)): diff --git a/jib-maven-plugin/src/integration-test/java/com/google/cloud/tools/jib/maven/BuildImageMojoIntegrationTest.java b/jib-maven-plugin/src/integration-test/java/com/google/cloud/tools/jib/maven/BuildImageMojoIntegrationTest.java index 52675002c2..6b0911a75b 100644 --- a/jib-maven-plugin/src/integration-test/java/com/google/cloud/tools/jib/maven/BuildImageMojoIntegrationTest.java +++ b/jib-maven-plugin/src/integration-test/java/com/google/cloud/tools/jib/maven/BuildImageMojoIntegrationTest.java @@ -17,6 +17,7 @@ package com.google.cloud.tools.jib.maven; import static com.google.common.truth.Truth.assertThat; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; import com.google.cloud.tools.jib.Command; @@ -714,7 +715,8 @@ public void testExecute_springBootPackaged() @Test public void testExecute_multiPlatformBuild() throws IOException, VerificationException, RegistryException { - String targetImage = dockerHost + ":5000/multiplatform:maven" + System.nanoTime(); + String standardTag = "maven" + System.nanoTime(); + String targetImage = dockerHost + ":5000/multiplatform:" + standardTag; Verifier verifier = new Verifier(simpleTestProject.getProjectRoot().toString()); verifier.setSystemProperty("_TARGET_IMAGE", targetImage); @@ -723,6 +725,7 @@ public void testExecute_multiPlatformBuild() verifier.setSystemProperty("jib.to.auth.password", "testpassword"); verifier.setSystemProperty("sendCredentialsOverHttp", "true"); verifier.setSystemProperty("jib.allowInsecureRegistries", "true"); + verifier.setSystemProperty("jib.to.enablePlatformTags", "true"); verifier.setAutoclean(false); verifier.addCliOption("--file=pom-multiplatform-build.xml"); @@ -773,6 +776,9 @@ public void testExecute_multiPlatformBuild() assertThat(arm64Config).contains("\"architecture\":\"arm64\""); assertThat(arm64Config).contains("\"os\":\"linux\""); + assertEquals( + arm64Digest, registryClient.pullManifest(standardTag + "-arm64").getDigest().toString()); + // Check amd64/linux container config. List amd64Digests = v22ManifestList.getDigestsForPlatform("amd64", "linux"); assertThat(amd64Digests.size()).isEqualTo(1); @@ -787,6 +793,9 @@ public void testExecute_multiPlatformBuild() String amd64Config = Blobs.writeToString(amd64ConfigBlob); assertThat(amd64Config).contains("\"architecture\":\"amd64\""); assertThat(amd64Config).contains("\"os\":\"linux\""); + + assertEquals( + amd64Digest, registryClient.pullManifest(standardTag + "-amd64").getDigest().toString()); } private void buildAndRunWebApp(TestProject project, String label, String pomXml) diff --git a/jib-maven-plugin/src/main/java/com/google/cloud/tools/jib/maven/JibPluginConfiguration.java b/jib-maven-plugin/src/main/java/com/google/cloud/tools/jib/maven/JibPluginConfiguration.java index 0e897cdaa9..d4076a3d41 100644 --- a/jib-maven-plugin/src/main/java/com/google/cloud/tools/jib/maven/JibPluginConfiguration.java +++ b/jib-maven-plugin/src/main/java/com/google/cloud/tools/jib/maven/JibPluginConfiguration.java @@ -223,6 +223,7 @@ public static class ToConfiguration { @Parameter private List tags = Collections.emptyList(); @Parameter private CredHelperParameters credHelper = new CredHelperParameters(); @Parameter private ToAuthConfiguration auth = new ToAuthConfiguration(); + @Parameter private boolean enablePlatformTags; public void set(String image) { this.image = image; @@ -811,6 +812,14 @@ boolean isSkipped() { return skip; } + boolean getEnablePlatformTags() { + final String property = getProperty(PropertyNames.ENABLE_PLATFORM_TAGS); + if (property != null) { + return Boolean.parseBoolean(property); + } + return to.enablePlatformTags; + } + List getPluginExtensions() { return pluginExtensions; } diff --git a/jib-maven-plugin/src/main/java/com/google/cloud/tools/jib/maven/MavenRawConfiguration.java b/jib-maven-plugin/src/main/java/com/google/cloud/tools/jib/maven/MavenRawConfiguration.java index 0d11c86f6f..ba7738e6df 100644 --- a/jib-maven-plugin/src/main/java/com/google/cloud/tools/jib/maven/MavenRawConfiguration.java +++ b/jib-maven-plugin/src/main/java/com/google/cloud/tools/jib/maven/MavenRawConfiguration.java @@ -219,4 +219,9 @@ public List getPluginExtensions() { public List getPlatforms() { return jibPluginConfiguration.getPlatforms(); } + + @Override + public boolean getEnablePlatformTags() { + return jibPluginConfiguration.getEnablePlatformTags(); + } } diff --git a/jib-plugins-common/src/main/java/com/google/cloud/tools/jib/plugins/common/RawConfiguration.java b/jib-plugins-common/src/main/java/com/google/cloud/tools/jib/plugins/common/RawConfiguration.java index d7f5907810..52b2967d24 100644 --- a/jib-plugins-common/src/main/java/com/google/cloud/tools/jib/plugins/common/RawConfiguration.java +++ b/jib-plugins-common/src/main/java/com/google/cloud/tools/jib/plugins/common/RawConfiguration.java @@ -135,7 +135,5 @@ interface CredHelperConfiguration { List getPluginExtensions(); - default boolean getEnablePlatformTags() { - return false; - } + boolean getEnablePlatformTags(); }