use of com.google.cloud.tools.jib.api.buildplan.Platform in project jib by GoogleContainerTools.
the class JibIntegrationTest method testScratch_multiPlatform.
@Test
public void testScratch_multiPlatform() throws IOException, InterruptedException, ExecutionException, RegistryException, CacheDirectoryCreationException, InvalidImageReferenceException {
Jib.fromScratch().setPlatforms(ImmutableSet.of(new Platform("arm64", "windows"), new Platform("amd32", "windows"))).containerize(Containerizer.to(RegistryImage.named("localhost:5000/jib-scratch:multi-platform")).setAllowInsecureRegistries(true));
V22ManifestListTemplate manifestList = (V22ManifestListTemplate) registryClient.pullManifest("multi-platform").getManifest();
Assert.assertEquals(2, manifestList.getManifests().size());
ManifestDescriptorTemplate.Platform platform1 = manifestList.getManifests().get(0).getPlatform();
ManifestDescriptorTemplate.Platform platform2 = manifestList.getManifests().get(1).getPlatform();
Assert.assertEquals("arm64", platform1.getArchitecture());
Assert.assertEquals("windows", platform1.getOs());
Assert.assertEquals("amd32", platform2.getArchitecture());
Assert.assertEquals("windows", platform2.getOs());
}
use of com.google.cloud.tools.jib.api.buildplan.Platform in project jib by GoogleContainerTools.
the class JibIntegrationTest method testScratch_singlePlatform.
@Test
public void testScratch_singlePlatform() throws IOException, InterruptedException, ExecutionException, RegistryException, CacheDirectoryCreationException, InvalidImageReferenceException {
Jib.fromScratch().setPlatforms(ImmutableSet.of(new Platform("arm64", "windows"))).containerize(Containerizer.to(RegistryImage.named("localhost:5000/jib-scratch:single-platform")).setAllowInsecureRegistries(true));
V22ManifestTemplate manifestTemplate = registryClient.pullManifest("single-platform", V22ManifestTemplate.class).getManifest();
String containerConfig = Blobs.writeToString(registryClient.pullBlob(manifestTemplate.getContainerConfiguration().getDigest(), ignored -> {
}, ignored -> {
}));
Assert.assertTrue(manifestTemplate.getLayers().isEmpty());
Assert.assertTrue(containerConfig.contains("\"architecture\":\"arm64\""));
Assert.assertTrue(containerConfig.contains("\"os\":\"windows\""));
}
use of com.google.cloud.tools.jib.api.buildplan.Platform in project jib by GoogleContainerTools.
the class BuildFilesTest method testToJibContainerBuilder_allProperties.
@Test
public void testToJibContainerBuilder_allProperties() throws URISyntaxException, IOException, InvalidImageReferenceException {
Path buildfile = Paths.get(Resources.getResource("buildfiles/projects/allProperties/jib.yaml").toURI());
Path projectRoot = buildfile.getParent();
JibContainerBuilder jibContainerBuilder = BuildFiles.toJibContainerBuilder(projectRoot, buildfile, buildCli, commonCliOptions, consoleLogger);
ContainerBuildPlan resolved = jibContainerBuilder.toContainerBuildPlan();
Assert.assertEquals("ubuntu", resolved.getBaseImage());
Assert.assertEquals(Instant.ofEpochMilli(2000), resolved.getCreationTime());
Assert.assertEquals(ImageFormat.OCI, resolved.getFormat());
Assert.assertEquals(ImmutableSet.of(new Platform("arm", "linux"), new Platform("amd64", "darwin")), resolved.getPlatforms());
Assert.assertEquals(ImmutableMap.of("KEY1", "v1", "KEY2", "v2"), resolved.getEnvironment());
Assert.assertEquals(ImmutableSet.of(AbsoluteUnixPath.get("/volume1"), AbsoluteUnixPath.get("/volume2")), resolved.getVolumes());
Assert.assertEquals(ImmutableMap.of("label1", "l1", "label2", "l2"), resolved.getLabels());
Assert.assertEquals(ImmutableSet.of(Port.udp(123), Port.tcp(456), Port.tcp(789)), resolved.getExposedPorts());
Assert.assertEquals("customUser", resolved.getUser());
Assert.assertEquals(AbsoluteUnixPath.get("/home"), resolved.getWorkingDirectory());
Assert.assertEquals(ImmutableList.of("sh", "script.sh"), resolved.getEntrypoint());
Assert.assertEquals(ImmutableList.of("--param", "param"), resolved.getCmd());
Assert.assertEquals(1, resolved.getLayers().size());
FileEntriesLayer resolvedLayer = (FileEntriesLayer) resolved.getLayers().get(0);
Assert.assertEquals("scripts", resolvedLayer.getName());
Assert.assertEquals(FileEntriesLayer.builder().addEntry(projectRoot.resolve("project/script.sh"), AbsoluteUnixPath.get("/home/script.sh")).build().getEntries(), resolvedLayer.getEntries());
Assert.assertEquals(LayerObject.Type.FILE_ENTRIES, resolvedLayer.getType());
}
use of com.google.cloud.tools.jib.api.buildplan.Platform in project jib by GoogleContainerTools.
the class ContainerBuildersTest method testCreate_platforms.
@Test
public void testCreate_platforms() throws IOException, InvalidImageReferenceException {
JibContainerBuilder containerBuilder = ContainerBuilders.create("registry://registry-image-ref", ImmutableSet.of(new Platform("arch1", "os1"), new Platform("arch2", "os2")), mockCommonCliOptions, mockLogger);
assertThat(containerBuilder.toContainerBuildPlan().getPlatforms()).isEqualTo(ImmutableSet.of(new Platform("arch1", "os1"), new Platform("arch2", "os2")));
}
use of com.google.cloud.tools.jib.api.buildplan.Platform in project jib by GoogleContainerTools.
the class PlatformCheckerTest method testCheckManifestPlatform_mismatch.
@Test
public void testCheckManifestPlatform_mismatch() {
Mockito.when(containerConfig.getPlatforms()).thenReturn(ImmutableSet.of(new Platform("configured arch", "configured OS")));
ContainerConfigurationTemplate containerConfigJson = new ContainerConfigurationTemplate();
containerConfigJson.setArchitecture("actual arch");
containerConfigJson.setOs("actual OS");
PlatformChecker.checkManifestPlatform(buildContext, containerConfigJson);
Mockito.verify(eventHandlers).dispatch(LogEvent.warn("the configured platform (configured arch/configured OS) doesn't match the " + "platform (actual arch/actual OS) of the base image (scratch)"));
}
Aggregations