use of com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan in project jib by GoogleContainerTools.
the class JarFilesTest method testToJibContainerBuilder_packagedStandard_basicInfo.
@Test
public void testToJibContainerBuilder_packagedStandard_basicInfo() throws IOException, InvalidImageReferenceException {
when(mockStandardPackagedProcessor.getJavaVersion()).thenReturn(8);
FileEntriesLayer layer = FileEntriesLayer.builder().setName("jar").addEntry(Paths.get("path/to/standardJar.jar"), AbsoluteUnixPath.get("/app/standardJar.jar")).build();
when(mockStandardPackagedProcessor.createLayers()).thenReturn(Arrays.asList(layer));
when(mockStandardPackagedProcessor.computeEntrypoint(anyList())).thenReturn(ImmutableList.of("java", "-jar", "/app/standardJar.jar"));
when(mockCommonContainerConfigCliOptions.getFrom()).thenReturn(Optional.empty());
JibContainerBuilder containerBuilder = JarFiles.toJibContainerBuilder(mockStandardPackagedProcessor, 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/standardJar.jar").inOrder();
assertThat(buildPlan.getLayers().get(0).getName()).isEqualTo("jar");
assertThat(((FileEntriesLayer) buildPlan.getLayers().get(0)).getEntries()).isEqualTo(FileEntriesLayer.builder().addEntry(Paths.get("path/to/standardJar.jar"), AbsoluteUnixPath.get("/app/standardJar.jar")).build().getEntries());
}
use of com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan in project jib by GoogleContainerTools.
the class JarFilesTest method testToJibContainerBuilder_explodedStandard_basicInfo.
@Test
public void testToJibContainerBuilder_explodedStandard_basicInfo() throws IOException, InvalidImageReferenceException {
when(mockStandardExplodedProcessor.getJavaVersion()).thenReturn(8);
FileEntriesLayer layer = FileEntriesLayer.builder().setName("classes").addEntry(Paths.get("path/to/tempDirectory/class1.class"), AbsoluteUnixPath.get("/app/explodedJar/class1.class")).build();
when(mockStandardExplodedProcessor.createLayers()).thenReturn(Arrays.asList(layer));
when(mockStandardExplodedProcessor.computeEntrypoint(anyList())).thenReturn(ImmutableList.of("java", "-cp", "/app/explodedJar:/app/dependencies/*", "HelloWorld"));
when(mockCommonContainerConfigCliOptions.getFrom()).thenReturn(Optional.empty());
JibContainerBuilder containerBuilder = JarFiles.toJibContainerBuilder(mockStandardExplodedProcessor, 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/explodedJar:/app/dependencies/*", "HelloWorld").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/class1.class"), AbsoluteUnixPath.get("/app/explodedJar/class1.class")).build().getEntries());
}
use of com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan in project jib by GoogleContainerTools.
the class JarFilesTest method testToJibContainer_defaultBaseImage.
@Test
@Parameters(value = { "8, eclipse-temurin:8-jre", "9, eclipse-temurin:11-jre", "11, eclipse-temurin:11-jre", "13, eclipse-temurin:17-jre", "17, eclipse-temurin:17-jre" })
public void testToJibContainer_defaultBaseImage(int javaVersion, String expectedBaseImage) throws IOException, InvalidImageReferenceException {
when(mockStandardExplodedProcessor.getJavaVersion()).thenReturn(javaVersion);
JibContainerBuilder containerBuilder = JarFiles.toJibContainerBuilder(mockStandardExplodedProcessor, mockJarCommand, mockCommonCliOptions, mockCommonContainerConfigCliOptions, mockLogger);
ContainerBuildPlan buildPlan = containerBuilder.toContainerBuildPlan();
assertThat(buildPlan.getBaseImage()).isEqualTo(expectedBaseImage);
}
use of com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan in project jib by GoogleContainerTools.
the class WarFilesTest method testToJibContainerBuilder_explodedStandard_basicInfo.
@Test
public void testToJibContainerBuilder_explodedStandard_basicInfo() throws IOException, InvalidImageReferenceException {
FileEntriesLayer layer = FileEntriesLayer.builder().setName("classes").addEntry(Paths.get("path/to/tempDirectory/WEB-INF/classes/class1.class"), AbsoluteUnixPath.get("/my/app/WEB-INF/classes/class1.class")).build();
when(mockStandardWarExplodedProcessor.createLayers()).thenReturn(Arrays.asList(layer));
when(mockCommonContainerConfigCliOptions.isJettyBaseimage()).thenReturn(true);
JibContainerBuilder containerBuilder = WarFiles.toJibContainerBuilder(mockStandardWarExplodedProcessor, mockCommonCliOptions, mockCommonContainerConfigCliOptions, mockLogger);
ContainerBuildPlan buildPlan = containerBuilder.toContainerBuildPlan();
assertThat(buildPlan.getBaseImage()).isEqualTo("jetty");
assertThat(buildPlan.getEntrypoint()).containsExactly("java", "-jar", "/usr/local/jetty/start.jar").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/WEB-INF/classes/class1.class"), AbsoluteUnixPath.get("/my/app/WEB-INF/classes/class1.class")).build().getEntries());
}
use of com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan in project jib by GoogleContainerTools.
the class WarFilesTest method testToJibContainerBuilder_optionalParameters.
@Test
public void testToJibContainerBuilder_optionalParameters() throws IOException, InvalidImageReferenceException {
when(mockCommonContainerConfigCliOptions.getFrom()).thenReturn(Optional.of("base-image"));
when(mockCommonContainerConfigCliOptions.getExposedPorts()).thenReturn(ImmutableSet.of(Port.udp(123)));
when(mockCommonContainerConfigCliOptions.getVolumes()).thenReturn(ImmutableSet.of(AbsoluteUnixPath.get("/volume1"), AbsoluteUnixPath.get("/volume2")));
when(mockCommonContainerConfigCliOptions.getEnvironment()).thenReturn(ImmutableMap.of("key1", "value1"));
when(mockCommonContainerConfigCliOptions.getLabels()).thenReturn(ImmutableMap.of("label", "mylabel"));
when(mockCommonContainerConfigCliOptions.getUser()).thenReturn(Optional.of("customUser"));
when(mockCommonContainerConfigCliOptions.getFormat()).thenReturn(Optional.of(ImageFormat.OCI));
when(mockCommonContainerConfigCliOptions.getProgramArguments()).thenReturn(ImmutableList.of("arg1"));
when(mockCommonContainerConfigCliOptions.getEntrypoint()).thenReturn(ImmutableList.of("custom", "entrypoint"));
when(mockCommonContainerConfigCliOptions.getCreationTime()).thenReturn(Optional.of(Instant.ofEpochSecond(5)));
JibContainerBuilder containerBuilder = WarFiles.toJibContainerBuilder(mockStandardWarExplodedProcessor, mockCommonCliOptions, mockCommonContainerConfigCliOptions, mockLogger);
ContainerBuildPlan buildPlan = containerBuilder.toContainerBuildPlan();
assertThat(buildPlan.getBaseImage()).isEqualTo("base-image");
assertThat(buildPlan.getExposedPorts()).isEqualTo(ImmutableSet.of(Port.udp(123)));
assertThat(buildPlan.getVolumes()).isEqualTo(ImmutableSet.of(AbsoluteUnixPath.get("/volume1"), AbsoluteUnixPath.get("/volume2")));
assertThat(buildPlan.getEnvironment()).isEqualTo(ImmutableMap.of("key1", "value1"));
assertThat(buildPlan.getLabels()).isEqualTo(ImmutableMap.of("label", "mylabel"));
assertThat(buildPlan.getUser()).isEqualTo("customUser");
assertThat(buildPlan.getFormat()).isEqualTo(ImageFormat.OCI);
assertThat(buildPlan.getCmd()).isEqualTo(ImmutableList.of("arg1"));
assertThat(buildPlan.getEntrypoint()).isEqualTo(ImmutableList.of("custom", "entrypoint"));
assertThat(buildPlan.getCreationTime()).isEqualTo(Instant.ofEpochSecond(5));
}
Aggregations