Search in sources :

Example 31 with Platform

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

the class JibContainerBuilderTest method testToBuildContext_containerConfigurationAdd.

@Test
public void testToBuildContext_containerConfigurationAdd() throws InvalidImageReferenceException, CacheDirectoryCreationException {
    ImageConfiguration imageConfiguration = ImageConfiguration.builder(ImageReference.parse("base/image")).build();
    JibContainerBuilder jibContainerBuilder = new JibContainerBuilder(imageConfiguration, spyBuildContextBuilder).addPlatform("testArchitecture", "testOS").setEntrypoint("entry", "point").setEnvironment(ImmutableMap.of("name", "value")).addEnvironmentVariable("environment", "variable").setExposedPorts(Port.tcp(1234), Port.udp(5678)).addExposedPort(Port.tcp(1337)).setLabels(ImmutableMap.of("key", "value")).addLabel("added", "label").setProgramArguments("program", "arguments");
    BuildContext buildContext = jibContainerBuilder.toBuildContext(Containerizer.to(RegistryImage.named("target/image")));
    ContainerConfiguration containerConfiguration = buildContext.getContainerConfiguration();
    Assert.assertEquals(ImmutableSet.of(new Platform("testArchitecture", "testOS"), new Platform("amd64", "linux")), containerConfiguration.getPlatforms());
    Assert.assertEquals(Arrays.asList("entry", "point"), containerConfiguration.getEntrypoint());
    Assert.assertEquals(ImmutableMap.of("name", "value", "environment", "variable"), containerConfiguration.getEnvironmentMap());
    Assert.assertEquals(ImmutableSet.of(Port.tcp(1234), Port.udp(5678), Port.tcp(1337)), containerConfiguration.getExposedPorts());
    Assert.assertEquals(ImmutableMap.of("key", "value", "added", "label"), containerConfiguration.getLabels());
    Assert.assertEquals(Arrays.asList("program", "arguments"), containerConfiguration.getProgramArguments());
    Assert.assertEquals(Instant.EPOCH, containerConfiguration.getCreationTime());
}
Also used : BuildContext(com.google.cloud.tools.jib.configuration.BuildContext) Platform(com.google.cloud.tools.jib.api.buildplan.Platform) ImageConfiguration(com.google.cloud.tools.jib.configuration.ImageConfiguration) ContainerConfiguration(com.google.cloud.tools.jib.configuration.ContainerConfiguration) Test(org.junit.Test)

Example 32 with Platform

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

the class PlatformCheckerTest method testCheckManifestPlatform_tarBaseImage.

@Test
public void testCheckManifestPlatform_tarBaseImage() {
    Path tar = Paths.get("/foo/bar.tar");
    Mockito.when(buildContext.getBaseImageConfiguration()).thenReturn(ImageConfiguration.builder(ImageReference.scratch()).setTarPath(tar).build());
    Mockito.when(containerConfig.getPlatforms()).thenReturn(ImmutableSet.of(new Platform("amd64", "linux"), new Platform("arch", "os")));
    PlatformChecker.checkManifestPlatform(buildContext, new ContainerConfigurationTemplate());
    Mockito.verify(eventHandlers).dispatch(LogEvent.warn("platforms configured, but '" + tar.toString() + "' is not a manifest list"));
}
Also used : Path(java.nio.file.Path) ContainerConfigurationTemplate(com.google.cloud.tools.jib.image.json.ContainerConfigurationTemplate) Platform(com.google.cloud.tools.jib.api.buildplan.Platform) Test(org.junit.Test)

Example 33 with Platform

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

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)

Example 34 with Platform

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

the class PullBaseImageStepTest method testGetCachedBaseImages_v22ManifestListCached.

