Search in sources :

Example 46 with Platform

use of com.google.cloud.tools.jib.api.buildplan.Platform in project jib by google.

the class JibContainerBuilderTest method testToBuildContext_containerConfigurationSet.

@Test
public void testToBuildContext_containerConfigurationSet() throws InvalidImageReferenceException, CacheDirectoryCreationException {
    ImageConfiguration imageConfiguration = ImageConfiguration.builder(ImageReference.parse("base/image")).build();
    JibContainerBuilder jibContainerBuilder = new JibContainerBuilder(imageConfiguration, spyBuildContextBuilder).setPlatforms(ImmutableSet.of(new Platform("testArchitecture", "testOS"))).setEntrypoint(Arrays.asList("entry", "point")).setEnvironment(ImmutableMap.of("name", "value")).setExposedPorts(ImmutableSet.of(Port.tcp(1234), Port.udp(5678))).setLabels(ImmutableMap.of("key", "value")).setProgramArguments(Arrays.asList("program", "arguments")).setCreationTime(Instant.ofEpochMilli(1000)).setUser("user").setWorkingDirectory(AbsoluteUnixPath.get("/working/directory"));
    BuildContext buildContext = jibContainerBuilder.toBuildContext(Containerizer.to(RegistryImage.named("target/image")));
    ContainerConfiguration containerConfiguration = buildContext.getContainerConfiguration();
    Assert.assertEquals(ImmutableSet.of(new Platform("testArchitecture", "testOS")), containerConfiguration.getPlatforms());
    Assert.assertEquals(Arrays.asList("entry", "point"), containerConfiguration.getEntrypoint());
    Assert.assertEquals(ImmutableMap.of("name", "value"), containerConfiguration.getEnvironmentMap());
    Assert.assertEquals(ImmutableSet.of(Port.tcp(1234), Port.udp(5678)), containerConfiguration.getExposedPorts());
    Assert.assertEquals(ImmutableMap.of("key", "value"), containerConfiguration.getLabels());
    Assert.assertEquals(Arrays.asList("program", "arguments"), containerConfiguration.getProgramArguments());
    Assert.assertEquals(Instant.ofEpochMilli(1000), containerConfiguration.getCreationTime());
    Assert.assertEquals("user", containerConfiguration.getUser());
    Assert.assertEquals(AbsoluteUnixPath.get("/working/directory"), containerConfiguration.getWorkingDirectory());
}
Also used : Platform(com.google.cloud.tools.jib.api.buildplan.Platform) BuildContext(com.google.cloud.tools.jib.configuration.BuildContext) ImageConfiguration(com.google.cloud.tools.jib.configuration.ImageConfiguration) ContainerConfiguration(com.google.cloud.tools.jib.configuration.ContainerConfiguration) Test(org.junit.Test)

Example 47 with Platform

use of com.google.cloud.tools.jib.api.buildplan.Platform in project jib by google.

the class JibContainerBuilderTest method setApplyContainerBuildPlan.

