Search in sources :

Example 21 with ManifestAndConfigTemplate

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

the class CacheStorageReaderTest method setupCachedMetadataV21.

private static void setupCachedMetadataV21(Path cacheDirectory) throws IOException, URISyntaxException {
    Path imageDirectory = cacheDirectory.resolve("images/test/image!tag");
    Files.createDirectories(imageDirectory);
    ManifestAndConfigTemplate manifestAndConfig = new ManifestAndConfigTemplate(loadJsonResource("core/json/v21manifest.json", V21ManifestTemplate.class), null);
    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) OutputStream(java.io.OutputStream) 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)

Example 22 with ManifestAndConfigTemplate

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

the class CacheStorageReaderTest method testVerifyImageMetadata_validV21.

@Test
public void testVerifyImageMetadata_validV21() throws CacheCorruptedException {
    ManifestAndConfigTemplate manifestAndConfig = new ManifestAndConfigTemplate(new V21ManifestTemplate(), null);
    ImageMetadataTemplate metadata = new ImageMetadataTemplate(null, Arrays.asList(manifestAndConfig));
    CacheStorageReader.verifyImageMetadata(metadata, Paths.get("/cache/dir"));
// should pass without CacheCorruptedException
}
Also used : 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 23 with ManifestAndConfigTemplate

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

the class CacheStorageReaderTest method testVerifyImageMetadata_validOciImageIndex.

@Test
public void testVerifyImageMetadata_validOciImageIndex() throws CacheCorruptedException {
    ManifestAndConfigTemplate manifestAndConfig = new ManifestAndConfigTemplate(new OciManifestTemplate(), new ContainerConfigurationTemplate(), "sha256:digest");
    ImageMetadataTemplate metadata = new ImageMetadataTemplate(new OciIndexTemplate(), Arrays.asList(manifestAndConfig, 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) OciIndexTemplate(com.google.cloud.tools.jib.image.json.OciIndexTemplate) ManifestAndConfigTemplate(com.google.cloud.tools.jib.image.json.ManifestAndConfigTemplate) ImageMetadataTemplate(com.google.cloud.tools.jib.image.json.ImageMetadataTemplate) Test(org.junit.Test)

Example 24 with ManifestAndConfigTemplate

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

the class CacheStorageReaderTest method testVerifyImageMetadata_unknownManifestType.

@Test
public void testVerifyImageMetadata_unknownManifestType() {
    ManifestAndConfigTemplate manifestAndConfig = new ManifestAndConfigTemplate(Mockito.mock(ManifestTemplate.class), 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("Unknown manifest type:"));
    }
}
Also used : ContainerConfigurationTemplate(com.google.cloud.tools.jib.image.json.ContainerConfigurationTemplate) ManifestAndConfigTemplate(com.google.cloud.tools.jib.image.json.ManifestAndConfigTemplate) 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) ImageMetadataTemplate(com.google.cloud.tools.jib.image.json.ImageMetadataTemplate) Test(org.junit.Test)

Example 25 with ManifestAndConfigTemplate

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

the class CacheStorageWriterTest method testWriteMetadata_oci.

@Test
public void testWriteMetadata_oci() throws URISyntaxException, IOException, InvalidImageReferenceException {
    ContainerConfigurationTemplate containerConfig = loadJsonResource("core/json/containerconfig.json", ContainerConfigurationTemplate.class);
    OciManifestTemplate manifest = loadJsonResource("core/json/ocimanifest.json", OciManifestTemplate.class);
    OciIndexTemplate ociIndex = loadJsonResource("core/json/ociindex.json", OciIndexTemplate.class);
    ImageReference imageReference = ImageReference.parse("image.reference/project/thing:tag");
    cacheStorageWriter.writeMetadata(imageReference, new ImageMetadataTemplate(ociIndex, Arrays.asList(new ManifestAndConfigTemplate(manifest, containerConfig, "sha256:digest"))));
    Path savedMetadataPath = cacheRoot.resolve("images/image.reference/project/thing!tag/manifests_configs.json");
    Assert.assertTrue(Files.exists(savedMetadataPath));
    ImageMetadataTemplate savedMetadata = JsonTemplateMapper.readJsonFromFile(savedMetadataPath, ImageMetadataTemplate.class);
    MatcherAssert.assertThat(savedMetadata.getManifestList(), CoreMatchers.instanceOf(OciIndexTemplate.class));
    List<ContentDescriptorTemplate> savedManifestDescriptors = ((OciIndexTemplate) savedMetadata.getManifestList()).getManifests();
    Assert.assertEquals(1, savedManifestDescriptors.size());
    Assert.assertEquals("8c662931926fa990b41da3c9f42663a537ccd498130030f9149173a0493832ad", savedManifestDescriptors.get(0).getDigest().getHash());
    Assert.assertEquals(1, savedMetadata.getManifestsAndConfigs().size());
    ManifestAndConfigTemplate savedManifestAndConfig = savedMetadata.getManifestsAndConfigs().get(0);
    OciManifestTemplate savedManifest1 = (OciManifestTemplate) savedManifestAndConfig.getManifest();
    Assert.assertEquals(2, savedManifest1.getSchemaVersion());
    Assert.assertEquals(1, savedManifest1.getLayers().size());
    Assert.assertEquals("4945ba5011739b0b98c4a41afe224e417f47c7c99b2ce76830999c9a0861b236", savedManifest1.getLayers().get(0).getDigest().getHash());
    Assert.assertEquals("8c662931926fa990b41da3c9f42663a537ccd498130030f9149173a0493832ad", savedManifest1.getContainerConfiguration().getDigest().getHash());
    Assert.assertEquals("wasm", savedManifestAndConfig.getConfig().getArchitecture());
}
Also used : Path(java.nio.file.Path) OciManifestTemplate(com.google.cloud.tools.jib.image.json.OciManifestTemplate) ImageReference(com.google.cloud.tools.jib.api.ImageReference) ContainerConfigurationTemplate(com.google.cloud.tools.jib.image.json.ContainerConfigurationTemplate) ContentDescriptorTemplate(com.google.cloud.tools.jib.image.json.BuildableManifestTemplate.ContentDescriptorTemplate) OciIndexTemplate(com.google.cloud.tools.jib.image.json.OciIndexTemplate) ImageMetadataTemplate(com.google.cloud.tools.jib.image.json.ImageMetadataTemplate) ManifestAndConfigTemplate(com.google.cloud.tools.jib.image.json.ManifestAndConfigTemplate) Test(org.junit.Test)

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