Search in sources :

Example 66 with ImageMetadataTemplate

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

Example 67 with ImageMetadataTemplate

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

use of com.google.cloud.tools.jib.image.json.ImageMetadataTemplate 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
}
Also used : V22ManifestTemplate(com.google.cloud.tools.jib.image.json.V22ManifestTemplate) V22ManifestListTemplate(com.google.cloud.tools.jib.image.json.V22ManifestListTemplate) 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 69 with ImageMetadataTemplate

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

Example 70 with ImageMetadataTemplate

use of com.google.cloud.tools.jib.image.json.ImageMetadataTemplate in project jib by google.

the class CacheStorageReaderTest method testRetrieveMetadata_v21SingleManifest.

@Test
public void testRetrieveMetadata_v21SingleManifest() throws IOException, URISyntaxException, CacheCorruptedException {
    setupCachedMetadataV21(cacheDirectory);
    ImageMetadataTemplate metadata = cacheStorageReader.retrieveMetadata(ImageReference.of("test", "image", "tag")).get();
    Assert.assertNull(metadata.getManifestList());
    Assert.assertEquals(1, metadata.getManifestsAndConfigs().size());
    Assert.assertNull(metadata.getManifestsAndConfigs().get(0).getConfig());
    V21ManifestTemplate manifestTemplate = (V21ManifestTemplate) metadata.getManifestsAndConfigs().get(0).getManifest();
    Assert.assertEquals(1, manifestTemplate.getSchemaVersion());
    Assert.assertEquals(2, manifestTemplate.getLayerDigests().size());
    Assert.assertEquals("8c662931926fa990b41da3c9f42663a537ccd498130030f9149173a0493832ad", manifestTemplate.getLayerDigests().get(0).getHash());
    Assert.assertEquals("5bd451067f9ab05e97cda8476c82f86d9b69c2dffb60a8ad2fe3723942544ab3", manifestTemplate.getLayerDigests().get(1).getHash());
}
Also used : ImageMetadataTemplate(com.google.cloud.tools.jib.image.json.ImageMetadataTemplate) V21ManifestTemplate(com.google.cloud.tools.jib.image.json.V21ManifestTemplate) Test(org.junit.Test)

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