use of com.google.cloud.tools.jib.image.json.V22ManifestListTemplate in project jib by google.
the class PullBaseImageStepTest method testGetCachedBaseImages_v22ManifestListCached_partialMatches.
@Test
public void testGetCachedBaseImages_v22ManifestListCached_partialMatches() 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("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(), new ContainerConfigurationTemplate(), "sha256:digest1")));
Mockito.when(cache.retrieveMetadata(imageReference)).thenReturn(Optional.of(imageMetadata));
Mockito.when(containerConfig.getPlatforms()).thenReturn(ImmutableSet.of(new Platform("arch1", "os1"), new Platform("arch2", "os2")));
Assert.assertEquals(Arrays.asList(), pullBaseImageStep.getCachedBaseImages());
}
use of com.google.cloud.tools.jib.image.json.V22ManifestListTemplate in project jib by google.
the class PullBaseImageStepTest method testLookUpPlatformSpecificImageManifest.
@Test
public void testLookUpPlatformSpecificImageManifest() throws IOException, UnlistedPlatformInManifestListException {
String manifestListJson = " {\n" + " \"schemaVersion\": 2,\n" + " \"mediaType\": \"application/vnd.docker.distribution.manifest.list.v2+json\",\n" + " \"manifests\": [\n" + " {\n" + " \"mediaType\": \"application/vnd.docker.distribution.manifest.v2+json\",\n" + " \"size\": 424,\n" + " \"digest\": \"sha256:1111111111111111111111111111111111111111111111111111111111111111\",\n" + " \"platform\": {\n" + " \"architecture\": \"arm64\",\n" + " \"os\": \"linux\"\n" + " }\n" + " },\n" + " {\n" + " \"mediaType\": \"application/vnd.docker.distribution.manifest.v2+json\",\n" + " \"size\": 425,\n" + " \"digest\": \"sha256:2222222222222222222222222222222222222222222222222222222222222222\",\n" + " \"platform\": {\n" + " \"architecture\": \"targetArchitecture\",\n" + " \"os\": \"targetOS\"\n" + " }\n" + " }\n" + " ]\n" + "}";
V22ManifestListTemplate manifestList = JsonTemplateMapper.readJson(manifestListJson, V22ManifestListTemplate.class);
String manifestDigest = pullBaseImageStep.lookUpPlatformSpecificImageManifest(manifestList, new Platform("targetArchitecture", "targetOS"));
Assert.assertEquals("sha256:2222222222222222222222222222222222222222222222222222222222222222", manifestDigest);
}
use of com.google.cloud.tools.jib.image.json.V22ManifestListTemplate in project jib by google.
the class CacheStorageReaderTest method testVerifyImageMetadata_validV22ManifestList.
@Test
public void testVerifyImageMetadata_validV22ManifestList() throws CacheCorruptedException {
ManifestAndConfigTemplate manifestAndConfig = new ManifestAndConfigTemplate(new V22ManifestTemplate(), new ContainerConfigurationTemplate(), "sha256:digest");
ImageMetadataTemplate metadata = new ImageMetadataTemplate(new V22ManifestListTemplate(), Arrays.asList(manifestAndConfig, manifestAndConfig));
CacheStorageReader.verifyImageMetadata(metadata, Paths.get("/cache/dir"));
// should pass without CacheCorruptedException
}
use of com.google.cloud.tools.jib.image.json.V22ManifestListTemplate in project jib by GoogleContainerTools.
the class JibIntegrationTest method testScratch_multiPlatform.
@Test
public void testScratch_multiPlatform() throws IOException, InterruptedException, ExecutionException, RegistryException, CacheDirectoryCreationException, InvalidImageReferenceException {
Jib.fromScratch().setPlatforms(ImmutableSet.of(new Platform("arm64", "windows"), new Platform("amd32", "windows"))).containerize(Containerizer.to(RegistryImage.named("localhost:5000/jib-scratch:multi-platform")).setAllowInsecureRegistries(true));
V22ManifestListTemplate manifestList = (V22ManifestListTemplate) registryClient.pullManifest("multi-platform").getManifest();
Assert.assertEquals(2, manifestList.getManifests().size());
ManifestDescriptorTemplate.Platform platform1 = manifestList.getManifests().get(0).getPlatform();
ManifestDescriptorTemplate.Platform platform2 = manifestList.getManifests().get(1).getPlatform();
Assert.assertEquals("arm64", platform1.getArchitecture());
Assert.assertEquals("windows", platform1.getOs());
Assert.assertEquals("amd32", platform2.getArchitecture());
Assert.assertEquals("windows", platform2.getOs());
}
use of com.google.cloud.tools.jib.image.json.V22ManifestListTemplate in project jib by GoogleContainerTools.
the class CacheStorageWriterTest method testWriteMetadata_v22.
@Test
public void testWriteMetadata_v22() throws IOException, URISyntaxException, InvalidImageReferenceException {
ContainerConfigurationTemplate containerConfig = loadJsonResource("core/json/containerconfig.json", ContainerConfigurationTemplate.class);
V22ManifestTemplate manifest1 = loadJsonResource("core/json/v22manifest.json", V22ManifestTemplate.class);
V22ManifestTemplate manifest2 = loadJsonResource("core/json/v22manifest_optional_properties.json", V22ManifestTemplate.class);
V22ManifestListTemplate manifestList = loadJsonResource("core/json/v22manifest_list.json", V22ManifestListTemplate.class);
ImageReference imageReference = ImageReference.parse("image.reference/project/thing:tag");
List<ManifestAndConfigTemplate> manifestsAndConfigs = Arrays.asList(new ManifestAndConfigTemplate(manifest1, containerConfig, "sha256:digest"), new ManifestAndConfigTemplate(manifest2, containerConfig, "sha256:digest"));
cacheStorageWriter.writeMetadata(imageReference, new ImageMetadataTemplate(manifestList, manifestsAndConfigs));
Path savedMetadataPath = cacheRoot.resolve("images/image.reference/project/thing!tag/manifests_configs.json");
Assert.assertTrue(Files.exists(savedMetadataPath));
ImageMetadataTemplate savedMetadata = JsonTemplateMapper.readJsonFromFile(savedMetadataPath, ImageMetadataTemplate.class);
MatcherAssert.assertThat(savedMetadata.getManifestList(), CoreMatchers.instanceOf(V22ManifestListTemplate.class));
List<ManifestDescriptorTemplate> savedManifestDescriptors = ((V22ManifestListTemplate) savedMetadata.getManifestList()).getManifests();
Assert.assertEquals(3, savedManifestDescriptors.size());
Assert.assertEquals("sha256:e692418e4cbaf90ca69d05a66403747baa33ee08806650b51fab815ad7fc331f", savedManifestDescriptors.get(0).getDigest());
Assert.assertEquals("sha256:5b0bcabd1ed22e9fb1310cf6c2dec7cdef19f0ad69efa1f392e94a4333501270", savedManifestDescriptors.get(1).getDigest());
Assert.assertEquals("sha256:cccbcabd1ed22e9fb1310cf6c2dec7cdef19f0ad69efa1f392e94a4333501999", savedManifestDescriptors.get(2).getDigest());
Assert.assertEquals(2, savedMetadata.getManifestsAndConfigs().size());
ManifestAndConfigTemplate savedManifestAndConfig1 = savedMetadata.getManifestsAndConfigs().get(0);
ManifestAndConfigTemplate savedManifestAndConfig2 = savedMetadata.getManifestsAndConfigs().get(1);
V22ManifestTemplate savedManifest1 = (V22ManifestTemplate) savedManifestAndConfig1.getManifest();
V22ManifestTemplate savedManifest2 = (V22ManifestTemplate) savedManifestAndConfig2.getManifest();
Assert.assertEquals(2, savedManifest1.getSchemaVersion());
Assert.assertEquals(2, savedManifest2.getSchemaVersion());
Assert.assertEquals(1, savedManifest1.getLayers().size());
Assert.assertEquals("4945ba5011739b0b98c4a41afe224e417f47c7c99b2ce76830999c9a0861b236", savedManifest1.getLayers().get(0).getDigest().getHash());
Assert.assertEquals(Arrays.asList("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"), savedManifest2.getLayers().stream().map(layer -> layer.getDigest().getHash()).collect(Collectors.toList()));
Assert.assertEquals("8c662931926fa990b41da3c9f42663a537ccd498130030f9149173a0493832ad", savedManifest1.getContainerConfiguration().getDigest().getHash());
Assert.assertEquals("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", savedManifest2.getContainerConfiguration().getDigest().getHash());
Assert.assertEquals("wasm", savedManifestAndConfig1.getConfig().getArchitecture());
Assert.assertEquals("wasm", savedManifestAndConfig2.getConfig().getArchitecture());
}
Aggregations