Search in sources :

Example 81 with ImageMetadataTemplate

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);
    }
}
Also used : ImageReference(com.google.cloud.tools.jib.api.ImageReference) V21ManifestTemplate(com.google.cloud.tools.jib.image.json.V21ManifestTemplate) Files(java.nio.file.Files) BuildableManifestTemplate(com.google.cloud.tools.jib.image.json.BuildableManifestTemplate) ManifestAndConfigTemplate(com.google.cloud.tools.jib.image.json.ManifestAndConfigTemplate) JsonTemplateMapper(com.google.cloud.tools.jib.json.JsonTemplateMapper) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) DescriptorDigest(com.google.cloud.tools.jib.api.DescriptorDigest) ContainerConfigurationTemplate(com.google.cloud.tools.jib.image.json.ContainerConfigurationTemplate) List(java.util.List) Stream(java.util.stream.Stream) LockFile(com.google.cloud.tools.jib.filesystem.LockFile) ImageMetadataTemplate(com.google.cloud.tools.jib.image.json.ImageMetadataTemplate) ManifestTemplate(com.google.cloud.tools.jib.image.json.ManifestTemplate) DigestException(java.security.DigestException) Optional(java.util.Optional) Blobs(com.google.cloud.tools.jib.blob.Blobs) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Path(java.nio.file.Path) ManifestAndConfigTemplate(com.google.cloud.tools.jib.image.json.ManifestAndConfigTemplate) V21ManifestTemplate(com.google.cloud.tools.jib.image.json.V21ManifestTemplate) BuildableManifestTemplate(com.google.cloud.tools.jib.image.json.BuildableManifestTemplate) ManifestTemplate(com.google.cloud.tools.jib.image.json.ManifestTemplate) BuildableManifestTemplate(com.google.cloud.tools.jib.image.json.BuildableManifestTemplate) V21ManifestTemplate(com.google.cloud.tools.jib.image.json.V21ManifestTemplate) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 82 with ImageMetadataTemplate

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));
}
Also used : ManifestAndConfigTemplate(com.google.cloud.tools.jib.image.json.ManifestAndConfigTemplate) ImageMetadataTemplate(com.google.cloud.tools.jib.image.json.ImageMetadataTemplate)

Aggregations

ImageMetadataTemplate (com.google.cloud.tools.jib.image.json.ImageMetadataTemplate)82 ManifestAndConfigTemplate (com.google.cloud.tools.jib.image.json.ManifestAndConfigTemplate)70 Test (org.junit.Test)58 ContainerConfigurationTemplate (com.google.cloud.tools.jib.image.json.ContainerConfigurationTemplate)52 V22ManifestTemplate (com.google.cloud.tools.jib.image.json.V22ManifestTemplate)34 V21ManifestTemplate (com.google.cloud.tools.jib.image.json.V21ManifestTemplate)28 ImageReference (com.google.cloud.tools.jib.api.ImageReference)26 V22ManifestListTemplate (com.google.cloud.tools.jib.image.json.V22ManifestListTemplate)22 Path (java.nio.file.Path)22 OciManifestTemplate (com.google.cloud.tools.jib.image.json.OciManifestTemplate)18 ManifestTemplate (com.google.cloud.tools.jib.image.json.ManifestTemplate)14 Image (com.google.cloud.tools.jib.image.Image)12 OutputStream (java.io.OutputStream)12 Platform (com.google.cloud.tools.jib.api.buildplan.Platform)10 BuildableManifestTemplate (com.google.cloud.tools.jib.image.json.BuildableManifestTemplate)8 DescriptorDigest (com.google.cloud.tools.jib.api.DescriptorDigest)6 Blobs (com.google.cloud.tools.jib.blob.Blobs)6 ImagesAndRegistryClient (com.google.cloud.tools.jib.builder.steps.PullBaseImageStep.ImagesAndRegistryClient)6 OciIndexTemplate (com.google.cloud.tools.jib.image.json.OciIndexTemplate)6 JsonTemplateMapper (com.google.cloud.tools.jib.json.JsonTemplateMapper)6