Search in sources :

Example 21 with V22ManifestListTemplate

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

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

the class CacheStorageReaderTest method testVerifyImageMetadata_manifestListMissing.

@Test
public void testVerifyImageMetadata_manifestListMissing() {
    ManifestAndConfigTemplate manifestAndConfig = new ManifestAndConfigTemplate(new V22ManifestListTemplate(), new ContainerConfigurationTemplate());
    ImageMetadataTemplate metadata = new ImageMetadataTemplate(null, Arrays.asList(manifestAndConfig, manifestAndConfig));
    try {
        CacheStorageReader.verifyImageMetadata(metadata, Paths.get("/cache/dir"));
        Assert.fail();
    } catch (CacheCorruptedException ex) {
        MatcherAssert.assertThat(ex.getMessage(), CoreMatchers.startsWith("Manifest list missing"));
    }
}
Also used : V22ManifestListTemplate(com.google.cloud.tools.jib.image.json.V22ManifestListTemplate) 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) Test(org.junit.Test)

Example 23 with V22ManifestListTemplate

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

the class CacheStorageReaderTest method testRetrieveMetadata_v22ManifestList.

@Test
public void testRetrieveMetadata_v22ManifestList() throws IOException, URISyntaxException, CacheCorruptedException {
    setupCachedMetadataV22ManifestList(cacheDirectory);
    ImageMetadataTemplate metadata = cacheStorageReader.retrieveMetadata(ImageReference.of("test", "image", "tag")).get();
    MatcherAssert.assertThat(metadata.getManifestList(), CoreMatchers.instanceOf(V22ManifestListTemplate.class));
    List<ManifestDescriptorTemplate> manifestDescriptors = ((V22ManifestListTemplate) metadata.getManifestList()).getManifests();
    Assert.assertEquals(3, manifestDescriptors.size());
    Assert.assertEquals("sha256:e692418e4cbaf90ca69d05a66403747baa33ee08806650b51fab815ad7fc331f", manifestDescriptors.get(0).getDigest());
    Assert.assertEquals("sha256:5b0bcabd1ed22e9fb1310cf6c2dec7cdef19f0ad69efa1f392e94a4333501270", manifestDescriptors.get(1).getDigest());
    Assert.assertEquals("sha256:cccbcabd1ed22e9fb1310cf6c2dec7cdef19f0ad69efa1f392e94a4333501999", manifestDescriptors.get(2).getDigest());
    Assert.assertEquals(2, metadata.getManifestsAndConfigs().size());
    ManifestAndConfigTemplate manifestAndConfig1 = metadata.getManifestsAndConfigs().get(0);
    ManifestAndConfigTemplate manifestAndConfig2 = metadata.getManifestsAndConfigs().get(1);
    V22ManifestTemplate manifest1 = (V22ManifestTemplate) manifestAndConfig1.getManifest();
    V22ManifestTemplate manifest2 = (V22ManifestTemplate) manifestAndConfig2.getManifest();
    Assert.assertEquals(2, manifest1.getSchemaVersion());
    Assert.assertEquals(2, manifest2.getSchemaVersion());
    Assert.assertEquals(1, manifest1.getLayers().size());
    Assert.assertEquals(1, manifest2.getLayers().size());
    Assert.assertEquals("4945ba5011739b0b98c4a41afe224e417f47c7c99b2ce76830999c9a0861b236", manifest1.getLayers().get(0).getDigest().getHash());
    Assert.assertEquals("8c662931926fa990b41da3c9f42663a537ccd498130030f9149173a0493832ad", manifest2.getLayers().get(0).getDigest().getHash());
    Assert.assertEquals("8c662931926fa990b41da3c9f42663a537ccd498130030f9149173a0493832ad", manifest1.getContainerConfiguration().getDigest().getHash());
    Assert.assertEquals("2000a70a1ce8bba401c493376fdb9eb81bcf7155212f4ce4c6ff96e577718a49", manifest2.getContainerConfiguration().getDigest().getHash());
    Assert.assertEquals("wasm", manifestAndConfig1.getConfig().getArchitecture());
    Assert.assertEquals("wasm", manifestAndConfig2.getConfig().getArchitecture());
}
Also used : V22ManifestListTemplate(com.google.cloud.tools.jib.image.json.V22ManifestListTemplate) V22ManifestTemplate(com.google.cloud.tools.jib.image.json.V22ManifestTemplate) ManifestDescriptorTemplate(com.google.cloud.tools.jib.image.json.V22ManifestListTemplate.ManifestDescriptorTemplate) ImageMetadataTemplate(com.google.cloud.tools.jib.image.json.ImageMetadataTemplate) ManifestAndConfigTemplate(com.google.cloud.tools.jib.image.json.ManifestAndConfigTemplate) Test(org.junit.Test)

