Skip to content

Commit

Permalink
add integration test for platform tags
Browse files Browse the repository at this point in the history
  • Loading branch information
eifinger committed May 31, 2024
1 parent 4591622 commit 475b7e3
Showing 1 changed file with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@
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;
import com.google.cloud.tools.jib.registry.LocalRegistry;
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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<FileEntriesLayer> fakeLayerConfigurations;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -336,6 +366,16 @@ private JibContainer buildImage(
ImageReference baseImage, Containerizer containerizer, List<String> additionalTags)
throws IOException, InterruptedException, RegistryException, CacheDirectoryCreationException,
ExecutionException {
return buildImage(baseImage, containerizer, additionalTags, null);
}

private JibContainer buildImage(
ImageReference baseImage,
Containerizer containerizer,
List<String> additionalTags,
Set<Platform> additionalPlatforms)
throws IOException, InterruptedException, RegistryException, CacheDirectoryCreationException,
ExecutionException {
JibContainerBuilder containerBuilder =
Jib.from(baseImage)
.setEntrypoint(
Expand All @@ -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)
Expand Down

0 comments on commit 475b7e3

Please sign in to comment.