From f9df0ba3d13782064cd51b3925885798f843f538 Mon Sep 17 00:00:00 2001 From: Kevin Stillhammer Date: Thu, 1 Jun 2023 08:49:41 +0200 Subject: [PATCH] add integration test for platform tags --- .../jib/api/ContainerizerIntegrationTest.java | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) 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 8715ffb784a..34e2274b5ab 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 @@ -19,6 +19,7 @@ import com.google.cloud.tools.jib.Command; import com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath; import com.google.cloud.tools.jib.api.buildplan.FileEntriesLayer; +import com.google.cloud.tools.jib.api.buildplan.Platform; 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; @@ -26,6 +27,7 @@ import com.google.common.base.Splitter; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; import com.google.common.io.Resources; import java.io.IOException; import java.net.URISyntaxException; @@ -35,6 +37,8 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; +import java.util.Objects; +import java.util.Set; import java.util.concurrent.ExecutionException; import java.util.stream.Stream; import org.hamcrest.CoreMatchers; @@ -83,6 +87,8 @@ private void checkCompletion() { private static final Logger logger = LoggerFactory.getLogger(ContainerizerIntegrationTest.class); private static final String DISTROLESS_DIGEST = "sha256:f488c213f278bc5f9ffe3ddf30c5dbb2303a15a74146b738d12453088e662880"; + private static final String MULTI_PLATFORM_DIGEST = + "sha256:c737fc29fc2556d3377d6a719a9842a500777fce35a7f1299acd569c73f65247"; private static final double DOUBLE_ERROR_MARGIN = 1e-10; public static ImmutableList fakeLayerConfigurations; @@ -228,6 +234,30 @@ public void testSteps_forBuildToDockerRegistry_multipleTags() new Command("docker", "run", "--rm", imageReference3).run()); } + @Test + public void testSteps_forBuildToDockerRegistry_multiplePlatforms() + throws IOException, InterruptedException, ExecutionException, RegistryException, + CacheDirectoryCreationException, InvalidImageReferenceException { + buildImage( + ImageReference.of("gcr.io", "distroless/java17-debian11", MULTI_PLATFORM_DIGEST), + Containerizer.to(RegistryImage.named(dockerHost + ":5000/testimage:testtag")), + Collections.singletonList("testtag"), + ImmutableSet.of(new Platform("amd64", "linux"), new Platform("arm64", "linux"))); + + String imageReference = dockerHost + ":5000/testimage:testtag-amd64"; + localRegistry.pull(imageReference); + assertDockerInspect(imageReference); + Assert.assertEquals( + "Hello, world. An argument.\n", new Command("docker", "run", "--rm", imageReference).run()); + + String imageReference2 = dockerHost + ":5000/testimage:testtag-arm64"; + localRegistry.pull(imageReference2); + assertDockerInspect(imageReference2); + Assert.assertEquals( + "Hello, world. An argument.\n", + new Command("docker", "run", "--rm", imageReference2).run()); + } + @Test public void testSteps_forBuildToDockerRegistry_skipExistingDigest() throws IOException, InterruptedException, ExecutionException, RegistryException, @@ -336,6 +366,16 @@ private JibContainer buildImage( ImageReference baseImage, Containerizer containerizer, List additionalTags) throws IOException, InterruptedException, RegistryException, CacheDirectoryCreationException, ExecutionException { + return buildImage(baseImage, containerizer, additionalTags, null); + } + + private JibContainer buildImage( + ImageReference baseImage, + Containerizer containerizer, + List additionalTags, + Set additionalPlatforms) + throws IOException, InterruptedException, RegistryException, CacheDirectoryCreationException, + ExecutionException { JibContainerBuilder containerBuilder = Jib.from(baseImage) .setEntrypoint( @@ -346,6 +386,9 @@ private JibContainer buildImage( .setExposedPorts(Ports.parse(Arrays.asList("1000", "2000-2002/tcp", "3000/udp"))) .setLabels(ImmutableMap.of("key1", "value1", "key2", "value2")) .setFileEntriesLayers(fakeLayerConfigurations); + if (Objects.nonNull(additionalPlatforms)) { + containerBuilder.setPlatforms(additionalPlatforms); + } containerizer .setAllowInsecureRegistries(true)