Skip to content

Commit

Permalink
feat: support for tagging platform specific images in maven plugin
Browse files Browse the repository at this point in the history
also adjusting description of property for gradle
  • Loading branch information
msvticket committed Nov 19, 2024
1 parent 7eedb25 commit 8d1f3f4
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 5 deletions.
2 changes: 1 addition & 1 deletion jib-gradle-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>` | *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 `<tag>-amd64` and `<tag>-arm64`.

<a name="auth-closure"></a>`auth` is a closure with the following properties (see [Using Specific Credentials](#using-specific-credentials)):

Expand Down
1 change: 1 addition & 0 deletions jib-maven-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<tag>-amd64` and `<tag>-arm64`.

<a name="auth-object"></a>`auth` is an object with the following properties (see [Using Specific Credentials](#using-specific-credentials)):

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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");
Expand Down Expand Up @@ -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<String> amd64Digests = v22ManifestList.getDigestsForPlatform("amd64", "linux");
assertThat(amd64Digests.size()).isEqualTo(1);
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ public static class ToConfiguration {
@Parameter private List<String> 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;
Expand Down Expand Up @@ -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<ExtensionParameters> getPluginExtensions() {
return pluginExtensions;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,4 +219,9 @@ public List<? extends ExtensionConfiguration> getPluginExtensions() {
public List<? extends PlatformConfiguration> getPlatforms() {
return jibPluginConfiguration.getPlatforms();
}

@Override
public boolean getEnablePlatformTags() {
return jibPluginConfiguration.getEnablePlatformTags();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,5 @@ interface CredHelperConfiguration {

List<? extends ExtensionConfiguration> getPluginExtensions();

default boolean getEnablePlatformTags() {
return false;
}
boolean getEnablePlatformTags();
}

0 comments on commit 8d1f3f4

Please sign in to comment.