use of com.google.cloud.tools.jib.image.json.ManifestAndConfigTemplate in project jib by google.
the class CacheStorageReaderTest method setupCachedMetadataV22ManifestList.
private static void setupCachedMetadataV22ManifestList(Path cacheDirectory) throws IOException, URISyntaxException {
Path imageDirectory = cacheDirectory.resolve("images/test/image!tag");
Files.createDirectories(imageDirectory);
ManifestTemplate v22ManifestList = loadJsonResource("core/json/v22manifest_list.json", V22ManifestListTemplate.class);
ManifestTemplate v22Manifest1 = loadJsonResource("core/json/v22manifest.json", V22ManifestTemplate.class);
ManifestTemplate v22Manifest2 = loadJsonResource("core/json/translated_v22manifest.json", V22ManifestTemplate.class);
ContainerConfigurationTemplate containerConfig = loadJsonResource("core/json/containerconfig.json", ContainerConfigurationTemplate.class);
List<ManifestAndConfigTemplate> manifestsAndConfigs = Arrays.asList(new ManifestAndConfigTemplate(v22Manifest1, containerConfig, "sha256:digest"), new ManifestAndConfigTemplate(v22Manifest2, containerConfig, "sha256:digest"));
try (OutputStream out = Files.newOutputStream(imageDirectory.resolve("manifests_configs.json"))) {
JsonTemplateMapper.writeTo(new ImageMetadataTemplate(v22ManifestList, manifestsAndConfigs), out);
}
}
use of com.google.cloud.tools.jib.image.json.ManifestAndConfigTemplate in project jib by google.
the class CacheStorageReaderTest method testVerifyImageMetadata_validOci.
@Test
public void testVerifyImageMetadata_validOci() throws CacheCorruptedException {
ManifestAndConfigTemplate manifestAndConfig = new ManifestAndConfigTemplate(new OciManifestTemplate(), new ContainerConfigurationTemplate(), "sha256:digest");
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 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.ManifestAndConfigTemplate in project jib by google.
the class CacheStorageReaderTest method testVerifyImageMetadata_schema1ManifestsCorrupted_containerConfigExists.
@Test
public void testVerifyImageMetadata_schema1ManifestsCorrupted_containerConfigExists() {
ManifestAndConfigTemplate manifestAndConfig = new ManifestAndConfigTemplate(new V21ManifestTemplate(), 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("Schema 1 manifests corrupted"));
}
}
use of com.google.cloud.tools.jib.image.json.ManifestAndConfigTemplate in project jib by google.
the class CacheStorageWriterTest method testWriteMetadata_v21.
@Test
public void testWriteMetadata_v21() throws IOException, URISyntaxException, InvalidImageReferenceException {
V21ManifestTemplate v21Manifest = loadJsonResource("core/json/v21manifest.json", V21ManifestTemplate.class);
ImageReference imageReference = ImageReference.parse("image.reference/project/thing:tag");
ManifestAndConfigTemplate manifestAndConfig = new ManifestAndConfigTemplate(v21Manifest, null);
cacheStorageWriter.writeMetadata(imageReference, new ImageMetadataTemplate(null, Arrays.asList(manifestAndConfig)));
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);
Assert.assertNull(savedMetadata.getManifestList());
Assert.assertEquals(1, savedMetadata.getManifestsAndConfigs().size());
ManifestAndConfigTemplate savedManifestAndConfig = savedMetadata.getManifestsAndConfigs().get(0);
Assert.assertNull(savedManifestAndConfig.getConfig());
V21ManifestTemplate savedManifest = (V21ManifestTemplate) savedManifestAndConfig.getManifest();
Assert.assertEquals("ppc64le", savedManifest.getContainerConfiguration().get().getArchitecture());
}
Aggregations