@Test
public void setApplyContainerBuildPlan() throws InvalidImageReferenceException, CacheDirectoryCreationException {
    FileEntriesLayer layer = FileEntriesLayer.builder().addEntry(Paths.get("/src/file/foo"), AbsoluteUnixPath.get("/path/in/container")).build();
    ContainerBuildPlan buildPlan = ContainerBuildPlan.builder().setBaseImage("some/base").setPlatforms(ImmutableSet.of(new Platform("testArchitecture", "testOS"))).setFormat(ImageFormat.OCI).setCreationTime(Instant.ofEpochMilli(30)).setEnvironment(ImmutableMap.of("env", "var")).setVolumes(ImmutableSet.of(AbsoluteUnixPath.get("/mnt/foo"), AbsoluteUnixPath.get("/bar"))).setLabels(ImmutableMap.of("com.example.label", "cool")).setExposedPorts(ImmutableSet.of(Port.tcp(443))).setLayers(Arrays.asList(layer)).setUser(":").setWorkingDirectory(AbsoluteUnixPath.get("/workspace")).setEntrypoint(Arrays.asList("foo", "entrypoint")).setCmd(Arrays.asList("bar", "cmd")).build();
    ImageConfiguration imageConfiguration = ImageConfiguration.builder(ImageReference.parse("initial/base")).build();
    JibContainerBuilder containerBuilder = new JibContainerBuilder(imageConfiguration, spyBuildContextBuilder).applyContainerBuildPlan(buildPlan);
    BuildContext buildContext = containerBuilder.toBuildContext(Containerizer.to(RegistryImage.named("target/image")));
    Assert.assertEquals("some/base", buildContext.getBaseImageConfiguration().getImage().toString());
    Assert.assertEquals(OciManifestTemplate.class, buildContext.getTargetFormat());
    Assert.assertEquals(1, buildContext.getLayerConfigurations().size());
    Assert.assertEquals(1, buildContext.getLayerConfigurations().get(0).getEntries().size());
    Assert.assertEquals(Arrays.asList(new FileEntry(Paths.get("/src/file/foo"), AbsoluteUnixPath.get("/path/in/container"), FilePermissions.fromOctalString("644"), Instant.ofEpochSecond(1))), buildContext.getLayerConfigurations().get(0).getEntries());
    ContainerConfiguration containerConfiguration = buildContext.getContainerConfiguration();
    Assert.assertEquals(Instant.ofEpochMilli(30), containerConfiguration.getCreationTime());
    Assert.assertEquals(ImmutableMap.of("env", "var"), containerConfiguration.getEnvironmentMap());
    Assert.assertEquals(ImmutableMap.of("com.example.label", "cool"), containerConfiguration.getLabels());
    Assert.assertEquals(ImmutableSet.of(AbsoluteUnixPath.get("/mnt/foo"), AbsoluteUnixPath.get("/bar")), containerConfiguration.getVolumes());
    Assert.assertEquals(ImmutableSet.of(Port.tcp(443)), containerConfiguration.getExposedPorts());
    Assert.assertEquals(":", containerConfiguration.getUser());
    Assert.assertEquals(AbsoluteUnixPath.get("/workspace"), containerConfiguration.getWorkingDirectory());
    Assert.assertEquals(Arrays.asList("foo", "entrypoint"), containerConfiguration.getEntrypoint());
    Assert.assertEquals(Arrays.asList("bar", "cmd"), containerConfiguration.getProgramArguments());
    ContainerBuildPlan convertedPlan = containerBuilder.toContainerBuildPlan();
    Assert.assertEquals(ImmutableSet.of(new Platform("testArchitecture", "testOS")), convertedPlan.getPlatforms());
}
Also used : Platform(com.google.cloud.tools.jib.api.buildplan.Platform) BuildContext(com.google.cloud.tools.jib.configuration.BuildContext) ImageConfiguration(com.google.cloud.tools.jib.configuration.ImageConfiguration) FileEntriesLayer(com.google.cloud.tools.jib.api.buildplan.FileEntriesLayer) FileEntry(com.google.cloud.tools.jib.api.buildplan.FileEntry) ContainerConfiguration(com.google.cloud.tools.jib.configuration.ContainerConfiguration) ContainerBuildPlan(com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan) Test(org.junit.Test)

Example 48 with Platform

use of com.google.cloud.tools.jib.api.buildplan.Platform in project jib by google.

the class JibContainerBuilderTest method testToContainerBuildPlan_default.

@Test
public void testToContainerBuildPlan_default() throws InvalidImageReferenceException {
    ImageConfiguration imageConfiguration = ImageConfiguration.builder(ImageReference.parse("base/image")).build();
    JibContainerBuilder containerBuilder = new JibContainerBuilder(imageConfiguration, spyBuildContextBuilder);
    ContainerBuildPlan buildPlan = containerBuilder.toContainerBuildPlan();
    Assert.assertEquals("base/image", buildPlan.getBaseImage());
    Assert.assertEquals(ImmutableSet.of(new Platform("amd64", "linux")), buildPlan.getPlatforms());
    Assert.assertEquals(Instant.EPOCH, buildPlan.getCreationTime());
    Assert.assertEquals(ImageFormat.Docker, buildPlan.getFormat());
    Assert.assertEquals(Collections.emptyMap(), buildPlan.getEnvironment());
    Assert.assertEquals(Collections.emptyMap(), buildPlan.getLabels());
    Assert.assertEquals(Collections.emptySet(), buildPlan.getVolumes());
    Assert.assertEquals(Collections.emptySet(), buildPlan.getExposedPorts());
    Assert.assertNull(buildPlan.getUser());
    Assert.assertNull(buildPlan.getWorkingDirectory());
    Assert.assertNull(buildPlan.getEntrypoint());
    Assert.assertNull(buildPlan.getCmd());
    Assert.assertEquals(Collections.emptyList(), buildPlan.getLayers());
}
Also used : Platform(com.google.cloud.tools.jib.api.buildplan.Platform) ImageConfiguration(com.google.cloud.tools.jib.configuration.ImageConfiguration) ContainerBuildPlan(com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan) Test(org.junit.Test)

Example 49 with Platform

use of com.google.cloud.tools.jib.api.buildplan.Platform in project jib by GoogleContainerTools.

the class JarFilesTest method testToJibContainerBuilder_packagedSpringBoot_basicInfo.

