use of com.google.cloud.tools.jib.image.json.ImageMetadataTemplate 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.ImageMetadataTemplate 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