Search in sources :

Example 51 with Platform

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());
}
Also used : V22ManifestListTemplate(com.google.cloud.tools.jib.image.json.V22ManifestListTemplate) Platform(com.google.cloud.tools.jib.api.buildplan.Platform) ManifestDescriptorTemplate(com.google.cloud.tools.jib.image.json.V22ManifestListTemplate.ManifestDescriptorTemplate) ManifestPullerIntegrationTest(com.google.cloud.tools.jib.registry.ManifestPullerIntegrationTest) Test(org.junit.Test)

Example 52 with Platform

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\""));
}
Also used : BeforeClass(org.junit.BeforeClass) URISyntaxException(java.net.URISyntaxException) Command(com.google.cloud.tools.jib.Command) ManifestPullerIntegrationTest(com.google.cloud.tools.jib.registry.ManifestPullerIntegrationTest) V22ManifestListTemplate(com.google.cloud.tools.jib.image.json.V22ManifestListTemplate) V22ManifestTemplate(com.google.cloud.tools.jib.image.json.V22ManifestTemplate) LocalRegistry(com.google.cloud.tools.jib.registry.LocalRegistry) After(org.junit.After) ManifestDescriptorTemplate(com.google.cloud.tools.jib.image.json.V22ManifestListTemplate.ManifestDescriptorTemplate) ClassRule(org.junit.ClassRule) Path(java.nio.file.Path) ExecutorService(java.util.concurrent.ExecutorService) Before(org.junit.Before) ImmutableSet(com.google.common.collect.ImmutableSet) Resources(com.google.common.io.Resources) FailoverHttpClient(com.google.cloud.tools.jib.http.FailoverHttpClient) IOException(java.io.IOException) Test(org.junit.Test) Executors(java.util.concurrent.Executors) RegistryClient(com.google.cloud.tools.jib.registry.RegistryClient) ExecutionException(java.util.concurrent.ExecutionException) Rule(org.junit.Rule) Paths(java.nio.file.Paths) EventHandlers(com.google.cloud.tools.jib.event.EventHandlers) Blobs(com.google.cloud.tools.jib.blob.Blobs) Platform(com.google.cloud.tools.jib.api.buildplan.Platform) Assert(org.junit.Assert) Collections(java.util.Collections) TemporaryFolder(org.junit.rules.TemporaryFolder) V22ManifestTemplate(com.google.cloud.tools.jib.image.json.V22ManifestTemplate) Platform(com.google.cloud.tools.jib.api.buildplan.Platform) ManifestPullerIntegrationTest(com.google.cloud.tools.jib.registry.ManifestPullerIntegrationTest) Test(org.junit.Test)

Example 53 with Platform

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());
}
Also used : Path(java.nio.file.Path) AbsoluteUnixPath(com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath) Platform(com.google.cloud.tools.jib.api.buildplan.Platform) FileEntriesLayer(com.google.cloud.tools.jib.api.buildplan.FileEntriesLayer) JibContainerBuilder(com.google.cloud.tools.jib.api.JibContainerBuilder) ContainerBuildPlan(com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan) Test(org.junit.Test)

Example 54 with Platform

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")));
}
Also used : Platform(com.google.cloud.tools.jib.api.buildplan.Platform) JibContainerBuilder(com.google.cloud.tools.jib.api.JibContainerBuilder) Test(org.junit.Test)

Example 55 with Platform

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)"));
}
Also used : ContainerConfigurationTemplate(com.google.cloud.tools.jib.image.json.ContainerConfigurationTemplate) Platform(com.google.cloud.tools.jib.api.buildplan.Platform) Test(org.junit.Test)

Aggregations

Platform (com.google.cloud.tools.jib.api.buildplan.Platform)65 Test (org.junit.Test)50 ContainerBuildPlan (com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan)18 ContainerConfigurationTemplate (com.google.cloud.tools.jib.image.json.ContainerConfigurationTemplate)18 V22ManifestListTemplate (com.google.cloud.tools.jib.image.json.V22ManifestListTemplate)18 JibContainerBuilder (com.google.cloud.tools.jib.api.JibContainerBuilder)16 FileEntriesLayer (com.google.cloud.tools.jib.api.buildplan.FileEntriesLayer)14 ImageConfiguration (com.google.cloud.tools.jib.configuration.ImageConfiguration)14 ImageReference (com.google.cloud.tools.jib.api.ImageReference)12 EventHandlers (com.google.cloud.tools.jib.event.EventHandlers)12 Path (java.nio.file.Path)12 ImageMetadataTemplate (com.google.cloud.tools.jib.image.json.ImageMetadataTemplate)10 ManifestAndConfigTemplate (com.google.cloud.tools.jib.image.json.ManifestAndConfigTemplate)10 V22ManifestTemplate (com.google.cloud.tools.jib.image.json.V22ManifestTemplate)10 Image (com.google.cloud.tools.jib.image.Image)9 BuildContext (com.google.cloud.tools.jib.configuration.BuildContext)8 ManifestDescriptorTemplate (com.google.cloud.tools.jib.image.json.V22ManifestListTemplate.ManifestDescriptorTemplate)8 RegistryClient (com.google.cloud.tools.jib.registry.RegistryClient)7 IOException (java.io.IOException)7 Blobs (com.google.cloud.tools.jib.blob.Blobs)6