From 528ae5a8380252f4e7320338d67eaa1f8cf06984 Mon Sep 17 00:00:00 2001 From: Louis Murerwa Date: Mon, 6 Jul 2020 21:50:51 +0000 Subject: [PATCH 01/19] Adding the plugins tag for Jib-Maven-Plugin --- .../jib/maven/JibPluginConfiguration.java | 34 +++++++++++++++++++ .../jib/maven/JibPluginConfigurationTest.java | 3 ++ 2 files changed, 37 insertions(+) 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 131da5a2a4..d3f5fa3ad1 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 @@ -27,6 +27,7 @@ import java.nio.file.InvalidPathException; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; import java.util.List; @@ -127,6 +128,19 @@ Optional getMode() { } } + public static class PlatformsConfiguration { + @Parameter private String os; + @Parameter private String architecture; + + public String getOs() { + return this.os; + } + + public String getArchitecture() { + return this.architecture; + } + } + /** Configuration for {@code from} parameter. */ public static class FromConfiguration { @@ -135,6 +149,16 @@ public static class FromConfiguration { @Nullable @Parameter private String credHelper; @Parameter private FromAuthConfiguration auth = new FromAuthConfiguration(); + + @Parameter private List platforms; + + public FromConfiguration() { + platforms = new ArrayList<>(); + PlatformsConfiguration platform = new PlatformsConfiguration(); + platform.architecture = "amd64"; + platform.os = "linux"; + platforms.add(platform); + } } /** Configuration for {@code to} parameter, where image is required. */ @@ -330,6 +354,16 @@ protected void checkJibVersion() throws MojoExecutionException { MojoCommon.checkJibVersion(descriptor); } + /** + * Gets the specified platforms + * + * @return the specified platforms + */ + @Nullable + List getPlatforms() { + return from.platforms; + } + /** * Gets the base image reference. * diff --git a/jib-maven-plugin/src/test/java/com/google/cloud/tools/jib/maven/JibPluginConfigurationTest.java b/jib-maven-plugin/src/test/java/com/google/cloud/tools/jib/maven/JibPluginConfigurationTest.java index a20ae1d707..ec5cf635a3 100644 --- a/jib-maven-plugin/src/test/java/com/google/cloud/tools/jib/maven/JibPluginConfigurationTest.java +++ b/jib-maven-plugin/src/test/java/com/google/cloud/tools/jib/maven/JibPluginConfigurationTest.java @@ -69,6 +69,8 @@ public Log getLog() { @Test public void testDefaults() { + Assert.assertEquals("linux", testPluginConfiguration.getPlatforms().get(0).getOs()); + Assert.assertEquals("amd64", testPluginConfiguration.getPlatforms().get(0).getArchitecture()); Assert.assertEquals("", testPluginConfiguration.getAppRoot()); Assert.assertNull(testPluginConfiguration.getWorkingDirectory()); Assert.assertTrue(testPluginConfiguration.getExtraClasspath().isEmpty()); @@ -181,6 +183,7 @@ public void testSystemProperties() { @Test public void testPomProperties() { + project.getProperties().setProperty("jib.from.image", "fromImage"); Assert.assertEquals("fromImage", testPluginConfiguration.getBaseImage()); project.getProperties().setProperty("jib.from.credHelper", "credHelper"); From 6dcfa25e255b9a189db1b24a2fa18206d5c519d9 Mon Sep 17 00:00:00 2001 From: Louis Murerwa Date: Mon, 6 Jul 2020 21:54:46 +0000 Subject: [PATCH 02/19] Adding the plugins tag --- .../com/google/cloud/tools/jib/maven/JibPluginConfiguration.java | 1 + 1 file changed, 1 insertion(+) 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 d3f5fa3ad1..48664895a4 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 @@ -361,6 +361,7 @@ protected void checkJibVersion() throws MojoExecutionException { */ @Nullable List getPlatforms() { + return from.platforms; } From 0643483c4a23741471a049a842c824c0c0b52781 Mon Sep 17 00:00:00 2001 From: Louis Murerwa Date: Mon, 6 Jul 2020 23:02:32 +0000 Subject: [PATCH 03/19] Solved Style Issues --- .../tools/jib/maven/JibPluginConfiguration.java | 12 +++++++----- .../tools/jib/maven/JibPluginConfigurationTest.java | 1 - 2 files changed, 7 insertions(+), 6 deletions(-) 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 48664895a4..cf37309722 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 @@ -132,6 +132,11 @@ public static class PlatformsConfiguration { @Parameter private String os; @Parameter private String architecture; + public PlatformsConfiguration(String os, String architecture) { + this.os = os; + this.architecture = architecture; + } + public String getOs() { return this.os; } @@ -154,9 +159,7 @@ public static class FromConfiguration { public FromConfiguration() { platforms = new ArrayList<>(); - PlatformsConfiguration platform = new PlatformsConfiguration(); - platform.architecture = "amd64"; - platform.os = "linux"; + PlatformsConfiguration platform = new PlatformsConfiguration("linux", "amd64"); platforms.add(platform); } } @@ -355,13 +358,12 @@ protected void checkJibVersion() throws MojoExecutionException { } /** - * Gets the specified platforms + * Gets the specified platforms. * * @return the specified platforms */ @Nullable List getPlatforms() { - return from.platforms; } diff --git a/jib-maven-plugin/src/test/java/com/google/cloud/tools/jib/maven/JibPluginConfigurationTest.java b/jib-maven-plugin/src/test/java/com/google/cloud/tools/jib/maven/JibPluginConfigurationTest.java index ec5cf635a3..cdca4be7a8 100644 --- a/jib-maven-plugin/src/test/java/com/google/cloud/tools/jib/maven/JibPluginConfigurationTest.java +++ b/jib-maven-plugin/src/test/java/com/google/cloud/tools/jib/maven/JibPluginConfigurationTest.java @@ -183,7 +183,6 @@ public void testSystemProperties() { @Test public void testPomProperties() { - project.getProperties().setProperty("jib.from.image", "fromImage"); Assert.assertEquals("fromImage", testPluginConfiguration.getBaseImage()); project.getProperties().setProperty("jib.from.credHelper", "credHelper"); From 42c07474090218dcd4559cd1375850ef6e9c7544 Mon Sep 17 00:00:00 2001 From: Louis Murerwa Date: Tue, 7 Jul 2020 16:24:54 +0000 Subject: [PATCH 04/19] Added the getPlatforms test --- .../tools/jib/maven/JibPluginConfiguration.java | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) 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 cf37309722..d88c0e354c 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 @@ -128,14 +128,10 @@ Optional getMode() { } } + /** Configuration for {@code platform} parameter. */ public static class PlatformsConfiguration { - @Parameter private String os; - @Parameter private String architecture; - - public PlatformsConfiguration(String os, String architecture) { - this.os = os; - this.architecture = architecture; - } + @Parameter private String os = "linux"; + @Parameter private String architecture = "amd64"; public String getOs() { return this.os; @@ -157,9 +153,10 @@ public static class FromConfiguration { @Parameter private List platforms; + /** Configuration for {@code platforms} parameter. */ public FromConfiguration() { platforms = new ArrayList<>(); - PlatformsConfiguration platform = new PlatformsConfiguration("linux", "amd64"); + PlatformsConfiguration platform = new PlatformsConfiguration(); platforms.add(platform); } } From d0f68fce793dc01b9136f3aa72c748fd632b72a7 Mon Sep 17 00:00:00 2001 From: Louis Murerwa Date: Tue, 7 Jul 2020 18:18:58 +0000 Subject: [PATCH 05/19] Style Fixes --- .../google/cloud/tools/jib/maven/JibPluginConfiguration.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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 d88c0e354c..cf9e4d0e48 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 @@ -153,7 +153,7 @@ public static class FromConfiguration { @Parameter private List platforms; - /** Configuration for {@code platforms} parameter. */ + /** Configuration for {@code platform} parameter. Defaults to amd64/linux. * */ public FromConfiguration() { platforms = new ArrayList<>(); PlatformsConfiguration platform = new PlatformsConfiguration(); @@ -359,7 +359,6 @@ protected void checkJibVersion() throws MojoExecutionException { * * @return the specified platforms */ - @Nullable List getPlatforms() { return from.platforms; } From c51faefc381811a72e2b2e202622afdb8360bb0f Mon Sep 17 00:00:00 2001 From: Louis Murerwa Date: Tue, 7 Jul 2020 18:22:17 +0000 Subject: [PATCH 06/19] Comment Fixes --- .../google/cloud/tools/jib/maven/JibPluginConfiguration.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 cf9e4d0e48..64dd2dd692 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 @@ -128,7 +128,7 @@ Optional getMode() { } } - /** Configuration for {@code platform} parameter. */ + /** Configuration for {@code platform} parameter. Defaults to amd64/linux. * */ public static class PlatformsConfiguration { @Parameter private String os = "linux"; @Parameter private String architecture = "amd64"; @@ -153,7 +153,7 @@ public static class FromConfiguration { @Parameter private List platforms; - /** Configuration for {@code platform} parameter. Defaults to amd64/linux. * */ + /** Constructor for defaults . * */ public FromConfiguration() { platforms = new ArrayList<>(); PlatformsConfiguration platform = new PlatformsConfiguration(); From 4fb526584a3be7113b73a04d993266d15e5b979b Mon Sep 17 00:00:00 2001 From: Louis Murerwa Date: Tue, 7 Jul 2020 18:47:41 +0000 Subject: [PATCH 07/19] Making inner classes private --- .../google/cloud/tools/jib/maven/JibPluginConfiguration.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 64dd2dd692..397540fa90 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 @@ -133,11 +133,11 @@ public static class PlatformsConfiguration { @Parameter private String os = "linux"; @Parameter private String architecture = "amd64"; - public String getOs() { + String getOs() { return this.os; } - public String getArchitecture() { + String getArchitecture() { return this.architecture; } } From 0082ce97ad2facae7c23ad5d1a1a3d6df67f2191 Mon Sep 17 00:00:00 2001 From: Karl Date: Tue, 7 Jul 2020 17:18:55 +0200 Subject: [PATCH 08/19] New option to skip pushing images (manifests) if the image (manifest) already exists in the target registry (#2531) * Adds proposal to control the pushing of tags on existing images in target registry. * Updates proposal with more detail. * Work for tags-on-existing-images.md * Cleanup. * * Simplified implementation: * Removed newly added class ManifestDescriptor, replaced it with already existing ManifestAndDigest. * Removed the CheckImageStep and incorporated the check within the PushImageStep. Implementation now follows similar checks, eg, in PushBlopStep. * Adds unit and integration tests. * Fixes resulting from testing. * Code formatting changes. * Code cleanup, post-review. * Code cleanup, post-review. * * Adds a new CheckImageStep and integrates it in the StepsRunner. * Reverts PushImageStep to the state before the PR started, apart from the manifest existence check. * Refactor code * CHANGELOG * Update comments * Improve test Co-authored-by: Chanseok Oh --- jib-core/CHANGELOG.md | 2 + .../jib/api/ContainerizerIntegrationTest.java | 51 ++++- .../ManifestCheckerIntegrationTest.java | 71 +++++++ .../jib/builder/steps/CheckImageStep.java | 89 +++++++++ .../jib/builder/steps/PushImageStep.java | 14 +- .../tools/jib/builder/steps/StepsRunner.java | 32 +++- .../tools/jib/global/JibSystemProperties.java | 12 ++ .../jib/registry/AbstractManifestPuller.java | 174 ++++++++++++++++++ .../cloud/tools/jib/registry/BlobChecker.java | 2 +- .../tools/jib/registry/ManifestChecker.java | 60 ++++++ .../tools/jib/registry/ManifestPuller.java | 142 +------------- .../tools/jib/registry/RegistryClient.java | 29 ++- .../jib/global/JibSystemPropertiesTest.java | 6 + jib-gradle-plugin/CHANGELOG.md | 1 + jib-maven-plugin/CHANGELOG.md | 1 + 15 files changed, 535 insertions(+), 151 deletions(-) create mode 100644 jib-core/src/integration-test/java/com/google/cloud/tools/jib/registry/ManifestCheckerIntegrationTest.java create mode 100644 jib-core/src/main/java/com/google/cloud/tools/jib/builder/steps/CheckImageStep.java create mode 100644 jib-core/src/main/java/com/google/cloud/tools/jib/registry/AbstractManifestPuller.java create mode 100644 jib-core/src/main/java/com/google/cloud/tools/jib/registry/ManifestChecker.java diff --git a/jib-core/CHANGELOG.md b/jib-core/CHANGELOG.md index 0c5f6417a1..1feb0866ae 100644 --- a/jib-core/CHANGELOG.md +++ b/jib-core/CHANGELOG.md @@ -5,6 +5,8 @@ All notable changes to this project will be documented in this file. ### Added +- New system property `jib.skipExistingImages` (false by default) to skip pushing images (manifests) if the image already exists in the registry. ([#2360](https://github.com/GoogleContainerTools/jib/issues/2360) + ### Changed ### Fixed diff --git a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/ContainerizerIntegrationTest.java b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/ContainerizerIntegrationTest.java index eafe6681eb..a88e3c51b3 100644 --- a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/ContainerizerIntegrationTest.java +++ b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/ContainerizerIntegrationTest.java @@ -21,6 +21,7 @@ import com.google.cloud.tools.jib.api.buildplan.FileEntriesLayer; import com.google.cloud.tools.jib.event.events.ProgressEvent; import com.google.cloud.tools.jib.event.progress.ProgressEventHandler; +import com.google.cloud.tools.jib.global.JibSystemProperties; import com.google.cloud.tools.jib.registry.LocalRegistry; import com.google.common.base.Splitter; import com.google.common.collect.ImmutableList; @@ -42,6 +43,7 @@ import org.junit.ClassRule; import org.junit.Rule; import org.junit.Test; +import org.junit.contrib.java.lang.system.RestoreSystemProperties; import org.junit.rules.TemporaryFolder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -50,6 +52,8 @@ /** Integration tests for {@link Containerizer}. */ public class ContainerizerIntegrationTest { + @Rule public final RestoreSystemProperties systemPropertyRestorer = new RestoreSystemProperties(); + /** * Helper class to hold a {@link ProgressEventHandler} and verify that it handles a full progress. */ @@ -218,7 +222,52 @@ public void testSteps_forBuildToDockerRegistry_multipleTags() } @Test - public void tesBuildToDockerRegistry_dockerHubBaseImage() + public void testSteps_forBuildToDockerRegistry_skipExistingDigest() + throws IOException, InterruptedException, ExecutionException, RegistryException, + CacheDirectoryCreationException { + System.setProperty(JibSystemProperties.SKIP_EXISTING_IMAGES, "true"); + + JibContainer image1 = + buildRegistryImage( + ImageReference.scratch(), + ImageReference.of("localhost:5000", "testimagerepo", "testtag"), + Collections.singletonList("testtag2")); + + // Test that the initial image with the original tag has been pushed. + String imageReference = "localhost:5000/testimagerepo:testtag"; + localRegistry.pull(imageReference); + + // Test that any additional tags have also been pushed with the original image. + String imageReference2 = "localhost:5000/testimagerepo:testtag2"; + localRegistry.pull(imageReference2); + + // Push the same image with a different tag, with SKIP_EXISTING_IMAGES enabled. + JibContainer image2 = + buildRegistryImage( + ImageReference.scratch(), + ImageReference.of("localhost:5000", "testimagerepo", "new_testtag"), + Collections.emptyList()); + + // Test that the pull request throws an exception, indicating that the new tag was not pushed. + try { + localRegistry.pull("localhost:5000/testimagerepo:new_testtag"); + Assert.fail( + "jib.skipExistingImages was enabled and digest was already pushed, " + + "hence new_testtag shouldn't have been pushed."); + } catch (RuntimeException ex) { + Assert.assertThat( + ex.getMessage(), + CoreMatchers.containsString( + "manifest for localhost:5000/testimagerepo:new_testtag not found")); + } + + // Test that both images have the same properties. + Assert.assertEquals(image1.getDigest(), image2.getDigest()); + Assert.assertEquals(image1.getImageId(), image2.getImageId()); + } + + @Test + public void testBuildToDockerRegistry_dockerHubBaseImage() throws InvalidImageReferenceException, IOException, InterruptedException, ExecutionException, RegistryException, CacheDirectoryCreationException { buildRegistryImage( diff --git a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/registry/ManifestCheckerIntegrationTest.java b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/registry/ManifestCheckerIntegrationTest.java new file mode 100644 index 0000000000..44afce9218 --- /dev/null +++ b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/registry/ManifestCheckerIntegrationTest.java @@ -0,0 +1,71 @@ +/* + * Copyright 2020 Google LLC. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package com.google.cloud.tools.jib.registry; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import com.google.cloud.tools.jib.api.RegistryException; +import com.google.cloud.tools.jib.event.EventHandlers; +import com.google.cloud.tools.jib.http.FailoverHttpClient; +import com.google.cloud.tools.jib.image.json.ManifestTemplate; +import java.io.IOException; +import java.util.Optional; +import org.junit.Test; + +/** Integration tests for {@link ManifestChecker}. */ +public class ManifestCheckerIntegrationTest { + + /** A known manifest list sha for openjdk:11-jre-slim. */ + private static final String KNOWN_MANIFEST = + "sha256:8ab7b3078b01ba66b937b7fbe0b9eccf60449cc101c42e99aeefaba0e1781155"; + + /** A fictitious sha to test unknown images. */ + private static final String UNKNOWN_MANIFEST = + "sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; + + private final FailoverHttpClient httpClient = new FailoverHttpClient(true, false, ignored -> {}); + + @Test + public void testExistingManifest() throws IOException, RegistryException { + RegistryClient registryClient = + RegistryClient.factory( + EventHandlers.NONE, "registry-1.docker.io", "library/openjdk", httpClient) + .newRegistryClient(); + registryClient.doPullBearerAuth(); + + Optional> manifestDescriptor = + registryClient.checkImage(KNOWN_MANIFEST); + + assertTrue(manifestDescriptor.isPresent()); + assertEquals(KNOWN_MANIFEST, manifestDescriptor.get().getDigest().toString()); + } + + @Test + public void testNonExistingManifest() throws IOException, RegistryException { + RegistryClient registryClient = + RegistryClient.factory( + EventHandlers.NONE, "registry-1.docker.io", "library/openjdk", httpClient) + .newRegistryClient(); + registryClient.doPullBearerAuth(); + + Optional> manifestDescriptor = + registryClient.checkImage(UNKNOWN_MANIFEST); + + assertEquals(Optional.empty(), manifestDescriptor); + } +} diff --git a/jib-core/src/main/java/com/google/cloud/tools/jib/builder/steps/CheckImageStep.java b/jib-core/src/main/java/com/google/cloud/tools/jib/builder/steps/CheckImageStep.java new file mode 100644 index 0000000000..ed4953a591 --- /dev/null +++ b/jib-core/src/main/java/com/google/cloud/tools/jib/builder/steps/CheckImageStep.java @@ -0,0 +1,89 @@ +/* + * Copyright 2020 Google LLC. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package com.google.cloud.tools.jib.builder.steps; + +import com.google.cloud.tools.jib.api.DescriptorDigest; +import com.google.cloud.tools.jib.api.LogEvent; +import com.google.cloud.tools.jib.api.RegistryException; +import com.google.cloud.tools.jib.blob.BlobDescriptor; +import com.google.cloud.tools.jib.builder.ProgressEventDispatcher; +import com.google.cloud.tools.jib.builder.TimerEventDispatcher; +import com.google.cloud.tools.jib.configuration.BuildContext; +import com.google.cloud.tools.jib.event.EventHandlers; +import com.google.cloud.tools.jib.global.JibSystemProperties; +import com.google.cloud.tools.jib.hash.Digests; +import com.google.cloud.tools.jib.image.Image; +import com.google.cloud.tools.jib.image.json.BuildableManifestTemplate; +import com.google.cloud.tools.jib.image.json.ImageToJsonTranslator; +import com.google.cloud.tools.jib.image.json.ManifestTemplate; +import com.google.cloud.tools.jib.registry.ManifestAndDigest; +import com.google.cloud.tools.jib.registry.RegistryClient; +import java.io.IOException; +import java.util.Optional; +import java.util.concurrent.Callable; + +/** Checks the existence of a manifest. */ +class CheckImageStep implements Callable>> { + + private static final String DESCRIPTION = "Checking existence of manifest"; + + private final BuildContext buildContext; + private final ProgressEventDispatcher.Factory progressEventDispatcherFactory; + private final RegistryClient registryClient; + private final BlobDescriptor containerConfigurationDigestAndSize; + private final Image image; + + CheckImageStep( + BuildContext buildContext, + ProgressEventDispatcher.Factory progressEventDispatcherFactory, + RegistryClient registryClient, + BlobDescriptor containerConfigurationDigestAndSize, + Image image) { + this.buildContext = buildContext; + this.progressEventDispatcherFactory = progressEventDispatcherFactory; + this.registryClient = registryClient; + this.containerConfigurationDigestAndSize = containerConfigurationDigestAndSize; + this.image = image; + } + + @Override + public Optional> call() + throws IOException, RegistryException { + BuildableManifestTemplate manifestTemplate = + new ImageToJsonTranslator(image) + .getManifestTemplate( + buildContext.getTargetFormat(), containerConfigurationDigestAndSize); + DescriptorDigest manifestDigest = Digests.computeJsonDigest(manifestTemplate); + + EventHandlers eventHandlers = buildContext.getEventHandlers(); + try (TimerEventDispatcher ignored = new TimerEventDispatcher(eventHandlers, DESCRIPTION); + ProgressEventDispatcher ignored2 = + progressEventDispatcherFactory.create( + "checking existence of manifest for " + manifestDigest, 1)) { + eventHandlers.dispatch( + LogEvent.info("Checking existence of manifest for " + manifestDigest + "...")); + + if (!JibSystemProperties.skipExistingImages()) { + eventHandlers.dispatch( + LogEvent.info("Skipping manifest existence check; system property set to false")); + return Optional.empty(); + } + + return registryClient.checkImage(manifestDigest.toString()); + } + } +} diff --git a/jib-core/src/main/java/com/google/cloud/tools/jib/builder/steps/PushImageStep.java b/jib-core/src/main/java/com/google/cloud/tools/jib/builder/steps/PushImageStep.java index 74eceddb4b..e818b45f1e 100644 --- a/jib-core/src/main/java/com/google/cloud/tools/jib/builder/steps/PushImageStep.java +++ b/jib-core/src/main/java/com/google/cloud/tools/jib/builder/steps/PushImageStep.java @@ -24,6 +24,7 @@ import com.google.cloud.tools.jib.builder.TimerEventDispatcher; import com.google.cloud.tools.jib.configuration.BuildContext; import com.google.cloud.tools.jib.event.EventHandlers; +import com.google.cloud.tools.jib.global.JibSystemProperties; import com.google.cloud.tools.jib.hash.Digests; import com.google.cloud.tools.jib.image.Image; import com.google.cloud.tools.jib.image.json.BuildableManifestTemplate; @@ -47,16 +48,23 @@ static ImmutableList makeList( ProgressEventDispatcher.Factory progressEventDispatcherFactory, RegistryClient registryClient, BlobDescriptor containerConfigurationDigestAndSize, - Image builtImage) + Image builtImage, + boolean manifestAlreadyExists) throws IOException { Set tags = buildContext.getAllTargetImageTags(); + EventHandlers eventHandlers = buildContext.getEventHandlers(); try (TimerEventDispatcher ignored = - new TimerEventDispatcher( - buildContext.getEventHandlers(), "Preparing manifest pushers"); + new TimerEventDispatcher(eventHandlers, "Preparing manifest pushers"); ProgressEventDispatcher progressEventDispatcher = progressEventDispatcherFactory.create("launching manifest pushers", tags.size())) { + if (JibSystemProperties.skipExistingImages() && manifestAlreadyExists) { + eventHandlers.dispatch( + LogEvent.info("Skipping pushing manifest; manifest already exists.")); + return ImmutableList.of(); + } + // Gets the image manifest to push. BuildableManifestTemplate manifestTemplate = new ImageToJsonTranslator(builtImage) diff --git a/jib-core/src/main/java/com/google/cloud/tools/jib/builder/steps/StepsRunner.java b/jib-core/src/main/java/com/google/cloud/tools/jib/builder/steps/StepsRunner.java index 943ca2a835..936e4cb39a 100644 --- a/jib-core/src/main/java/com/google/cloud/tools/jib/builder/steps/StepsRunner.java +++ b/jib-core/src/main/java/com/google/cloud/tools/jib/builder/steps/StepsRunner.java @@ -26,6 +26,8 @@ import com.google.cloud.tools.jib.filesystem.TempDirectoryProvider; import com.google.cloud.tools.jib.global.JibSystemProperties; import com.google.cloud.tools.jib.image.Image; +import com.google.cloud.tools.jib.image.json.ManifestTemplate; +import com.google.cloud.tools.jib.registry.ManifestAndDigest; import com.google.cloud.tools.jib.registry.RegistryClient; import com.google.common.base.Preconditions; import com.google.common.base.Verify; @@ -70,6 +72,8 @@ private static Future failedFuture() { private Future>> applicationLayerPushResults = failedFuture(); private Future containerConfigurationPushResult = failedFuture(); private Future buildResult = failedFuture(); + private Future>> manifestCheckResult = + failedFuture(); } /** @@ -175,6 +179,7 @@ public StepsRunner registryPushSteps() { stepsToRun.add(this::pushBaseImageLayers); stepsToRun.add(this::pushApplicationLayers); stepsToRun.add(this::pushContainerConfiguration); + stepsToRun.add(this::checkImageInTargetRegistry); stepsToRun.add(this::pushImages); return this; } @@ -377,6 +382,22 @@ private void pushApplicationLayers() { Verify.verifyNotNull(results.applicationLayers)))); } + private void checkImageInTargetRegistry() { + ProgressEventDispatcher.Factory childProgressDispatcherFactory = + Verify.verifyNotNull(rootProgressDispatcher).newChildProducer(); + + results.manifestCheckResult = + executorService.submit( + () -> + new CheckImageStep( + buildContext, + childProgressDispatcherFactory, + results.targetRegistryClient.get(), + results.containerConfigurationPushResult.get(), + results.builtImage.get()) + .call()); + } + private void pushImages() { ProgressEventDispatcher.Factory childProgressDispatcherFactory = Verify.verifyNotNull(rootProgressDispatcher).newChildProducer(); @@ -394,10 +415,15 @@ private void pushImages() { childProgressDispatcherFactory, results.targetRegistryClient.get(), results.containerConfigurationPushResult.get(), - results.builtImage.get())); + results.builtImage.get(), + results.manifestCheckResult.get().isPresent())); realizeFutures(manifestPushResults); - // Manifest pushers return the same BuildResult. - return manifestPushResults.get(0).get(); + return manifestPushResults.isEmpty() + ? new BuildResult( + results.manifestCheckResult.get().get().getDigest(), + results.containerConfigurationPushResult.get().getDigest()) + // Manifest pushers return the same BuildResult. + : manifestPushResults.get(0).get(); }); } diff --git a/jib-core/src/main/java/com/google/cloud/tools/jib/global/JibSystemProperties.java b/jib-core/src/main/java/com/google/cloud/tools/jib/global/JibSystemProperties.java index 329f4b4fcb..a96ce24aee 100644 --- a/jib-core/src/main/java/com/google/cloud/tools/jib/global/JibSystemProperties.java +++ b/jib-core/src/main/java/com/google/cloud/tools/jib/global/JibSystemProperties.java @@ -36,6 +36,8 @@ public class JibSystemProperties { private static final String DISABLE_USER_AGENT = "_JIB_DISABLE_USER_AGENT"; + @VisibleForTesting public static final String SKIP_EXISTING_IMAGES = "jib.skipExistingImages"; + /** * Gets the HTTP connection/read timeouts for registry interactions in milliseconds. This is * defined by the {@code jib.httpTimeout} system property. The default value is 20000 if the @@ -114,6 +116,16 @@ public static void checkProxyPortProperty() throws NumberFormatException { checkNumericSystemProperty("https.proxyPort", Range.closed(0, 65535)); } + /** + * Gets whether or not to skip pushing tags to existing images. This is defined by the {@code + * jib.skipExistingImages} system property. + * + * @return {@code true} if Jib should skip pushing tags to existing images, {@code false} if not + */ + public static boolean skipExistingImages() { + return Boolean.getBoolean(SKIP_EXISTING_IMAGES); + } + private static void checkNumericSystemProperty(String property, Range validRange) { String value = System.getProperty(property); if (value == null) { diff --git a/jib-core/src/main/java/com/google/cloud/tools/jib/registry/AbstractManifestPuller.java b/jib-core/src/main/java/com/google/cloud/tools/jib/registry/AbstractManifestPuller.java new file mode 100644 index 0000000000..a9da20046a --- /dev/null +++ b/jib-core/src/main/java/com/google/cloud/tools/jib/registry/AbstractManifestPuller.java @@ -0,0 +1,174 @@ +/* + * Copyright 2017 Google LLC. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package com.google.cloud.tools.jib.registry; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ObjectNode; +import com.google.api.client.http.HttpMethods; +import com.google.cloud.tools.jib.api.DescriptorDigest; +import com.google.cloud.tools.jib.hash.Digests; +import com.google.cloud.tools.jib.http.BlobHttpContent; +import com.google.cloud.tools.jib.http.Response; +import com.google.cloud.tools.jib.http.ResponseException; +import com.google.cloud.tools.jib.image.json.ManifestTemplate; +import com.google.cloud.tools.jib.image.json.OciManifestTemplate; +import com.google.cloud.tools.jib.image.json.UnknownManifestFormatException; +import com.google.cloud.tools.jib.image.json.V21ManifestTemplate; +import com.google.cloud.tools.jib.image.json.V22ManifestListTemplate; +import com.google.cloud.tools.jib.image.json.V22ManifestTemplate; +import com.google.cloud.tools.jib.json.JsonTemplateMapper; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.nio.charset.StandardCharsets; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import javax.annotation.Nullable; + +/** Base class for manifest pullers. */ +abstract class AbstractManifestPuller + implements RegistryEndpointProvider { + + private final RegistryEndpointRequestProperties registryEndpointRequestProperties; + private final String imageQualifier; + private final Class manifestTemplateClass; + + AbstractManifestPuller( + RegistryEndpointRequestProperties registryEndpointRequestProperties, + String imageQualifier, + Class manifestTemplateClass) { + this.registryEndpointRequestProperties = registryEndpointRequestProperties; + this.imageQualifier = imageQualifier; + this.manifestTemplateClass = manifestTemplateClass; + } + + @Nullable + @Override + public BlobHttpContent getContent() { + return null; + } + + @Override + public List getAccept() { + if (manifestTemplateClass.equals(V21ManifestTemplate.class)) { + return Collections.singletonList(V21ManifestTemplate.MEDIA_TYPE); + } + if (manifestTemplateClass.equals(V22ManifestTemplate.class)) { + return Collections.singletonList(V22ManifestTemplate.MANIFEST_MEDIA_TYPE); + } + if (manifestTemplateClass.equals(OciManifestTemplate.class)) { + return Collections.singletonList(OciManifestTemplate.MANIFEST_MEDIA_TYPE); + } + if (manifestTemplateClass.equals(V22ManifestListTemplate.class)) { + return Collections.singletonList(V22ManifestListTemplate.MANIFEST_MEDIA_TYPE); + } + + // V22ManifestListTemplate is not included by default, we don't explicitly accept + // it, we only handle it if referenced by sha256 (see getManifestTemplateFromJson) in which + // case registries ignore the "accept" directive and just return a manifest list anyway. + return Arrays.asList( + OciManifestTemplate.MANIFEST_MEDIA_TYPE, + V22ManifestTemplate.MANIFEST_MEDIA_TYPE, + V21ManifestTemplate.MEDIA_TYPE); + } + + /** Parses the response body into a {@link ManifestAndDigest}. */ + @Override + public R handleResponse(Response response) throws IOException, UnknownManifestFormatException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + DescriptorDigest digest = + Digests.computeDigest(response.getBody(), byteArrayOutputStream).getDigest(); + String jsonString = byteArrayOutputStream.toString(StandardCharsets.UTF_8.name()); + T manifestTemplate = getManifestTemplateFromJson(jsonString); + return computeReturn(new ManifestAndDigest<>(manifestTemplate, digest)); + } + + abstract R computeReturn(ManifestAndDigest manifestAndDigest); + + @Override + public URL getApiRoute(String apiRouteBase) throws MalformedURLException { + return new URL( + apiRouteBase + + registryEndpointRequestProperties.getImageName() + + "/manifests/" + + imageQualifier); + } + + @Override + public String getHttpMethod() { + return HttpMethods.GET; + } + + @Override + public String getActionDescription() { + return "pull image manifest for " + + registryEndpointRequestProperties.getServerUrl() + + "/" + + registryEndpointRequestProperties.getImageName() + + ":" + + imageQualifier; + } + + /** + * Instantiates a {@link ManifestTemplate} from a JSON string. This checks the {@code + * schemaVersion} field of the JSON to determine which manifest version to use. + */ + private T getManifestTemplateFromJson(String jsonString) + throws IOException, UnknownManifestFormatException { + ObjectNode node = new ObjectMapper().readValue(jsonString, ObjectNode.class); + if (!node.has("schemaVersion")) { + throw new UnknownManifestFormatException("Cannot find field 'schemaVersion' in manifest"); + } + + int schemaVersion = node.get("schemaVersion").asInt(-1); + if (schemaVersion == -1) { + throw new UnknownManifestFormatException("`schemaVersion` field is not an integer"); + } + + if (schemaVersion == 1) { + return manifestTemplateClass.cast( + JsonTemplateMapper.readJson(jsonString, V21ManifestTemplate.class)); + } + if (schemaVersion == 2) { + // 'schemaVersion' of 2 can be either Docker V2.2 or OCI. + String mediaType = node.get("mediaType").asText(); + if (V22ManifestTemplate.MANIFEST_MEDIA_TYPE.equals(mediaType)) { + return manifestTemplateClass.cast( + JsonTemplateMapper.readJson(jsonString, V22ManifestTemplate.class)); + } + if (OciManifestTemplate.MANIFEST_MEDIA_TYPE.equals(mediaType)) { + return manifestTemplateClass.cast( + JsonTemplateMapper.readJson(jsonString, OciManifestTemplate.class)); + } + if (V22ManifestListTemplate.MANIFEST_MEDIA_TYPE.equals(mediaType)) { + return manifestTemplateClass.cast( + JsonTemplateMapper.readJson(jsonString, V22ManifestListTemplate.class)); + } + throw new UnknownManifestFormatException("Unknown mediaType: " + mediaType); + } + throw new UnknownManifestFormatException( + "Unknown schemaVersion: " + schemaVersion + " - only 1 and 2 are supported"); + } + + @Override + public R handleHttpResponseException(ResponseException responseException) + throws ResponseException, RegistryErrorException { + throw responseException; + } +} diff --git a/jib-core/src/main/java/com/google/cloud/tools/jib/registry/BlobChecker.java b/jib-core/src/main/java/com/google/cloud/tools/jib/registry/BlobChecker.java index e39288e9bb..470ddfadde 100644 --- a/jib-core/src/main/java/com/google/cloud/tools/jib/registry/BlobChecker.java +++ b/jib-core/src/main/java/com/google/cloud/tools/jib/registry/BlobChecker.java @@ -66,13 +66,13 @@ public Optional handleHttpResponseException(ResponseException re throw responseException; } - // Finds a BLOB_UNKNOWN error response code. if (responseException.getContent() == null) { // TODO: The Google HTTP client gives null content for HEAD requests. Make the content never // be null, even for HEAD requests. return Optional.empty(); } + // Find a BLOB_UNKNOWN error response code. ErrorCodes errorCode = ErrorResponseUtil.getErrorCode(responseException); if (errorCode == ErrorCodes.BLOB_UNKNOWN) { return Optional.empty(); diff --git a/jib-core/src/main/java/com/google/cloud/tools/jib/registry/ManifestChecker.java b/jib-core/src/main/java/com/google/cloud/tools/jib/registry/ManifestChecker.java new file mode 100644 index 0000000000..31ab274677 --- /dev/null +++ b/jib-core/src/main/java/com/google/cloud/tools/jib/registry/ManifestChecker.java @@ -0,0 +1,60 @@ +/* + * Copyright 2020 Google LLC. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package com.google.cloud.tools.jib.registry; + +import com.google.api.client.http.HttpStatusCodes; +import com.google.cloud.tools.jib.http.ResponseException; +import com.google.cloud.tools.jib.image.json.ManifestTemplate; +import java.util.Optional; + +/** Checks an image's manifest. */ +class ManifestChecker + extends AbstractManifestPuller>> { + + ManifestChecker( + RegistryEndpointRequestProperties registryEndpointRequestProperties, + String imageQualifier, + Class manifestTemplateClass) { + super(registryEndpointRequestProperties, imageQualifier, manifestTemplateClass); + } + + @Override + public Optional> handleHttpResponseException( + ResponseException responseException) throws ResponseException { + if (responseException.getStatusCode() != HttpStatusCodes.STATUS_CODE_NOT_FOUND) { + throw responseException; + } + + if (responseException.getContent() == null) { + return Optional.empty(); + } + + // Find a MANIFEST_UNKNOWN error response code. + ErrorCodes errorCode = ErrorResponseUtil.getErrorCode(responseException); + if (errorCode == ErrorCodes.MANIFEST_UNKNOWN) { + return Optional.empty(); + } + + // MANIFEST_UNKNOWN was not found as a error response code. + throw responseException; + } + + @Override + Optional> computeReturn(ManifestAndDigest manifestAndDigest) { + return Optional.of(manifestAndDigest); + } +} diff --git a/jib-core/src/main/java/com/google/cloud/tools/jib/registry/ManifestPuller.java b/jib-core/src/main/java/com/google/cloud/tools/jib/registry/ManifestPuller.java index 1e9756af15..f6ddfc5ce0 100644 --- a/jib-core/src/main/java/com/google/cloud/tools/jib/registry/ManifestPuller.java +++ b/jib-core/src/main/java/com/google/cloud/tools/jib/registry/ManifestPuller.java @@ -16,155 +16,21 @@ package com.google.cloud.tools.jib.registry; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.node.ObjectNode; -import com.google.api.client.http.HttpMethods; -import com.google.cloud.tools.jib.api.DescriptorDigest; -import com.google.cloud.tools.jib.hash.Digests; -import com.google.cloud.tools.jib.http.BlobHttpContent; -import com.google.cloud.tools.jib.http.Response; -import com.google.cloud.tools.jib.http.ResponseException; import com.google.cloud.tools.jib.image.json.ManifestTemplate; -import com.google.cloud.tools.jib.image.json.OciManifestTemplate; -import com.google.cloud.tools.jib.image.json.UnknownManifestFormatException; -import com.google.cloud.tools.jib.image.json.V21ManifestTemplate; -import com.google.cloud.tools.jib.image.json.V22ManifestListTemplate; -import com.google.cloud.tools.jib.image.json.V22ManifestTemplate; -import com.google.cloud.tools.jib.json.JsonTemplateMapper; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URL; -import java.nio.charset.StandardCharsets; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import javax.annotation.Nullable; /** Pulls an image's manifest. */ class ManifestPuller - implements RegistryEndpointProvider> { - - private final RegistryEndpointRequestProperties registryEndpointRequestProperties; - private final String imageTag; - private final Class manifestTemplateClass; + extends AbstractManifestPuller> { ManifestPuller( RegistryEndpointRequestProperties registryEndpointRequestProperties, String imageTag, Class manifestTemplateClass) { - this.registryEndpointRequestProperties = registryEndpointRequestProperties; - this.imageTag = imageTag; - this.manifestTemplateClass = manifestTemplateClass; - } - - @Nullable - @Override - public BlobHttpContent getContent() { - return null; - } - - @Override - public List getAccept() { - if (manifestTemplateClass.equals(V21ManifestTemplate.class)) { - return Collections.singletonList(V21ManifestTemplate.MEDIA_TYPE); - } - if (manifestTemplateClass.equals(V22ManifestTemplate.class)) { - return Collections.singletonList(V22ManifestTemplate.MANIFEST_MEDIA_TYPE); - } - if (manifestTemplateClass.equals(OciManifestTemplate.class)) { - return Collections.singletonList(OciManifestTemplate.MANIFEST_MEDIA_TYPE); - } - if (manifestTemplateClass.equals(V22ManifestListTemplate.class)) { - return Collections.singletonList(V22ManifestListTemplate.MANIFEST_MEDIA_TYPE); - } - - // V22ManifestListTemplate is not included by default, we don't explicitly accept - // it, we only handle it if referenced by sha256 (see getManifestTemplateFromJson) in which - // case registries ignore the "accept" directive and just return a manifest list anyway. - return Arrays.asList( - OciManifestTemplate.MANIFEST_MEDIA_TYPE, - V22ManifestTemplate.MANIFEST_MEDIA_TYPE, - V21ManifestTemplate.MEDIA_TYPE); - } - - /** Parses the response body into a {@link ManifestAndDigest}. */ - @Override - public ManifestAndDigest handleResponse(Response response) - throws IOException, UnknownManifestFormatException { - ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); - DescriptorDigest digest = - Digests.computeDigest(response.getBody(), byteArrayOutputStream).getDigest(); - String jsonString = byteArrayOutputStream.toString(StandardCharsets.UTF_8.name()); - T manifestTemplate = getManifestTemplateFromJson(jsonString); - return new ManifestAndDigest<>(manifestTemplate, digest); - } - - @Override - public URL getApiRoute(String apiRouteBase) throws MalformedURLException { - return new URL( - apiRouteBase + registryEndpointRequestProperties.getImageName() + "/manifests/" + imageTag); - } - - @Override - public String getHttpMethod() { - return HttpMethods.GET; - } - - @Override - public String getActionDescription() { - return "pull image manifest for " - + registryEndpointRequestProperties.getServerUrl() - + "/" - + registryEndpointRequestProperties.getImageName() - + ":" - + imageTag; - } - - /** - * Instantiates a {@link ManifestTemplate} from a JSON string. This checks the {@code - * schemaVersion} field of the JSON to determine which manifest version to use. - */ - private T getManifestTemplateFromJson(String jsonString) - throws IOException, UnknownManifestFormatException { - ObjectNode node = new ObjectMapper().readValue(jsonString, ObjectNode.class); - if (!node.has("schemaVersion")) { - throw new UnknownManifestFormatException("Cannot find field 'schemaVersion' in manifest"); - } - - int schemaVersion = node.get("schemaVersion").asInt(-1); - if (schemaVersion == -1) { - throw new UnknownManifestFormatException("`schemaVersion` field is not an integer"); - } - - if (schemaVersion == 1) { - return manifestTemplateClass.cast( - JsonTemplateMapper.readJson(jsonString, V21ManifestTemplate.class)); - } - if (schemaVersion == 2) { - // 'schemaVersion' of 2 can be either Docker V2.2 or OCI. - String mediaType = node.get("mediaType").asText(); - if (V22ManifestTemplate.MANIFEST_MEDIA_TYPE.equals(mediaType)) { - return manifestTemplateClass.cast( - JsonTemplateMapper.readJson(jsonString, V22ManifestTemplate.class)); - } - if (OciManifestTemplate.MANIFEST_MEDIA_TYPE.equals(mediaType)) { - return manifestTemplateClass.cast( - JsonTemplateMapper.readJson(jsonString, OciManifestTemplate.class)); - } - if (V22ManifestListTemplate.MANIFEST_MEDIA_TYPE.equals(mediaType)) { - return manifestTemplateClass.cast( - JsonTemplateMapper.readJson(jsonString, V22ManifestListTemplate.class)); - } - throw new UnknownManifestFormatException("Unknown mediaType: " + mediaType); - } - throw new UnknownManifestFormatException( - "Unknown schemaVersion: " + schemaVersion + " - only 1 and 2 are supported"); + super(registryEndpointRequestProperties, imageTag, manifestTemplateClass); } @Override - public ManifestAndDigest handleHttpResponseException(ResponseException responseException) - throws ResponseException, RegistryErrorException { - throw responseException; + ManifestAndDigest computeReturn(ManifestAndDigest manifestAndDigest) { + return manifestAndDigest; } } diff --git a/jib-core/src/main/java/com/google/cloud/tools/jib/registry/RegistryClient.java b/jib-core/src/main/java/com/google/cloud/tools/jib/registry/RegistryClient.java index c652f487bc..4bcdea13dd 100644 --- a/jib-core/src/main/java/com/google/cloud/tools/jib/registry/RegistryClient.java +++ b/jib-core/src/main/java/com/google/cloud/tools/jib/registry/RegistryClient.java @@ -367,11 +367,28 @@ private Authorization refreshBearerAuth(@Nullable String wwwAuthenticate) return Verify.verifyNotNull(initialBearerAuthenticator.get()).authenticatePush(credential); } + /** + * Check if an image is on the registry. + * + * @param imageQualifier the tag or digest to check for + * @return the {@link ManifestAndDigest} of the image if the image exists on the registry, or + * {@link Optional#empty()} otherwise + * @throws IOException if communicating with the endpoint fails + * @throws RegistryException if communicating with the endpoint fails + */ + public Optional> checkImage(String imageQualifier) + throws IOException, RegistryException { + ManifestChecker manifestChecker = + new ManifestChecker<>( + registryEndpointRequestProperties, imageQualifier, ManifestTemplate.class); + return callRegistryEndpoint(manifestChecker); + } + /** * Pulls the image manifest and digest for a specific tag. * * @param child type of ManifestTemplate - * @param imageTag the tag to pull on + * @param imageQualifier the tag or digest to pull on * @param manifestTemplateClass the specific version of manifest template to pull, or {@link * ManifestTemplate} to pull predefined subclasses; see: {@link * ManifestPuller#handleResponse(Response)} @@ -380,14 +397,16 @@ private Authorization refreshBearerAuth(@Nullable String wwwAuthenticate) * @throws RegistryException if communicating with the endpoint fails */ public ManifestAndDigest pullManifest( - String imageTag, Class manifestTemplateClass) throws IOException, RegistryException { + String imageQualifier, Class manifestTemplateClass) throws IOException, RegistryException { ManifestPuller manifestPuller = - new ManifestPuller<>(registryEndpointRequestProperties, imageTag, manifestTemplateClass); + new ManifestPuller<>( + registryEndpointRequestProperties, imageQualifier, manifestTemplateClass); return callRegistryEndpoint(manifestPuller); } - public ManifestAndDigest pullManifest(String imageTag) throws IOException, RegistryException { - return pullManifest(imageTag, ManifestTemplate.class); + public ManifestAndDigest pullManifest(String imageQualifier) + throws IOException, RegistryException { + return pullManifest(imageQualifier, ManifestTemplate.class); } /** diff --git a/jib-core/src/test/java/com/google/cloud/tools/jib/global/JibSystemPropertiesTest.java b/jib-core/src/test/java/com/google/cloud/tools/jib/global/JibSystemPropertiesTest.java index b66fec1e4f..8774de988b 100644 --- a/jib-core/src/test/java/com/google/cloud/tools/jib/global/JibSystemPropertiesTest.java +++ b/jib-core/src/test/java/com/google/cloud/tools/jib/global/JibSystemPropertiesTest.java @@ -160,4 +160,10 @@ public void testUseBlobMounts_other() { System.setProperty(JibSystemProperties.CROSS_REPOSITORY_BLOB_MOUNTS, "nonbool"); Assert.assertFalse(JibSystemProperties.useCrossRepositoryBlobMounts()); } + + @Test + public void testSkipExistingImages_undefined() { + System.clearProperty(JibSystemProperties.SKIP_EXISTING_IMAGES); + Assert.assertFalse(JibSystemProperties.skipExistingImages()); + } } diff --git a/jib-gradle-plugin/CHANGELOG.md b/jib-gradle-plugin/CHANGELOG.md index da5ec8031f..c21f3e7900 100644 --- a/jib-gradle-plugin/CHANGELOG.md +++ b/jib-gradle-plugin/CHANGELOG.md @@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file. ### Added - Also tries `.exe` file extension for credential helpers on Windows. ([#2527](https://github.com/GoogleContainerTools/jib/issues/2527)) +- New system property `jib.skipExistingImages` (false by default) to skip pushing images (manifests) if the image already exists in the registry. ([#2360](https://github.com/GoogleContainerTools/jib/issues/2360) ### Changed diff --git a/jib-maven-plugin/CHANGELOG.md b/jib-maven-plugin/CHANGELOG.md index d3f4e87428..a8a973083e 100644 --- a/jib-maven-plugin/CHANGELOG.md +++ b/jib-maven-plugin/CHANGELOG.md @@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file. ### Added - Also tries `.exe` file extension for credential helpers on Windows. ([#2527](https://github.com/GoogleContainerTools/jib/issues/2527)) +- New system property `jib.skipExistingImages` (false by default) to skip pushing images (manifests) if the image already exists in the registry. ([#2360](https://github.com/GoogleContainerTools/jib/issues/2360) ### Changed From 22fcbbfe026f944e225a10f58742adba490095d0 Mon Sep 17 00:00:00 2001 From: Louis Murerwa Date: Wed, 8 Jul 2020 15:00:47 +0000 Subject: [PATCH 09/19] Making the os/platform nullable --- .../tools/jib/maven/JibPluginConfiguration.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) 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 397540fa90..0e631fb644 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 @@ -27,7 +27,6 @@ import java.nio.file.InvalidPathException; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; import java.util.List; @@ -128,15 +127,17 @@ Optional getMode() { } } - /** Configuration for {@code platform} parameter. Defaults to amd64/linux. * */ + /** Configuration for {@code platform} parameter. * */ public static class PlatformsConfiguration { - @Parameter private String os = "linux"; - @Parameter private String architecture = "amd64"; + @Nullable @Parameter private String os; + @Nullable @Parameter private String architecture; + @Nullable String getOs() { return this.os; } + @Nullable String getArchitecture() { return this.architecture; } @@ -155,9 +156,10 @@ public static class FromConfiguration { /** Constructor for defaults . * */ public FromConfiguration() { - platforms = new ArrayList<>(); PlatformsConfiguration platform = new PlatformsConfiguration(); - platforms.add(platform); + platform.os = "linux"; + platform.architecture = "amd64"; + platforms = Collections.singletonList(platform); } } From 09533eda36e44459779a7f45d50f9271cdd79af3 Mon Sep 17 00:00:00 2001 From: Louis Murerwa Date: Wed, 8 Jul 2020 16:20:27 +0000 Subject: [PATCH 10/19] Style Fixes --- .../google/cloud/tools/jib/maven/JibPluginConfiguration.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 0e631fb644..64d9172316 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 @@ -127,7 +127,7 @@ Optional getMode() { } } - /** Configuration for {@code platform} parameter. * */ + /** Configuration for {@code platform} parameter. */ public static class PlatformsConfiguration { @Nullable @Parameter private String os; @Nullable @Parameter private String architecture; @@ -154,7 +154,7 @@ public static class FromConfiguration { @Parameter private List platforms; - /** Constructor for defaults . * */ + /** Constructor for defaults. */ public FromConfiguration() { PlatformsConfiguration platform = new PlatformsConfiguration(); platform.os = "linux"; From 8d9a3b8516c24ad305652a9cc866d7b30ed13ccb Mon Sep 17 00:00:00 2001 From: Louis Murerwa Date: Wed, 8 Jul 2020 18:03:12 +0000 Subject: [PATCH 11/19] Adding getPlatforms() to RawConfiguration --- .../jib/maven/JibPluginConfiguration.java | 21 ++++++++++--------- .../jib/maven/MavenRawConfiguration.java | 5 +++++ .../jib/maven/JibPluginConfigurationTest.java | 5 +++-- .../jib/plugins/common/RawConfiguration.java | 9 ++++++++ 4 files changed, 28 insertions(+), 12 deletions(-) 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 64d9172316..a48b24f383 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 @@ -20,6 +20,7 @@ import com.google.cloud.tools.jib.plugins.common.ConfigurationPropertyValidator; import com.google.cloud.tools.jib.plugins.common.PropertyNames; import com.google.cloud.tools.jib.plugins.common.RawConfiguration.ExtensionConfiguration; +import com.google.cloud.tools.jib.plugins.common.RawConfiguration.PlatformsConfiguration; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Preconditions; import com.google.common.base.Strings; @@ -128,18 +129,18 @@ Optional getMode() { } /** Configuration for {@code platform} parameter. */ - public static class PlatformsConfiguration { + public static class PlatformsParameters implements PlatformsConfiguration { @Nullable @Parameter private String os; @Nullable @Parameter private String architecture; - @Nullable - String getOs() { - return this.os; + @Override + public Optional getOs() { + return Optional.ofNullable(this.os); } - @Nullable - String getArchitecture() { - return this.architecture; + @Override + public Optional getArchitecture() { + return Optional.ofNullable(this.architecture); } } @@ -152,11 +153,11 @@ public static class FromConfiguration { @Parameter private FromAuthConfiguration auth = new FromAuthConfiguration(); - @Parameter private List platforms; + @Parameter private List platforms; /** Constructor for defaults. */ public FromConfiguration() { - PlatformsConfiguration platform = new PlatformsConfiguration(); + PlatformsParameters platform = new PlatformsParameters(); platform.os = "linux"; platform.architecture = "amd64"; platforms = Collections.singletonList(platform); @@ -361,7 +362,7 @@ protected void checkJibVersion() throws MojoExecutionException { * * @return the specified platforms */ - List getPlatforms() { + List getPlatforms() { return from.platforms; } 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 8493675fae..bbc19260d6 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 @@ -217,4 +217,9 @@ public Path getImageJsonOutputPath() { public List getPluginExtensions() { return jibPluginConfiguration.getPluginExtensions(); } + + @Override + public List getPlatforms() { + return jibPluginConfiguration.getPlatforms(); + } } diff --git a/jib-maven-plugin/src/test/java/com/google/cloud/tools/jib/maven/JibPluginConfigurationTest.java b/jib-maven-plugin/src/test/java/com/google/cloud/tools/jib/maven/JibPluginConfigurationTest.java index cdca4be7a8..a658a3f331 100644 --- a/jib-maven-plugin/src/test/java/com/google/cloud/tools/jib/maven/JibPluginConfigurationTest.java +++ b/jib-maven-plugin/src/test/java/com/google/cloud/tools/jib/maven/JibPluginConfigurationTest.java @@ -69,8 +69,9 @@ public Log getLog() { @Test public void testDefaults() { - Assert.assertEquals("linux", testPluginConfiguration.getPlatforms().get(0).getOs()); - Assert.assertEquals("amd64", testPluginConfiguration.getPlatforms().get(0).getArchitecture()); + Assert.assertEquals("linux", testPluginConfiguration.getPlatforms().get(0).getOs().get()); + Assert.assertEquals( + "amd64", testPluginConfiguration.getPlatforms().get(0).getArchitecture().get()); Assert.assertEquals("", testPluginConfiguration.getAppRoot()); Assert.assertNull(testPluginConfiguration.getWorkingDirectory()); Assert.assertTrue(testPluginConfiguration.getExtraClasspath().isEmpty()); 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 7e1d720c48..381e4648d4 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 @@ -40,6 +40,13 @@ static interface ExtensionConfiguration { Optional getExtraConfiguration(); } + static interface PlatformsConfiguration { + + Optional getOs(); + + Optional getArchitecture(); + } + Optional getFromImage(); Optional getToImage(); @@ -107,4 +114,6 @@ static interface ExtensionConfiguration { Path getImageJsonOutputPath(); List getPluginExtensions(); + + List getPlatforms(); } From 977f9b7874ebacf15f0d38eafff9a1b087af2b39 Mon Sep 17 00:00:00 2001 From: Louis Murerwa Date: Thu, 9 Jul 2020 16:03:21 +0000 Subject: [PATCH 12/19] Adding the Jib config parameter to jib-gradle-plugin --- .../tools/jib/gradle/BaseImageParameters.java | 23 ++++++++- .../jib/gradle/GradleRawConfiguration.java | 5 ++ .../cloud/tools/jib/gradle/JibExtension.java | 6 +++ .../tools/jib/gradle/PlatformsParameters.java | 36 ++++++++++++++ .../jib/gradle/PlatformsParametersSpec.java | 47 +++++++++++++++++++ 5 files changed, 115 insertions(+), 2 deletions(-) create mode 100644 jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/PlatformsParameters.java create mode 100644 jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/PlatformsParametersSpec.java diff --git a/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/BaseImageParameters.java b/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/BaseImageParameters.java index c1afc93ec7..2e9195539c 100644 --- a/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/BaseImageParameters.java +++ b/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/BaseImageParameters.java @@ -21,6 +21,7 @@ import javax.inject.Inject; import org.gradle.api.Action; import org.gradle.api.model.ObjectFactory; +import org.gradle.api.provider.ListProperty; import org.gradle.api.tasks.Input; import org.gradle.api.tasks.Nested; import org.gradle.api.tasks.Optional; @@ -29,13 +30,31 @@ public class BaseImageParameters { private final AuthParameters auth; - - @Nullable private String image; @Nullable private String credHelper; + @Nullable private String image; + private final PlatformsParametersSpec platformsParametersSpec; + private ListProperty platforms; @Inject public BaseImageParameters(ObjectFactory objectFactory) { auth = objectFactory.newInstance(AuthParameters.class, "from.auth"); + platforms = objectFactory.listProperty(PlatformsParameters.class).empty(); + platformsParametersSpec = + objectFactory.newInstance(PlatformsParametersSpec.class, objectFactory, platforms); + + PlatformsParameters platform = new PlatformsParameters(); + platform.os = "linux"; + platform.architecture = "amd64"; + platforms.add(platform); + } + + @Input + ListProperty getPlatforms() { + return platforms; + } + + public void platforms(Action action) { + action.execute(platformsParametersSpec); } @Input diff --git a/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/GradleRawConfiguration.java b/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/GradleRawConfiguration.java index a4d15f8449..ba213a4e20 100644 --- a/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/GradleRawConfiguration.java +++ b/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/GradleRawConfiguration.java @@ -215,4 +215,9 @@ public Path getImageJsonOutputPath() { public List getPluginExtensions() { return jibExtension.getPluginExtensions().get(); } + + @Override + public List getPlatforms() { + return jibExtension.getFrom().getPlatforms().get(); + } } diff --git a/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/JibExtension.java b/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/JibExtension.java index 6b85f6aa01..5794d6c972 100644 --- a/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/JibExtension.java +++ b/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/JibExtension.java @@ -37,6 +37,12 @@ * from { * image = 'gcr.io/my-gcp-project/my-base-image' * credHelper = 'gcr' + * platforms { + * platform { + * os = 'value1' + * architecture = 'value2' + * } + * } * } * to { * image = 'gcr.io/gcp-project/my-app:built-with-jib' diff --git a/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/PlatformsParameters.java b/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/PlatformsParameters.java new file mode 100644 index 0000000000..2592ff1bdf --- /dev/null +++ b/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/PlatformsParameters.java @@ -0,0 +1,36 @@ +/* + * Copyright 2020 Google LLC. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package com.google.cloud.tools.jib.gradle; + +import com.google.cloud.tools.jib.plugins.common.RawConfiguration.PlatformsConfiguration; +import javax.annotation.Nullable; + +/** Configuration of a platform. */ +public class PlatformsParameters implements PlatformsConfiguration { + @Nullable String os; + @Nullable String architecture; + + @Override + public java.util.Optional getOs() { + return java.util.Optional.ofNullable(this.os); + } + + @Override + public java.util.Optional getArchitecture() { + return java.util.Optional.ofNullable(this.architecture); + } +} diff --git a/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/PlatformsParametersSpec.java b/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/PlatformsParametersSpec.java new file mode 100644 index 0000000000..212cb9ef66 --- /dev/null +++ b/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/PlatformsParametersSpec.java @@ -0,0 +1,47 @@ +/* + * Copyright 2020 Google LLC. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package com.google.cloud.tools.jib.gradle; + +import javax.inject.Inject; +import org.gradle.api.Action; +import org.gradle.api.model.ObjectFactory; +import org.gradle.api.provider.ListProperty; + +/** Allows to add {@link PlatformsParameters} objects to the list property of the same type. */ +public class PlatformsParametersSpec { + + private final ObjectFactory objectFactory; + private final ListProperty platforms; + + @Inject + public PlatformsParametersSpec( + ObjectFactory objectFactory, ListProperty platforms) { + this.platforms = platforms; + this.objectFactory = objectFactory; + } + + /** + * Adds a new platform configuration to the platforms list. + * + * @param action closure representing a platform configuration + */ + public void platform(Action action) { + PlatformsParameters platform = objectFactory.newInstance(PlatformsParameters.class); + action.execute(platform); + platforms.add(platform); + } +} From 532076c692d4a27fb6f9919e5be1dd200b16bcb1 Mon Sep 17 00:00:00 2001 From: Louis Murerwa Date: Thu, 9 Jul 2020 16:19:44 +0000 Subject: [PATCH 13/19] Style Fixes --- .../com/google/cloud/tools/jib/gradle/BaseImageParameters.java | 1 - 1 file changed, 1 deletion(-) diff --git a/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/BaseImageParameters.java b/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/BaseImageParameters.java index 2e9195539c..4e32b01a36 100644 --- a/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/BaseImageParameters.java +++ b/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/BaseImageParameters.java @@ -48,7 +48,6 @@ public BaseImageParameters(ObjectFactory objectFactory) { platforms.add(platform); } - @Input ListProperty getPlatforms() { return platforms; } From 368f971ab8feb9f5dc1d533f47bf1ee89222303d Mon Sep 17 00:00:00 2001 From: Louis Murerwa Date: Thu, 9 Jul 2020 18:23:16 +0000 Subject: [PATCH 14/19] Making Platforms Parameter Singular --- .../tools/jib/gradle/BaseImageParameters.java | 14 +++++++------- .../tools/jib/gradle/GradleRawConfiguration.java | 2 +- .../cloud/tools/jib/gradle/JibExtension.java | 4 ++-- ...ormsParameters.java => PlatformParameters.java} | 13 +++++++------ ...metersSpec.java => PlatformParametersSpec.java} | 14 +++++++------- .../tools/jib/maven/JibPluginConfiguration.java | 4 ++-- .../tools/jib/maven/MavenRawConfiguration.java | 2 +- .../tools/jib/plugins/common/RawConfiguration.java | 4 ++-- 8 files changed, 29 insertions(+), 28 deletions(-) rename jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/{PlatformsParameters.java => PlatformParameters.java} (73%) rename jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/{PlatformsParametersSpec.java => PlatformParametersSpec.java} (70%) diff --git a/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/BaseImageParameters.java b/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/BaseImageParameters.java index 4e32b01a36..92f9584cd3 100644 --- a/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/BaseImageParameters.java +++ b/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/BaseImageParameters.java @@ -32,27 +32,27 @@ public class BaseImageParameters { private final AuthParameters auth; @Nullable private String credHelper; @Nullable private String image; - private final PlatformsParametersSpec platformsParametersSpec; - private ListProperty platforms; + private final PlatformParametersSpec platformsParametersSpec; + private final ListProperty platforms; @Inject public BaseImageParameters(ObjectFactory objectFactory) { auth = objectFactory.newInstance(AuthParameters.class, "from.auth"); - platforms = objectFactory.listProperty(PlatformsParameters.class).empty(); + platforms = objectFactory.listProperty(PlatformParameters.class).empty(); platformsParametersSpec = - objectFactory.newInstance(PlatformsParametersSpec.class, objectFactory, platforms); + objectFactory.newInstance(PlatformParametersSpec.class, objectFactory, platforms); - PlatformsParameters platform = new PlatformsParameters(); + PlatformParameters platform = new PlatformParameters(); platform.os = "linux"; platform.architecture = "amd64"; platforms.add(platform); } - ListProperty getPlatforms() { + public ListProperty getPlatforms() { return platforms; } - public void platforms(Action action) { + public void platforms(Action action) { action.execute(platformsParametersSpec); } diff --git a/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/GradleRawConfiguration.java b/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/GradleRawConfiguration.java index ba213a4e20..6b87545ef9 100644 --- a/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/GradleRawConfiguration.java +++ b/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/GradleRawConfiguration.java @@ -217,7 +217,7 @@ public List getPluginExtensions() { } @Override - public List getPlatforms() { + public List getPlatforms() { return jibExtension.getFrom().getPlatforms().get(); } } diff --git a/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/JibExtension.java b/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/JibExtension.java index 5794d6c972..282b7adc0d 100644 --- a/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/JibExtension.java +++ b/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/JibExtension.java @@ -39,8 +39,8 @@ * credHelper = 'gcr' * platforms { * platform { - * os = 'value1' - * architecture = 'value2' + * os = 'linux' + * architecture = 'amd64' * } * } * } diff --git a/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/PlatformsParameters.java b/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/PlatformParameters.java similarity index 73% rename from jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/PlatformsParameters.java rename to jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/PlatformParameters.java index 2592ff1bdf..9fa1cf6a98 100644 --- a/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/PlatformsParameters.java +++ b/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/PlatformParameters.java @@ -16,21 +16,22 @@ package com.google.cloud.tools.jib.gradle; -import com.google.cloud.tools.jib.plugins.common.RawConfiguration.PlatformsConfiguration; +import com.google.cloud.tools.jib.plugins.common.RawConfiguration.PlatformConfiguration; +import java.util.Optional; import javax.annotation.Nullable; /** Configuration of a platform. */ -public class PlatformsParameters implements PlatformsConfiguration { +public class PlatformParameters implements PlatformConfiguration { @Nullable String os; @Nullable String architecture; @Override - public java.util.Optional getOs() { - return java.util.Optional.ofNullable(this.os); + public Optional getOs() { + return Optional.ofNullable(this.os); } @Override - public java.util.Optional getArchitecture() { - return java.util.Optional.ofNullable(this.architecture); + public Optional getArchitecture() { + return Optional.ofNullable(this.architecture); } } diff --git a/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/PlatformsParametersSpec.java b/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/PlatformParametersSpec.java similarity index 70% rename from jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/PlatformsParametersSpec.java rename to jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/PlatformParametersSpec.java index 212cb9ef66..681118a0c4 100644 --- a/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/PlatformsParametersSpec.java +++ b/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/PlatformParametersSpec.java @@ -21,15 +21,15 @@ import org.gradle.api.model.ObjectFactory; import org.gradle.api.provider.ListProperty; -/** Allows to add {@link PlatformsParameters} objects to the list property of the same type. */ -public class PlatformsParametersSpec { +/** Allows to add {@link PlatformParameters} objects to the list property of the same type. */ +public class PlatformParametersSpec { private final ObjectFactory objectFactory; - private final ListProperty platforms; + private final ListProperty platforms; @Inject - public PlatformsParametersSpec( - ObjectFactory objectFactory, ListProperty platforms) { + public PlatformParametersSpec( + ObjectFactory objectFactory, ListProperty platforms) { this.platforms = platforms; this.objectFactory = objectFactory; } @@ -39,8 +39,8 @@ public PlatformsParametersSpec( * * @param action closure representing a platform configuration */ - public void platform(Action action) { - PlatformsParameters platform = objectFactory.newInstance(PlatformsParameters.class); + public void platform(Action action) { + PlatformParameters platform = objectFactory.newInstance(PlatformParameters.class); action.execute(platform); platforms.add(platform); } 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 a48b24f383..f8f657e9ce 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 @@ -20,7 +20,7 @@ import com.google.cloud.tools.jib.plugins.common.ConfigurationPropertyValidator; import com.google.cloud.tools.jib.plugins.common.PropertyNames; import com.google.cloud.tools.jib.plugins.common.RawConfiguration.ExtensionConfiguration; -import com.google.cloud.tools.jib.plugins.common.RawConfiguration.PlatformsConfiguration; +import com.google.cloud.tools.jib.plugins.common.RawConfiguration.PlatformConfiguration; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Preconditions; import com.google.common.base.Strings; @@ -129,7 +129,7 @@ Optional getMode() { } /** Configuration for {@code platform} parameter. */ - public static class PlatformsParameters implements PlatformsConfiguration { + public static class PlatformsParameters implements PlatformConfiguration { @Nullable @Parameter private String os; @Nullable @Parameter private String architecture; 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 bbc19260d6..6b53006f4b 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,7 +219,7 @@ public List getPluginExtensions() { } @Override - public List getPlatforms() { + public List getPlatforms() { return jibPluginConfiguration.getPlatforms(); } } 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 381e4648d4..6310bd8e23 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 @@ -40,7 +40,7 @@ static interface ExtensionConfiguration { Optional getExtraConfiguration(); } - static interface PlatformsConfiguration { + static interface PlatformConfiguration { Optional getOs(); @@ -115,5 +115,5 @@ static interface PlatformsConfiguration { List getPluginExtensions(); - List getPlatforms(); + List getPlatforms(); } From f2bd668a16e62f15664cd5f1e3e6aceb2f8da0cd Mon Sep 17 00:00:00 2001 From: Louis Murerwa Date: Thu, 9 Jul 2020 19:19:18 +0000 Subject: [PATCH 15/19] Style FIxes --- .../google/cloud/tools/jib/gradle/BaseImageParameters.java | 1 + .../google/cloud/tools/jib/gradle/PlatformParameters.java | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/BaseImageParameters.java b/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/BaseImageParameters.java index 92f9584cd3..de5ba6007b 100644 --- a/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/BaseImageParameters.java +++ b/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/BaseImageParameters.java @@ -48,6 +48,7 @@ public BaseImageParameters(ObjectFactory objectFactory) { platforms.add(platform); } + @Input public ListProperty getPlatforms() { return platforms; } diff --git a/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/PlatformParameters.java b/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/PlatformParameters.java index 9fa1cf6a98..9c7c4f2a91 100644 --- a/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/PlatformParameters.java +++ b/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/PlatformParameters.java @@ -19,18 +19,23 @@ import com.google.cloud.tools.jib.plugins.common.RawConfiguration.PlatformConfiguration; import java.util.Optional; import javax.annotation.Nullable; +import org.gradle.api.tasks.Input; /** Configuration of a platform. */ public class PlatformParameters implements PlatformConfiguration { @Nullable String os; @Nullable String architecture; + @Input @Override + @Nullable public Optional getOs() { return Optional.ofNullable(this.os); } + @Input @Override + @Nullable public Optional getArchitecture() { return Optional.ofNullable(this.architecture); } From 44b6a19518a8533236904259f170719a6b3ee3e6 Mon Sep 17 00:00:00 2001 From: Louis Murerwa Date: Thu, 9 Jul 2020 19:56:26 +0000 Subject: [PATCH 16/19] SMALL FIX --- .../cloud/tools/jib/gradle/BaseImageParameters.java | 1 + .../cloud/tools/jib/gradle/PlatformParameters.java | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/BaseImageParameters.java b/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/BaseImageParameters.java index de5ba6007b..df6214643f 100644 --- a/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/BaseImageParameters.java +++ b/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/BaseImageParameters.java @@ -49,6 +49,7 @@ public BaseImageParameters(ObjectFactory objectFactory) { } @Input + @Optional public ListProperty getPlatforms() { return platforms; } diff --git a/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/PlatformParameters.java b/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/PlatformParameters.java index 9c7c4f2a91..fd86d3ce90 100644 --- a/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/PlatformParameters.java +++ b/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/PlatformParameters.java @@ -28,15 +28,21 @@ public class PlatformParameters implements PlatformConfiguration { @Input @Override - @Nullable public Optional getOs() { return Optional.ofNullable(this.os); } + public void setOs(String os) { + this.os = os; + } + @Input @Override - @Nullable public Optional getArchitecture() { return Optional.ofNullable(this.architecture); } + + public void setArchitecture(String architecture) { + this.architecture = architecture; + } } From e492da64d9b292216c9f17e6be5e5dd96f488481 Mon Sep 17 00:00:00 2001 From: Chanseok Oh Date: Thu, 9 Jul 2020 17:19:08 -0400 Subject: [PATCH 17/19] Fix Gradle platforms config --- .../tools/jib/gradle/BaseImageParameters.java | 6 ++--- .../jib/gradle/GradleRawConfiguration.java | 22 ++++++++++++++++++- .../tools/jib/gradle/PlatformParameters.java | 20 ++++++++--------- 3 files changed, 33 insertions(+), 15 deletions(-) diff --git a/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/BaseImageParameters.java b/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/BaseImageParameters.java index df6214643f..c43fb90c21 100644 --- a/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/BaseImageParameters.java +++ b/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/BaseImageParameters.java @@ -43,12 +43,12 @@ public BaseImageParameters(ObjectFactory objectFactory) { objectFactory.newInstance(PlatformParametersSpec.class, objectFactory, platforms); PlatformParameters platform = new PlatformParameters(); - platform.os = "linux"; - platform.architecture = "amd64"; + platform.setOs("linux"); + platform.setArchitecture("amd64"); platforms.add(platform); } - @Input + @Nested @Optional public ListProperty getPlatforms() { return platforms; diff --git a/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/GradleRawConfiguration.java b/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/GradleRawConfiguration.java index 6b87545ef9..5cc32f7e8f 100644 --- a/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/GradleRawConfiguration.java +++ b/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/GradleRawConfiguration.java @@ -28,10 +28,29 @@ import java.util.Map; import java.util.Optional; import java.util.Set; +import java.util.stream.Collectors; /** Gradle-specific adapter for providing raw configuration parameter values. */ public class GradleRawConfiguration implements RawConfiguration { + private static class GradlePlatformConfiguration implements PlatformConfiguration { + private final PlatformParameters platform; + + private GradlePlatformConfiguration(PlatformParameters platform) { + this.platform = platform; + } + + @Override + public Optional getOs() { + return Optional.ofNullable(platform.getOs()); + } + + @Override + public Optional getArchitecture() { + return Optional.ofNullable(platform.getArchitecture()); + } + } + private final JibExtension jibExtension; public GradleRawConfiguration(JibExtension jibExtension) { @@ -218,6 +237,7 @@ public List getPluginExtensions() { @Override public List getPlatforms() { - return jibExtension.getFrom().getPlatforms().get(); + List platforms = jibExtension.getFrom().getPlatforms().get(); + return platforms.stream().map(GradlePlatformConfiguration::new).collect(Collectors.toList()); } } diff --git a/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/PlatformParameters.java b/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/PlatformParameters.java index fd86d3ce90..135fce2823 100644 --- a/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/PlatformParameters.java +++ b/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/PlatformParameters.java @@ -16,20 +16,18 @@ package com.google.cloud.tools.jib.gradle; -import com.google.cloud.tools.jib.plugins.common.RawConfiguration.PlatformConfiguration; -import java.util.Optional; import javax.annotation.Nullable; import org.gradle.api.tasks.Input; /** Configuration of a platform. */ -public class PlatformParameters implements PlatformConfiguration { - @Nullable String os; - @Nullable String architecture; +public class PlatformParameters { + @Nullable private String os; + @Nullable private String architecture; @Input - @Override - public Optional getOs() { - return Optional.ofNullable(this.os); + @Nullable + public String getOs() { + return os; } public void setOs(String os) { @@ -37,9 +35,9 @@ public void setOs(String os) { } @Input - @Override - public Optional getArchitecture() { - return Optional.ofNullable(this.architecture); + @Nullable + public String getArchitecture() { + return architecture; } public void setArchitecture(String architecture) { From 9287c28b170d8b3a8e2ab5d3d1bd06f6fd9dc5ac Mon Sep 17 00:00:00 2001 From: Chanseok Oh Date: Thu, 9 Jul 2020 17:40:05 -0400 Subject: [PATCH 18/19] Rename PlatformConfiguration interface --- .../jib/gradle/GradleRawConfiguration.java | 22 +------------------ .../tools/jib/gradle/PlatformParameters.java | 17 +++++++++++++- .../jib/maven/JibPluginConfiguration.java | 8 +++---- .../jib/maven/JibPluginConfigurationTest.java | 4 ++-- .../jib/plugins/common/RawConfiguration.java | 4 ++-- 5 files changed, 25 insertions(+), 30 deletions(-) diff --git a/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/GradleRawConfiguration.java b/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/GradleRawConfiguration.java index 5cc32f7e8f..6b87545ef9 100644 --- a/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/GradleRawConfiguration.java +++ b/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/GradleRawConfiguration.java @@ -28,29 +28,10 @@ import java.util.Map; import java.util.Optional; import java.util.Set; -import java.util.stream.Collectors; /** Gradle-specific adapter for providing raw configuration parameter values. */ public class GradleRawConfiguration implements RawConfiguration { - private static class GradlePlatformConfiguration implements PlatformConfiguration { - private final PlatformParameters platform; - - private GradlePlatformConfiguration(PlatformParameters platform) { - this.platform = platform; - } - - @Override - public Optional getOs() { - return Optional.ofNullable(platform.getOs()); - } - - @Override - public Optional getArchitecture() { - return Optional.ofNullable(platform.getArchitecture()); - } - } - private final JibExtension jibExtension; public GradleRawConfiguration(JibExtension jibExtension) { @@ -237,7 +218,6 @@ public List getPluginExtensions() { @Override public List getPlatforms() { - List platforms = jibExtension.getFrom().getPlatforms().get(); - return platforms.stream().map(GradlePlatformConfiguration::new).collect(Collectors.toList()); + return jibExtension.getFrom().getPlatforms().get(); } } diff --git a/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/PlatformParameters.java b/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/PlatformParameters.java index 135fce2823..204d0c20ad 100644 --- a/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/PlatformParameters.java +++ b/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/PlatformParameters.java @@ -16,11 +16,14 @@ package com.google.cloud.tools.jib.gradle; +import com.google.cloud.tools.jib.plugins.common.RawConfiguration.PlatformConfiguration; +import java.util.Optional; import javax.annotation.Nullable; import org.gradle.api.tasks.Input; +import org.gradle.api.tasks.Internal; /** Configuration of a platform. */ -public class PlatformParameters { +public class PlatformParameters implements PlatformConfiguration { @Nullable private String os; @Nullable private String architecture; @@ -30,6 +33,12 @@ public String getOs() { return os; } + @Internal + @Override + public Optional getOsName() { + return Optional.ofNullable(os); + } + public void setOs(String os) { this.os = os; } @@ -40,6 +49,12 @@ public String getArchitecture() { return architecture; } + @Internal + @Override + public Optional getArchitectureName() { + return Optional.ofNullable(architecture); + } + public void setArchitecture(String architecture) { this.architecture = architecture; } 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 f8f657e9ce..1c2d7ac444 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 @@ -134,13 +134,13 @@ public static class PlatformsParameters implements PlatformConfiguration { @Nullable @Parameter private String architecture; @Override - public Optional getOs() { - return Optional.ofNullable(this.os); + public Optional getOsName() { + return Optional.ofNullable(os); } @Override - public Optional getArchitecture() { - return Optional.ofNullable(this.architecture); + public Optional getArchitectureName() { + return Optional.ofNullable(architecture); } } diff --git a/jib-maven-plugin/src/test/java/com/google/cloud/tools/jib/maven/JibPluginConfigurationTest.java b/jib-maven-plugin/src/test/java/com/google/cloud/tools/jib/maven/JibPluginConfigurationTest.java index a658a3f331..4ac8dad7e6 100644 --- a/jib-maven-plugin/src/test/java/com/google/cloud/tools/jib/maven/JibPluginConfigurationTest.java +++ b/jib-maven-plugin/src/test/java/com/google/cloud/tools/jib/maven/JibPluginConfigurationTest.java @@ -69,9 +69,9 @@ public Log getLog() { @Test public void testDefaults() { - Assert.assertEquals("linux", testPluginConfiguration.getPlatforms().get(0).getOs().get()); + Assert.assertEquals("linux", testPluginConfiguration.getPlatforms().get(0).getOsName().get()); Assert.assertEquals( - "amd64", testPluginConfiguration.getPlatforms().get(0).getArchitecture().get()); + "amd64", testPluginConfiguration.getPlatforms().get(0).getArchitectureName().get()); Assert.assertEquals("", testPluginConfiguration.getAppRoot()); Assert.assertNull(testPluginConfiguration.getWorkingDirectory()); Assert.assertTrue(testPluginConfiguration.getExtraClasspath().isEmpty()); 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 6310bd8e23..d980f0849f 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 @@ -42,9 +42,9 @@ static interface ExtensionConfiguration { static interface PlatformConfiguration { - Optional getOs(); + Optional getOsName(); - Optional getArchitecture(); + Optional getArchitectureName(); } Optional getFromImage(); From e98f9bb5109f3a568885a0abba51e6ed91e1a675 Mon Sep 17 00:00:00 2001 From: Louis Murerwa Date: Fri, 10 Jul 2020 14:53:23 +0000 Subject: [PATCH 19/19] Small style changes --- .../cloud/tools/jib/gradle/BaseImageParameters.java | 8 ++++---- .../cloud/tools/jib/maven/JibPluginConfiguration.java | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/BaseImageParameters.java b/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/BaseImageParameters.java index c43fb90c21..3b182b06f6 100644 --- a/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/BaseImageParameters.java +++ b/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/BaseImageParameters.java @@ -30,16 +30,16 @@ public class BaseImageParameters { private final AuthParameters auth; - @Nullable private String credHelper; @Nullable private String image; - private final PlatformParametersSpec platformsParametersSpec; + @Nullable private String credHelper; + private final PlatformParametersSpec platformParametersSpec; private final ListProperty platforms; @Inject public BaseImageParameters(ObjectFactory objectFactory) { auth = objectFactory.newInstance(AuthParameters.class, "from.auth"); platforms = objectFactory.listProperty(PlatformParameters.class).empty(); - platformsParametersSpec = + platformParametersSpec = objectFactory.newInstance(PlatformParametersSpec.class, objectFactory, platforms); PlatformParameters platform = new PlatformParameters(); @@ -55,7 +55,7 @@ public ListProperty getPlatforms() { } public void platforms(Action action) { - action.execute(platformsParametersSpec); + action.execute(platformParametersSpec); } @Input 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 1c2d7ac444..53653d7804 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 @@ -129,7 +129,7 @@ Optional getMode() { } /** Configuration for {@code platform} parameter. */ - public static class PlatformsParameters implements PlatformConfiguration { + public static class PlatformParameters implements PlatformConfiguration { @Nullable @Parameter private String os; @Nullable @Parameter private String architecture; @@ -153,11 +153,11 @@ public static class FromConfiguration { @Parameter private FromAuthConfiguration auth = new FromAuthConfiguration(); - @Parameter private List platforms; + @Parameter private List platforms; /** Constructor for defaults. */ public FromConfiguration() { - PlatformsParameters platform = new PlatformsParameters(); + PlatformParameters platform = new PlatformParameters(); platform.os = "linux"; platform.architecture = "amd64"; platforms = Collections.singletonList(platform); @@ -362,7 +362,7 @@ protected void checkJibVersion() throws MojoExecutionException { * * @return the specified platforms */ - List getPlatforms() { + List getPlatforms() { return from.platforms; }