Search in sources :

Example 41 with ImageMetadataTemplate

use of com.google.cloud.tools.jib.image.json.ImageMetadataTemplate in project jib by google.

the class PullBaseImageStepTest method testCall_offlineMode_cached.

@Test
public void testCall_offlineMode_cached() throws LayerPropertyNotFoundException, RegistryException, LayerCountMismatchException, BadContainerConfigurationFormatException, CacheCorruptedException, CredentialRetrievalException, InvalidImageReferenceException, IOException {
    ImageReference imageReference = ImageReference.parse("cat");
    Mockito.when(imageConfiguration.getImage()).thenReturn(imageReference);
    Mockito.when(buildContext.isOffline()).thenReturn(true);
    ContainerConfigurationTemplate containerConfigJson = new ContainerConfigurationTemplate();
    containerConfigJson.setArchitecture("slim arch");
    containerConfigJson.setOs("fat system");
    ManifestAndConfigTemplate manifestAndConfig = new ManifestAndConfigTemplate(new V22ManifestTemplate(), containerConfigJson, "sha256:digest");
    ImageMetadataTemplate imageMetadata = new ImageMetadataTemplate(null, Arrays.asList(manifestAndConfig));
    Mockito.when(cache.retrieveMetadata(imageReference)).thenReturn(Optional.of(imageMetadata));
    ImagesAndRegistryClient result = pullBaseImageStep.call();
    Assert.assertEquals("fat system", result.images.get(0).getOs());
    Assert.assertNull(result.registryClient);
    Mockito.verify(buildContext, Mockito.never()).newBaseImageRegistryClientFactory();
}
Also used : ImageReference(com.google.cloud.tools.jib.api.ImageReference) V22ManifestTemplate(com.google.cloud.tools.jib.image.json.V22ManifestTemplate) ContainerConfigurationTemplate(com.google.cloud.tools.jib.image.json.ContainerConfigurationTemplate) ImagesAndRegistryClient(com.google.cloud.tools.jib.builder.steps.PullBaseImageStep.ImagesAndRegistryClient) ManifestAndConfigTemplate(com.google.cloud.tools.jib.image.json.ManifestAndConfigTemplate) ImageMetadataTemplate(com.google.cloud.tools.jib.image.json.ImageMetadataTemplate) Test(org.junit.Test)

Example 42 with ImageMetadataTemplate

use of com.google.cloud.tools.jib.image.json.ImageMetadataTemplate in project jib by google.

the class PullBaseImageStepTest method testCall_digestBaseImage.

@Test
public void testCall_digestBaseImage() throws LayerPropertyNotFoundException, IOException, RegistryException, LayerCountMismatchException, BadContainerConfigurationFormatException, CacheCorruptedException, CredentialRetrievalException, InvalidImageReferenceException {
    ImageReference imageReference = ImageReference.parse("awesome@sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
    Assert.assertTrue(imageReference.getDigest().isPresent());
    Mockito.when(imageConfiguration.getImage()).thenReturn(imageReference);
    ContainerConfigurationTemplate containerConfigJson = new ContainerConfigurationTemplate();
    containerConfigJson.setArchitecture("slim arch");
    containerConfigJson.setOs("fat system");
    ManifestAndConfigTemplate manifestAndConfig = new ManifestAndConfigTemplate(new V22ManifestTemplate(), containerConfigJson, "sha256:digest");
    ImageMetadataTemplate imageMetadata = new ImageMetadataTemplate(null, Arrays.asList(manifestAndConfig));
    Mockito.when(cache.retrieveMetadata(imageReference)).thenReturn(Optional.of(imageMetadata));
    ImagesAndRegistryClient result = pullBaseImageStep.call();
    Assert.assertEquals("fat system", result.images.get(0).getOs());
    Assert.assertEquals(registryClient, result.registryClient);
}
Also used : ImageReference(com.google.cloud.tools.jib.api.ImageReference) V22ManifestTemplate(com.google.cloud.tools.jib.image.json.V22ManifestTemplate) ContainerConfigurationTemplate(com.google.cloud.tools.jib.image.json.ContainerConfigurationTemplate) ImagesAndRegistryClient(com.google.cloud.tools.jib.builder.steps.PullBaseImageStep.ImagesAndRegistryClient) ManifestAndConfigTemplate(com.google.cloud.tools.jib.image.json.ManifestAndConfigTemplate) ImageMetadataTemplate(com.google.cloud.tools.jib.image.json.ImageMetadataTemplate) Test(org.junit.Test)

Example 43 with ImageMetadataTemplate

use of com.google.cloud.tools.jib.image.json.ImageMetadataTemplate 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 44 with ImageMetadataTemplate

use of com.google.cloud.tools.jib.image.json.ImageMetadataTemplate 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)

