use of com.google.cloud.tools.jib.image.json.ManifestAndConfigTemplate in project jib by GoogleContainerTools.
the class CacheStorageReaderTest method setupCachedMetadataV22.
private static void setupCachedMetadataV22(Path cacheDirectory) throws IOException, URISyntaxException {
Path imageDirectory = cacheDirectory.resolve("images/test/image!tag");
Files.createDirectories(imageDirectory);
ManifestAndConfigTemplate manifestAndConfig = new ManifestAndConfigTemplate(loadJsonResource("core/json/v22manifest.json", V22ManifestTemplate.class), loadJsonResource("core/json/containerconfig.json", ContainerConfigurationTemplate.class), "sha256:digest");
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_validV22.
@Test
public void testVerifyImageMetadata_validV22() throws CacheCorruptedException {
ManifestAndConfigTemplate manifestAndConfig = new ManifestAndConfigTemplate(new V22ManifestTemplate(), new ContainerConfigurationTemplate());
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_schema2ManifestsCorrupted_nullContainerConfig.
@Test
public void testVerifyImageMetadata_schema2ManifestsCorrupted_nullContainerConfig() {
ManifestAndConfigTemplate manifestAndConfig = new ManifestAndConfigTemplate(new V22ManifestTemplate(), null, "sha256:digest");
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 2 manifests corrupted"));
}
}
use of com.google.cloud.tools.jib.image.json.ManifestAndConfigTemplate in project jib by GoogleContainerTools.
the class CacheStorageReader method verifyImageMetadata.
@VisibleForTesting
static void verifyImageMetadata(ImageMetadataTemplate metadata, Path metadataCacheDirectory) throws CacheCorruptedException {
List<ManifestAndConfigTemplate> manifestsAndConfigs = metadata.getManifestsAndConfigs();
if (manifestsAndConfigs.isEmpty()) {
throw new CacheCorruptedException(metadataCacheDirectory, "Manifest cache empty");
}
if (manifestsAndConfigs.stream().anyMatch(entry -> entry.getManifest() == null)) {
throw new CacheCorruptedException(metadataCacheDirectory, "Manifest(s) missing");
}
if (metadata.getManifestList() == null && manifestsAndConfigs.size() != 1) {
throw new CacheCorruptedException(metadataCacheDirectory, "Manifest list missing");
}
ManifestTemplate firstManifest = manifestsAndConfigs.get(0).getManifest();
if (firstManifest instanceof V21ManifestTemplate) {
if (metadata.getManifestList() != null || manifestsAndConfigs.stream().anyMatch(entry -> entry.getConfig() != null)) {
throw new CacheCorruptedException(metadataCacheDirectory, "Schema 1 manifests corrupted");
}
} else if (firstManifest instanceof BuildableManifestTemplate) {
if (manifestsAndConfigs.stream().anyMatch(entry -> entry.getConfig() == null)) {
throw new CacheCorruptedException(metadataCacheDirectory, "Schema 2 manifests corrupted");
}
if (metadata.getManifestList() != null && manifestsAndConfigs.stream().anyMatch(entry -> entry.getManifestDigest() == null)) {
throw new CacheCorruptedException(metadataCacheDirectory, "Schema 2 manifests corrupted");
}
} else {
throw new CacheCorruptedException(metadataCacheDirectory, "Unknown manifest type: " + firstManifest);
}
}
use of com.google.cloud.tools.jib.image.json.ManifestAndConfigTemplate in project jib by GoogleContainerTools.
the class Cache method writeMetadata.
/**
* Saves a V2.1 image manifest. This is a simple wrapper around {@link
* #writeMetadata(ImageReference, ImageMetadataTemplate)} to save a single manifest without a
* manifest list.
*
* @param imageReference the image reference to save the manifest for
* @param manifestTemplate the V2.1 manifest
* @throws IOException if an I/O exception occurs
*/
public void writeMetadata(ImageReference imageReference, V21ManifestTemplate manifestTemplate) throws IOException {
List<ManifestAndConfigTemplate> singleton = Collections.singletonList(new ManifestAndConfigTemplate(manifestTemplate, null));
cacheStorageWriter.writeMetadata(imageReference, new ImageMetadataTemplate(null, singleton));
}
Aggregations