Search in sources :

Example 1 with ContentDescriptorTemplate

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

Example 2 with ContentDescriptorTemplate

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

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)

Example 3 with ContentDescriptorTemplate

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

the class V22ManifestTemplateTest method testFromJson_optionalProperties.

@Test
public void testFromJson_optionalProperties() throws IOException, URISyntaxException {
    Path jsonFile = Paths.get(Resources.getResource("core/json/v22manifest_optional_properties.json").toURI());
    V22ManifestTemplate manifestJson = JsonTemplateMapper.readJsonFromFile(jsonFile, V22ManifestTemplate.class);
    List<ContentDescriptorTemplate> layers = manifestJson.getLayers();
    Assert.assertEquals(4, layers.size());
    Assert.assertNull(layers.get(0).getUrls());
    Assert.assertNull(layers.get(0).getAnnotations());
    Assert.assertEquals(Arrays.asList("url-foo", "url-bar"), layers.get(1).getUrls());
    Assert.assertNull(layers.get(1).getAnnotations());
    Assert.assertNull(layers.get(2).getUrls());
    Assert.assertEquals(ImmutableMap.of("key-foo", "value-foo"), layers.get(2).getAnnotations());
    Assert.assertEquals(Arrays.asList("cool-url"), layers.get(3).getUrls());
    Assert.assertEquals(ImmutableMap.of("key1", "value1", "key2", "value2"), layers.get(3).getAnnotations());
}
Also used : Path(java.nio.file.Path) ContentDescriptorTemplate(com.google.cloud.tools.jib.image.json.BuildableManifestTemplate.ContentDescriptorTemplate) Test(org.junit.Test)

Example 4 with ContentDescriptorTemplate

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

the class CacheStorageReaderTest method testRetrieveMetadata_ociImageIndex.

@Test
public void testRetrieveMetadata_ociImageIndex() throws IOException, URISyntaxException, CacheCorruptedException {
    setupCachedMetadataOciImageIndex(cacheDirectory);
    ImageMetadataTemplate metadata = cacheStorageReader.retrieveMetadata(ImageReference.of("test", "image", "tag")).get();
    MatcherAssert.assertThat(metadata.getManifestList(), CoreMatchers.instanceOf(OciIndexTemplate.class));
    List<ContentDescriptorTemplate> manifestDescriptors = ((OciIndexTemplate) metadata.getManifestList()).getManifests();
    Assert.assertEquals(1, manifestDescriptors.size());
    Assert.assertEquals("8c662931926fa990b41da3c9f42663a537ccd498130030f9149173a0493832ad", manifestDescriptors.get(0).getDigest().getHash());
    Assert.assertEquals(1, metadata.getManifestsAndConfigs().size());
    ManifestAndConfigTemplate manifestAndConfig = metadata.getManifestsAndConfigs().get(0);
    OciManifestTemplate manifestTemplate = (OciManifestTemplate) manifestAndConfig.getManifest();
    Assert.assertEquals(2, manifestTemplate.getSchemaVersion());
    Assert.assertEquals("8c662931926fa990b41da3c9f42663a537ccd498130030f9149173a0493832ad", manifestTemplate.getContainerConfiguration().getDigest().getHash());
    Assert.assertEquals("wasm", manifestAndConfig.getConfig().getArchitecture());
}
Also used : OciManifestTemplate(com.google.cloud.tools.jib.image.json.OciManifestTemplate) 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)

Example 5 with ContentDescriptorTemplate

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

the class CacheStorageReaderTest method testRetrieveMetadata_ociImageIndex.

@Test
public void testRetrieveMetadata_ociImageIndex() throws IOException, URISyntaxException, CacheCorruptedException {
    setupCachedMetadataOciImageIndex(cacheDirectory);
    ImageMetadataTemplate metadata = cacheStorageReader.retrieveMetadata(ImageReference.of("test", "image", "tag")).get();
    MatcherAssert.assertThat(metadata.getManifestList(), CoreMatchers.instanceOf(OciIndexTemplate.class));
    List<ContentDescriptorTemplate> manifestDescriptors = ((OciIndexTemplate) metadata.getManifestList()).getManifests();
    Assert.assertEquals(1, manifestDescriptors.size());
    Assert.assertEquals("8c662931926fa990b41da3c9f42663a537ccd498130030f9149173a0493832ad", manifestDescriptors.get(0).getDigest().getHash());
    Assert.assertEquals(1, metadata.getManifestsAndConfigs().size());
    ManifestAndConfigTemplate manifestAndConfig = metadata.getManifestsAndConfigs().get(0);
    OciManifestTemplate manifestTemplate = (OciManifestTemplate) manifestAndConfig.getManifest();
    Assert.assertEquals(2, manifestTemplate.getSchemaVersion());
    Assert.assertEquals("8c662931926fa990b41da3c9f42663a537ccd498130030f9149173a0493832ad", manifestTemplate.getContainerConfiguration().getDigest().getHash());
    Assert.assertEquals("wasm", manifestAndConfig.getConfig().getArchitecture());
}
Also used : OciManifestTemplate(com.google.cloud.tools.jib.image.json.OciManifestTemplate) 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

ContentDescriptorTemplate (com.google.cloud.tools.jib.image.json.BuildableManifestTemplate.ContentDescriptorTemplate)6 Test (org.junit.Test)6 ImageMetadataTemplate (com.google.cloud.tools.jib.image.json.ImageMetadataTemplate)4 ManifestAndConfigTemplate (com.google.cloud.tools.jib.image.json.ManifestAndConfigTemplate)4 OciIndexTemplate (com.google.cloud.tools.jib.image.json.OciIndexTemplate)4 OciManifestTemplate (com.google.cloud.tools.jib.image.json.OciManifestTemplate)4 Path (java.nio.file.Path)4 ImageReference (com.google.cloud.tools.jib.api.ImageReference)2 ContainerConfigurationTemplate (com.google.cloud.tools.jib.image.json.ContainerConfigurationTemplate)2