use of com.google.cloud.tools.jib.image.json.ManifestAndConfigTemplate in project jib by GoogleContainerTools.
the class CacheStorageReaderTest method setupCachedMetadataV21.
private static void setupCachedMetadataV21(Path cacheDirectory) throws IOException, URISyntaxException {
Path imageDirectory = cacheDirectory.resolve("images/test/image!tag");
Files.createDirectories(imageDirectory);
ManifestAndConfigTemplate manifestAndConfig = new ManifestAndConfigTemplate(loadJsonResource("core/json/v21manifest.json", V21ManifestTemplate.class), null);
try (OutputStream out = Files.newOutputStream(imageDirectory.resolve("manifests_configs.json"))) {
JsonTemplateMapper.writeTo(new ImageMetadataTemplate(null, Arrays.asList(manifestAndConfig)), out);
}
}
use of com.google.cloud.tools.jib.image.json.ManifestAndConfigTemplate in project jib by GoogleContainerTools.
the class CacheStorageReaderTest method testVerifyImageMetadata_validV21.
@Test
public void testVerifyImageMetadata_validV21() throws CacheCorruptedException {
ManifestAndConfigTemplate manifestAndConfig = new ManifestAndConfigTemplate(new V21ManifestTemplate(), null);
ImageMetadataTemplate metadata = new ImageMetadataTemplate(null, Arrays.asList(manifestAndConfig));
CacheStorageReader.verifyImageMetadata(metadata, Paths.get("/cache/dir"));
// should pass without CacheCorruptedException
}
use of com.google.cloud.tools.jib.image.json.ManifestAndConfigTemplate in project jib by GoogleContainerTools.
the class CacheStorageReaderTest method testVerifyImageMetadata_validOciImageIndex.
@Test
public void testVerifyImageMetadata_validOciImageIndex() throws CacheCorruptedException {
ManifestAndConfigTemplate manifestAndConfig = new ManifestAndConfigTemplate(new OciManifestTemplate(), new ContainerConfigurationTemplate(), "sha256:digest");
ImageMetadataTemplate metadata = new ImageMetadataTemplate(new OciIndexTemplate(), Arrays.asList(manifestAndConfig, manifestAndConfig));
CacheStorageReader.verifyImageMetadata(metadata, Paths.get("/cache/dir"));
// should pass without CacheCorruptedException
}
use of com.google.cloud.tools.jib.image.json.ManifestAndConfigTemplate in project jib by GoogleContainerTools.
the class CacheStorageReaderTest method testVerifyImageMetadata_unknownManifestType.
@Test
public void testVerifyImageMetadata_unknownManifestType() {
ManifestAndConfigTemplate manifestAndConfig = new ManifestAndConfigTemplate(Mockito.mock(ManifestTemplate.class), new ContainerConfigurationTemplate());
ImageMetadataTemplate metadata = new ImageMetadataTemplate(null, Arrays.asList(manifestAndConfig));
try {
CacheStorageReader.verifyImageMetadata(metadata, Paths.get("/cache/dir"));
Assert.fail();
} catch (CacheCorruptedException ex) {
MatcherAssert.assertThat(ex.getMessage(), CoreMatchers.startsWith("Unknown manifest type:"));
}
}
use of com.google.cloud.tools.jib.image.json.ManifestAndConfigTemplate in project jib by GoogleContainerTools.
the class CacheStorageWriterTest method testWriteMetadata_oci.
@Test
public void testWriteMetadata_oci() throws URISyntaxException, IOException, InvalidImageReferenceException {
ContainerConfigurationTemplate containerConfig = loadJsonResource("core/json/containerconfig.json", ContainerConfigurationTemplate.class);
OciManifestTemplate manifest = loadJsonResource("core/json/ocimanifest.json", OciManifestTemplate.class);
OciIndexTemplate ociIndex = loadJsonResource("core/json/ociindex.json", OciIndexTemplate.class);
ImageReference imageReference = ImageReference.parse("image.reference/project/thing:tag");
cacheStorageWriter.writeMetadata(imageReference, new ImageMetadataTemplate(ociIndex, Arrays.asList(new ManifestAndConfigTemplate(manifest, containerConfig, "sha256:digest"))));
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(OciIndexTemplate.class));
List<ContentDescriptorTemplate> savedManifestDescriptors = ((OciIndexTemplate) savedMetadata.getManifestList()).getManifests();
Assert.assertEquals(1, savedManifestDescriptors.size());
Assert.assertEquals("8c662931926fa990b41da3c9f42663a537ccd498130030f9149173a0493832ad", savedManifestDescriptors.get(0).getDigest().getHash());
Assert.assertEquals(1, savedMetadata.getManifestsAndConfigs().size());
ManifestAndConfigTemplate savedManifestAndConfig = savedMetadata.getManifestsAndConfigs().get(0);
OciManifestTemplate savedManifest1 = (OciManifestTemplate) savedManifestAndConfig.getManifest();
Assert.assertEquals(2, savedManifest1.getSchemaVersion());
Assert.assertEquals(1, savedManifest1.getLayers().size());
Assert.assertEquals("4945ba5011739b0b98c4a41afe224e417f47c7c99b2ce76830999c9a0861b236", savedManifest1.getLayers().get(0).getDigest().getHash());
Assert.assertEquals("8c662931926fa990b41da3c9f42663a537ccd498130030f9149173a0493832ad", savedManifest1.getContainerConfiguration().getDigest().getHash());
Assert.assertEquals("wasm", savedManifestAndConfig.getConfig().getArchitecture());
}
Aggregations