@Test
public void testGetCachedBaseImages_v22ManifestListCached() throws InvalidImageReferenceException, IOException, CacheCorruptedException, UnlistedPlatformInManifestListException, BadContainerConfigurationFormatException, LayerCountMismatchException {
    ImageReference imageReference = ImageReference.parse("cat");
    Mockito.when(buildContext.getBaseImageConfiguration()).thenReturn(ImageConfiguration.builder(imageReference).build());
    ContainerConfigurationTemplate containerConfigJson1 = new ContainerConfigurationTemplate();
    ContainerConfigurationTemplate containerConfigJson2 = new ContainerConfigurationTemplate();
    containerConfigJson1.setContainerUser("user1");
    containerConfigJson2.setContainerUser("user2");
    V22ManifestListTemplate manifestList = Mockito.mock(V22ManifestListTemplate.class);
    Mockito.when(manifestList.getDigestsForPlatform("arch1", "os1")).thenReturn(Arrays.asList("sha256:digest1"));
    Mockito.when(manifestList.getDigestsForPlatform("arch2", "os2")).thenReturn(Arrays.asList("sha256:digest2"));
    ImageMetadataTemplate imageMetadata = new ImageMetadataTemplate(manifestList, Arrays.asList(new ManifestAndConfigTemplate(new V22ManifestTemplate(), containerConfigJson1, "sha256:digest1"), new ManifestAndConfigTemplate(new V22ManifestTemplate(), containerConfigJson2, "sha256:digest2")));
    Mockito.when(cache.retrieveMetadata(imageReference)).thenReturn(Optional.of(imageMetadata));
    Mockito.when(containerConfig.getPlatforms()).thenReturn(ImmutableSet.of(new Platform("arch1", "os1"), new Platform("arch2", "os2")));
    List<Image> images = pullBaseImageStep.getCachedBaseImages();
    Assert.assertEquals(2, images.size());
    Assert.assertEquals("user1", images.get(0).getUser());
    Assert.assertEquals("user2", images.get(1).getUser());
}
Also used : ImageReference(com.google.cloud.tools.jib.api.ImageReference) V22ManifestListTemplate(com.google.cloud.tools.jib.image.json.V22ManifestListTemplate) V22ManifestTemplate(com.google.cloud.tools.jib.image.json.V22ManifestTemplate) ContainerConfigurationTemplate(com.google.cloud.tools.jib.image.json.ContainerConfigurationTemplate) Platform(com.google.cloud.tools.jib.api.buildplan.Platform) ImageMetadataTemplate(com.google.cloud.tools.jib.image.json.ImageMetadataTemplate) ManifestAndConfigTemplate(com.google.cloud.tools.jib.image.json.ManifestAndConfigTemplate) Image(com.google.cloud.tools.jib.image.Image) Test(org.junit.Test)

Example 35 with Platform

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

the class PullBaseImageStepTest method testGetCachedBaseImages_v22ManifestListCached_onlyPlatforms.

@Test
public void testGetCachedBaseImages_v22ManifestListCached_onlyPlatforms() throws InvalidImageReferenceException, IOException, CacheCorruptedException, UnlistedPlatformInManifestListException, BadContainerConfigurationFormatException, LayerCountMismatchException {
    ImageReference imageReference = ImageReference.parse("cat");
    Mockito.when(buildContext.getBaseImageConfiguration()).thenReturn(ImageConfiguration.builder(imageReference).build());
    V22ManifestListTemplate manifestList = Mockito.mock(V22ManifestListTemplate.class);
    Mockito.when(manifestList.getDigestsForPlatform("target-arch", "target-os")).thenReturn(Arrays.asList("sha256:target-digest"));
    ContainerConfigurationTemplate containerConfigJson = new ContainerConfigurationTemplate();
    containerConfigJson.setContainerUser("target-user");
    ManifestAndConfigTemplate targetManifestAndConfig = new ManifestAndConfigTemplate(new V22ManifestTemplate(), containerConfigJson, "sha256:target-digest");
    ManifestAndConfigTemplate unrelatedManifestAndConfig = new ManifestAndConfigTemplate(new V22ManifestTemplate(), new ContainerConfigurationTemplate(), "sha256:unrelated-digest");
    ImageMetadataTemplate imageMetadata = new ImageMetadataTemplate(manifestList, Arrays.asList(unrelatedManifestAndConfig, targetManifestAndConfig, unrelatedManifestAndConfig));
    Mockito.when(cache.retrieveMetadata(imageReference)).thenReturn(Optional.of(imageMetadata));
    Mockito.when(containerConfig.getPlatforms()).thenReturn(ImmutableSet.of(new Platform("target-arch", "target-os")));
    List<Image> images = pullBaseImageStep.getCachedBaseImages();
    Assert.assertEquals(1, images.size());
    Assert.assertEquals("target-user", images.get(0).getUser());
}
Also used : ImageReference(com.google.cloud.tools.jib.api.ImageReference) V22ManifestListTemplate(com.google.cloud.tools.jib.image.json.V22ManifestListTemplate) V22ManifestTemplate(com.google.cloud.tools.jib.image.json.V22ManifestTemplate) ContainerConfigurationTemplate(com.google.cloud.tools.jib.image.json.ContainerConfigurationTemplate) Platform(com.google.cloud.tools.jib.api.buildplan.Platform) ManifestAndConfigTemplate(com.google.cloud.tools.jib.image.json.ManifestAndConfigTemplate) ImageMetadataTemplate(com.google.cloud.tools.jib.image.json.ImageMetadataTemplate) Image(com.google.cloud.tools.jib.image.Image) 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