Search in sources :

Example 66 with ManifestAndConfigTemplate

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);
    }
}
Also used : Path(java.nio.file.Path) V22ManifestTemplate(com.google.cloud.tools.jib.image.json.V22ManifestTemplate) ContainerConfigurationTemplate(com.google.cloud.tools.jib.image.json.ContainerConfigurationTemplate) OutputStream(java.io.OutputStream) ManifestAndConfigTemplate(com.google.cloud.tools.jib.image.json.ManifestAndConfigTemplate) ImageMetadataTemplate(com.google.cloud.tools.jib.image.json.ImageMetadataTemplate)

Example 67 with ManifestAndConfigTemplate

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

Example 68 with ManifestAndConfigTemplate

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

Example 69 with ManifestAndConfigTemplate

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);
    }
}
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 70 with ManifestAndConfigTemplate

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));
}
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)70 ManifestAndConfigTemplate (com.google.cloud.tools.jib.image.json.ManifestAndConfigTemplate)70 ContainerConfigurationTemplate (com.google.cloud.tools.jib.image.json.ContainerConfigurationTemplate)50 Test (org.junit.Test)48 V22ManifestTemplate (com.google.cloud.tools.jib.image.json.V22ManifestTemplate)32 ImageReference (com.google.cloud.tools.jib.api.ImageReference)26 V21ManifestTemplate (com.google.cloud.tools.jib.image.json.V21ManifestTemplate)26 V22ManifestListTemplate (com.google.cloud.tools.jib.image.json.V22ManifestListTemplate)22 Path (java.nio.file.Path)20 OciManifestTemplate (com.google.cloud.tools.jib.image.json.OciManifestTemplate)16 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