Search in sources :

Example 1 with Platform

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\""));
}
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) ManifestPullerIntegrationTest(com.google.cloud.tools.jib.registry.ManifestPullerIntegrationTest) Test(org.junit.Test)

Example 2 with Platform

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());
}
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 3 with Platform

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());
}
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 4 with Platform

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

Example 5 with Platform

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);
}
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