Example 45 with ImageMetadataTemplate

use of com.google.cloud.tools.jib.image.json.ImageMetadataTemplate in project jib by google.

the class PullBaseImageStepTest method testGetCachedBaseImages_v22ManifestCached.

@Test
public void testGetCachedBaseImages_v22ManifestCached() throws InvalidImageReferenceException, IOException, CacheCorruptedException, UnlistedPlatformInManifestListException, BadContainerConfigurationFormatException, LayerCountMismatchException {
    ImageReference imageReference = ImageReference.parse("cat");
    Mockito.when(buildContext.getBaseImageConfiguration()).thenReturn(ImageConfiguration.builder(imageReference).build());
    ContainerConfigurationTemplate containerConfigJson = new ContainerConfigurationTemplate();
    containerConfigJson.setArchitecture("slim arch");
    containerConfigJson.setOs("fat system");
    ManifestAndConfigTemplate manifestAndConfig = new ManifestAndConfigTemplate(new V22ManifestTemplate(), containerConfigJson, "sha256:digest");
    ImageMetadataTemplate imageMetadata = new ImageMetadataTemplate(null, Arrays.asList(manifestAndConfig));
    Mockito.when(cache.retrieveMetadata(imageReference)).thenReturn(Optional.of(imageMetadata));
    List<Image> images = pullBaseImageStep.getCachedBaseImages();
    Assert.assertEquals(1, images.size());
    Assert.assertEquals("slim arch", images.get(0).getArchitecture());
    Assert.assertEquals("fat system", images.get(0).getOs());
}
Also used : ImageReference(com.google.cloud.tools.jib.api.ImageReference) V22ManifestTemplate(com.google.cloud.tools.jib.image.json.V22ManifestTemplate) ContainerConfigurationTemplate(com.google.cloud.tools.jib.image.json.ContainerConfigurationTemplate) 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

ImageMetadataTemplate (com.google.cloud.tools.jib.image.json.ImageMetadataTemplate)82 ManifestAndConfigTemplate (com.google.cloud.tools.jib.image.json.ManifestAndConfigTemplate)70 Test (org.junit.Test)58 ContainerConfigurationTemplate (com.google.cloud.tools.jib.image.json.ContainerConfigurationTemplate)52 V22ManifestTemplate (com.google.cloud.tools.jib.image.json.V22ManifestTemplate)34 V21ManifestTemplate (com.google.cloud.tools.jib.image.json.V21ManifestTemplate)28 ImageReference (com.google.cloud.tools.jib.api.ImageReference)26 V22ManifestListTemplate (com.google.cloud.tools.jib.image.json.V22ManifestListTemplate)22 Path (java.nio.file.Path)22 OciManifestTemplate (com.google.cloud.tools.jib.image.json.OciManifestTemplate)18 ManifestTemplate (com.google.cloud.tools.jib.image.json.ManifestTemplate)14 Image (com.google.cloud.tools.jib.image.Image)12 OutputStream (java.io.OutputStream)12 Platform (com.google.cloud.tools.jib.api.buildplan.Platform)10 BuildableManifestTemplate (com.google.cloud.tools.jib.image.json.BuildableManifestTemplate)8 DescriptorDigest (com.google.cloud.tools.jib.api.DescriptorDigest)6 Blobs (com.google.cloud.tools.jib.blob.Blobs)6 ImagesAndRegistryClient (com.google.cloud.tools.jib.builder.steps.PullBaseImageStep.ImagesAndRegistryClient)6 OciIndexTemplate (com.google.cloud.tools.jib.image.json.OciIndexTemplate)6 JsonTemplateMapper (com.google.cloud.tools.jib.json.JsonTemplateMapper)6