use of com.google.cloud.tools.jib.api.buildplan.Platform in project jib by GoogleContainerTools.
the class JibIntegrationTest method testScratch_defaultPlatform.
@Test
public void testScratch_defaultPlatform() throws IOException, InterruptedException, ExecutionException, RegistryException, CacheDirectoryCreationException, InvalidImageReferenceException {
Jib.fromScratch().containerize(Containerizer.to(RegistryImage.named("localhost:5000/jib-scratch:default-platform")).setAllowInsecureRegistries(true));
V22ManifestTemplate manifestTemplate = registryClient.pullManifest("default-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\":\"amd64\""));
Assert.assertTrue(containerConfig.contains("\"os\":\"linux\""));
}
use of com.google.cloud.tools.jib.api.buildplan.Platform 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.Platform 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.Platform in project jib by GoogleContainerTools.
the class BuildFilesTest method testToJibContainerBuilder_requiredProperties.
@Test
public void testToJibContainerBuilder_requiredProperties() throws URISyntaxException, IOException, InvalidImageReferenceException {
Path buildfile = Paths.get(Resources.getResource("buildfiles/projects/allDefaults/jib.yaml").toURI());
JibContainerBuilder jibContainerBuilder = BuildFiles.toJibContainerBuilder(buildfile.getParent(), buildfile, buildCli, commonCliOptions, consoleLogger);
ContainerBuildPlan resolved = jibContainerBuilder.toContainerBuildPlan();
Assert.assertEquals("scratch", resolved.getBaseImage());
Assert.assertEquals(ImmutableSet.of(new Platform("amd64", "linux")), resolved.getPlatforms());
Assert.assertEquals(Instant.EPOCH, resolved.getCreationTime());
Assert.assertEquals(ImageFormat.Docker, resolved.getFormat());
Assert.assertTrue(resolved.getEnvironment().isEmpty());
Assert.assertTrue(resolved.getLabels().isEmpty());
Assert.assertTrue(resolved.getVolumes().isEmpty());
Assert.assertTrue(resolved.getExposedPorts().isEmpty());
Assert.assertNull(resolved.getUser());
Assert.assertNull(resolved.getWorkingDirectory());
Assert.assertNull(resolved.getEntrypoint());
Assert.assertTrue(resolved.getLayers().isEmpty());
}
use of com.google.cloud.tools.jib.api.buildplan.Platform in project jib by GoogleContainerTools.
the class PlatformCheckerTest method testCheckManifestPlatform_noWarningIfDefaultAmd64Linux.
@Test
public void testCheckManifestPlatform_noWarningIfDefaultAmd64Linux() {
Mockito.when(containerConfig.getPlatforms()).thenReturn(ImmutableSet.of(new Platform("amd64", "linux")));
ContainerConfigurationTemplate containerConfigJson = new ContainerConfigurationTemplate();
containerConfigJson.setArchitecture("actual arch");
containerConfigJson.setOs("actual OS");
PlatformChecker.checkManifestPlatform(buildContext, containerConfigJson);
Mockito.verifyNoInteractions(eventHandlers);
}
Aggregations