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());
}
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"));
}
}
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());
}
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"));
}
}
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());
}
Aggregations