@Test
public void testToJibContainerBuilder_packagedSpringBoot_basicInfo() throws IOException, InvalidImageReferenceException {
    when(mockSpringBootPackagedProcessor.getJavaVersion()).thenReturn(8);
    FileEntriesLayer layer = FileEntriesLayer.builder().setName("jar").addEntry(Paths.get("path/to/spring-boot.jar"), AbsoluteUnixPath.get("/app/spring-boot.jar")).build();
    when(mockSpringBootPackagedProcessor.createLayers()).thenReturn(Arrays.asList(layer));
    when(mockSpringBootPackagedProcessor.computeEntrypoint(anyList())).thenReturn(ImmutableList.of("java", "-jar", "/app/spring-boot.jar"));
    when(mockCommonContainerConfigCliOptions.getFrom()).thenReturn(Optional.empty());
    JibContainerBuilder containerBuilder = JarFiles.toJibContainerBuilder(mockSpringBootPackagedProcessor, mockJarCommand, mockCommonCliOptions, mockCommonContainerConfigCliOptions, mockLogger);
    ContainerBuildPlan buildPlan = containerBuilder.toContainerBuildPlan();
    assertThat(buildPlan.getBaseImage()).isEqualTo("eclipse-temurin:8-jre");
    assertThat(buildPlan.getPlatforms()).isEqualTo(ImmutableSet.of(new Platform("amd64", "linux")));
    assertThat(buildPlan.getCreationTime()).isEqualTo(Instant.EPOCH);
    assertThat(buildPlan.getFormat()).isEqualTo(ImageFormat.Docker);
    assertThat(buildPlan.getEnvironment()).isEmpty();
    assertThat(buildPlan.getLabels()).isEmpty();
    assertThat(buildPlan.getVolumes()).isEmpty();
    assertThat(buildPlan.getExposedPorts()).isEmpty();
    assertThat(buildPlan.getUser()).isNull();
    assertThat(buildPlan.getWorkingDirectory()).isNull();
    assertThat(buildPlan.getEntrypoint()).containsExactly("java", "-jar", "/app/spring-boot.jar").inOrder();
    assertThat(buildPlan.getLayers()).hasSize(1);
    assertThat(buildPlan.getLayers().get(0).getName()).isEqualTo("jar");
    assertThat(((FileEntriesLayer) buildPlan.getLayers().get(0)).getEntries()).isEqualTo(FileEntriesLayer.builder().addEntry(Paths.get("path/to/spring-boot.jar"), AbsoluteUnixPath.get("/app/spring-boot.jar")).build().getEntries());
}
Also used : 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 50 with Platform

use of com.google.cloud.tools.jib.api.buildplan.Platform in project jib by GoogleContainerTools.

the class JarFilesTest method testToJibContainerBuilder_explodedLayeredSpringBoot_basicInfo.

@Test
public void testToJibContainerBuilder_explodedLayeredSpringBoot_basicInfo() throws IOException, InvalidImageReferenceException {
    when(mockSpringBootExplodedProcessor.getJavaVersion()).thenReturn(8);
    FileEntriesLayer layer = FileEntriesLayer.builder().setName("classes").addEntry(Paths.get("path/to/tempDirectory/BOOT-INF/classes/class1.class"), AbsoluteUnixPath.get("/app/BOOT-INF/classes/class1.class")).build();
    when(mockCommonContainerConfigCliOptions.getFrom()).thenReturn(Optional.empty());
    when(mockSpringBootExplodedProcessor.createLayers()).thenReturn(Arrays.asList(layer));
    when(mockSpringBootExplodedProcessor.computeEntrypoint(anyList())).thenReturn(ImmutableList.of("java", "-cp", "/app", "org.springframework.boot.loader.JarLauncher"));
    when(mockCommonContainerConfigCliOptions.getFrom()).thenReturn(Optional.empty());
    JibContainerBuilder containerBuilder = JarFiles.toJibContainerBuilder(mockSpringBootExplodedProcessor, mockJarCommand, mockCommonCliOptions, mockCommonContainerConfigCliOptions, mockLogger);
    ContainerBuildPlan buildPlan = containerBuilder.toContainerBuildPlan();
    assertThat(buildPlan.getBaseImage()).isEqualTo("eclipse-temurin:8-jre");
    assertThat(buildPlan.getPlatforms()).isEqualTo(ImmutableSet.of(new Platform("amd64", "linux")));
    assertThat(buildPlan.getCreationTime()).isEqualTo(Instant.EPOCH);
    assertThat(buildPlan.getFormat()).isEqualTo(ImageFormat.Docker);
    assertThat(buildPlan.getEnvironment()).isEmpty();
    assertThat(buildPlan.getLabels()).isEmpty();
    assertThat(buildPlan.getVolumes()).isEmpty();
    assertThat(buildPlan.getExposedPorts()).isEmpty();
    assertThat(buildPlan.getUser()).isNull();
    assertThat(buildPlan.getWorkingDirectory()).isNull();
    assertThat(buildPlan.getEntrypoint()).containsExactly("java", "-cp", "/app", "org.springframework.boot.loader.JarLauncher").inOrder();
    assertThat(buildPlan.getLayers()).hasSize(1);
    assertThat(buildPlan.getLayers().get(0).getName()).isEqualTo("classes");
    assertThat(((FileEntriesLayer) buildPlan.getLayers().get(0)).getEntries()).containsExactlyElementsIn(FileEntriesLayer.builder().addEntry(Paths.get("path/to/tempDirectory/BOOT-INF/classes/class1.class"), AbsoluteUnixPath.get("/app/BOOT-INF/classes/class1.class")).build().getEntries());
}
Also used : 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)

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