Example 24 with V22ManifestListTemplate

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

the class CacheStorageReaderTest method testVerifyImageMetadata_schema2ManifestsCorrupted_nullManifestDigest.

@Test
public void testVerifyImageMetadata_schema2ManifestsCorrupted_nullManifestDigest() {
    ManifestAndConfigTemplate manifestAndConfig = new ManifestAndConfigTemplate(new V22ManifestTemplate(), new ContainerConfigurationTemplate(), null);
    ImageMetadataTemplate metadata = new ImageMetadataTemplate(new V22ManifestListTemplate(), Arrays.asList(manifestAndConfig));
    try {
        CacheStorageReader.verifyImageMetadata(metadata, Paths.get("/cache/dir"));
        Assert.fail();
    } catch (CacheCorruptedException ex) {
        MatcherAssert.assertThat(ex.getMessage(), CoreMatchers.startsWith("Schema 2 manifests corrupted"));
    }
}
Also used : V22ManifestTemplate(com.google.cloud.tools.jib.image.json.V22ManifestTemplate) V22ManifestListTemplate(com.google.cloud.tools.jib.image.json.V22ManifestListTemplate) 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) Test(org.junit.Test)

Example 25 with V22ManifestListTemplate

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

the class ManifestPullerTest method testHandleResponse_v22ManifestList.

@Test
public void testHandleResponse_v22ManifestList() throws URISyntaxException, IOException, UnknownManifestFormatException {
    Path v22ManifestListFile = Paths.get(Resources.getResource("core/json/v22manifest_list.json").toURI());
    InputStream v22ManifestList = new ByteArrayInputStream(Files.readAllBytes(v22ManifestListFile));
    DescriptorDigest expectedDigest = Digests.computeDigest(v22ManifestList).getDigest();
    v22ManifestList.reset();
    Mockito.when(mockResponse.getBody()).thenReturn(v22ManifestList);
    ManifestAndDigest<V22ManifestListTemplate> manifestAndDigest = new ManifestPuller<>(fakeRegistryEndpointRequestProperties, "test-image-tag", V22ManifestListTemplate.class).handleResponse(mockResponse);
    V22ManifestListTemplate manifestTemplate = manifestAndDigest.getManifest();
    MatcherAssert.assertThat(manifestTemplate, CoreMatchers.instanceOf(V22ManifestListTemplate.class));
    Assert.assertTrue(manifestTemplate.getManifests().size() > 0);
    Assert.assertEquals(expectedDigest, manifestAndDigest.getDigest());
}
Also used : Path(java.nio.file.Path) V22ManifestListTemplate(com.google.cloud.tools.jib.image.json.V22ManifestListTemplate) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) DescriptorDigest(com.google.cloud.tools.jib.api.DescriptorDigest) Test(org.junit.Test)

Aggregations

V22ManifestListTemplate (com.google.cloud.tools.jib.image.json.V22ManifestListTemplate)38 Test (org.junit.Test)34 ImageMetadataTemplate (com.google.cloud.tools.jib.image.json.ImageMetadataTemplate)22 ManifestAndConfigTemplate (com.google.cloud.tools.jib.image.json.ManifestAndConfigTemplate)22 V22ManifestTemplate (com.google.cloud.tools.jib.image.json.V22ManifestTemplate)22 ContainerConfigurationTemplate (com.google.cloud.tools.jib.image.json.ContainerConfigurationTemplate)18 Platform (com.google.cloud.tools.jib.api.buildplan.Platform)14 ManifestTemplate (com.google.cloud.tools.jib.image.json.ManifestTemplate)12 ImageReference (com.google.cloud.tools.jib.api.ImageReference)10 V21ManifestTemplate (com.google.cloud.tools.jib.image.json.V21ManifestTemplate)10 Image (com.google.cloud.tools.jib.image.Image)8 ManifestDescriptorTemplate (com.google.cloud.tools.jib.image.json.V22ManifestListTemplate.ManifestDescriptorTemplate)8 DescriptorDigest (com.google.cloud.tools.jib.api.DescriptorDigest)6 Path (java.nio.file.Path)6 ProgressEventDispatcher (com.google.cloud.tools.jib.builder.ProgressEventDispatcher)4 Cache (com.google.cloud.tools.jib.cache.Cache)4 ImageConfiguration (com.google.cloud.tools.jib.configuration.ImageConfiguration)4 EventHandlers (com.google.cloud.tools.jib.event.EventHandlers)4 BuildableManifestTemplate (com.google.cloud.tools.jib.image.json.BuildableManifestTemplate)4 RegistryClient (com.google.cloud.tools.jib.registry.RegistryClient)4