use of com.google.cloud.tools.jib.image.json.V22ManifestListTemplate.ManifestDescriptorTemplate in project jib by GoogleContainerTools.
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.ManifestDescriptorTemplate in project jib by google.
the class ManifestListGenerator method getManifestListTemplate.
/**
* Generates a manifest list JSON for the given {@link Image}s.
*
* @param <T> child type of {@link BuildableManifestTemplate}
* @param manifestTemplateClass the JSON template to translate the image to
* @return a manifest list JSON
* @throws IOException if generating a manifest list fails due to an I/O error when computing
* digests
*/
public <T extends BuildableManifestTemplate> ManifestTemplate getManifestListTemplate(Class<T> manifestTemplateClass) throws IOException {
Preconditions.checkArgument(manifestTemplateClass == V22ManifestTemplate.class, "Build an OCI image index is not yet supported");
Preconditions.checkState(!images.isEmpty(), "no images given");
V22ManifestListTemplate manifestList = new V22ManifestListTemplate();
for (Image image : images) {
ImageToJsonTranslator imageTranslator = new ImageToJsonTranslator(image);
BlobDescriptor configDescriptor = Digests.computeDigest(imageTranslator.getContainerConfiguration());
BuildableManifestTemplate manifestTemplate = imageTranslator.getManifestTemplate(manifestTemplateClass, configDescriptor);
BlobDescriptor manifestDescriptor = Digests.computeDigest(manifestTemplate);
ManifestDescriptorTemplate manifest = new ManifestDescriptorTemplate();
manifest.setMediaType(manifestTemplate.getManifestMediaType());
manifest.setSize(manifestDescriptor.getSize());
manifest.setDigest(manifestDescriptor.getDigest().toString());
manifest.setPlatform(image.getArchitecture(), image.getOs());
manifestList.addManifest(manifest);
}
return manifestList;
}
use of com.google.cloud.tools.jib.image.json.V22ManifestListTemplate.ManifestDescriptorTemplate in project jib by google.
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());
}
use of com.google.cloud.tools.jib.image.json.V22ManifestListTemplate.ManifestDescriptorTemplate in project jib by google.
the class PushImageStepTest method setUp.
@Before
public void setUp() {
when(buildContext.getAllTargetImageTags()).thenReturn(ImmutableSet.of("tag1", "tag2"));
when(buildContext.getEventHandlers()).thenReturn(EventHandlers.NONE);
when(buildContext.getContainerConfiguration()).thenReturn(containerConfig);
doReturn(V22ManifestTemplate.class).when(buildContext).getTargetFormat();
when(containerConfig.getPlatforms()).thenReturn(ImmutableSet.of(new Platform("amd64", "linux"), new Platform("arm64", "windows")));
when(progressDispatcherFactory.create(anyString(), anyLong())).thenReturn(progressDispatcher);
when(progressDispatcher.newChildProducer()).thenReturn(progressDispatcherFactory);
ManifestDescriptorTemplate manifest = new ManifestDescriptorTemplate();
manifest.setSize(100);
manifest.setDigest("sha256:1f25787aab4669d252bdae09a72b9c345d2a7b8c64c8dbfba4c82af4834dbccc");
manifestList.addManifest(manifest);
}
use of com.google.cloud.tools.jib.image.json.V22ManifestListTemplate.ManifestDescriptorTemplate 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());
}
Aggregations