Search in sources :

Example 6 with ManifestDescriptorTemplate

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

the class V22ManifestListTemplateTest method testFromJson.

@Test
public void testFromJson() throws IOException, URISyntaxException {
    Path jsonFile = Paths.get(Resources.getResource("core/json/v22manifest_list.json").toURI());
    V22ManifestListTemplate manifestListJson = JsonTemplateMapper.readJsonFromFile(jsonFile, V22ManifestListTemplate.class);
    Assert.assertEquals(2, manifestListJson.getSchemaVersion());
    List<ManifestDescriptorTemplate> manifests = manifestListJson.getManifests();
    Assert.assertEquals(3, manifests.size());
    List<String> validPlatformPpc = manifestListJson.getDigestsForPlatform("ppc64le", "linux");
    Assert.assertEquals(1, validPlatformPpc.size());
    Assert.assertEquals("sha256:e692418e4cbaf90ca69d05a66403747baa33ee08806650b51fab815ad7fc331f", validPlatformPpc.get(0));
    List<String> validPlatformAmd = manifestListJson.getDigestsForPlatform("amd64", "linux");
    Assert.assertEquals(2, validPlatformAmd.size());
    Assert.assertEquals("sha256:5b0bcabd1ed22e9fb1310cf6c2dec7cdef19f0ad69efa1f392e94a4333501270", validPlatformAmd.get(0));
    Assert.assertEquals("sha256:cccbcabd1ed22e9fb1310cf6c2dec7cdef19f0ad69efa1f392e94a4333501999", validPlatformAmd.get(1));
    List<String> invalidArch = manifestListJson.getDigestsForPlatform("amd72", "linux");
    Assert.assertEquals(0, invalidArch.size());
    List<String> invalidOs = manifestListJson.getDigestsForPlatform("amd64", "minix");
    Assert.assertEquals(0, invalidOs.size());
}
Also used : Path(java.nio.file.Path) ManifestDescriptorTemplate(com.google.cloud.tools.jib.image.json.V22ManifestListTemplate.ManifestDescriptorTemplate) Test(org.junit.Test)

Example 7 with ManifestDescriptorTemplate

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

the class CacheStorageWriterTest method testWriteMetadata_v22.

@Test
public void testWriteMetadata_v22() throws IOException, URISyntaxException, InvalidImageReferenceException {
    ContainerConfigurationTemplate containerConfig = loadJsonResource("core/json/containerconfig.json", ContainerConfigurationTemplate.class);
    V22ManifestTemplate manifest1 = loadJsonResource("core/json/v22manifest.json", V22ManifestTemplate.class);
    V22ManifestTemplate manifest2 = loadJsonResource("core/json/v22manifest_optional_properties.json", V22ManifestTemplate.class);
    V22ManifestListTemplate manifestList = loadJsonResource("core/json/v22manifest_list.json", V22ManifestListTemplate.class);
    ImageReference imageReference = ImageReference.parse("image.reference/project/thing:tag");
    List<ManifestAndConfigTemplate> manifestsAndConfigs = Arrays.asList(new ManifestAndConfigTemplate(manifest1, containerConfig, "sha256:digest"), new ManifestAndConfigTemplate(manifest2, containerConfig, "sha256:digest"));
    cacheStorageWriter.writeMetadata(imageReference, new ImageMetadataTemplate(manifestList, manifestsAndConfigs));
    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(V22ManifestListTemplate.class));
    List<ManifestDescriptorTemplate> savedManifestDescriptors = ((V22ManifestListTemplate) savedMetadata.getManifestList()).getManifests();
    Assert.assertEquals(3, savedManifestDescriptors.size());
    Assert.assertEquals("sha256:e692418e4cbaf90ca69d05a66403747baa33ee08806650b51fab815ad7fc331f", savedManifestDescriptors.get(0).getDigest());
    Assert.assertEquals("sha256:5b0bcabd1ed22e9fb1310cf6c2dec7cdef19f0ad69efa1f392e94a4333501270", savedManifestDescriptors.get(1).getDigest());
    Assert.assertEquals("sha256:cccbcabd1ed22e9fb1310cf6c2dec7cdef19f0ad69efa1f392e94a4333501999", savedManifestDescriptors.get(2).getDigest());
    Assert.assertEquals(2, savedMetadata.getManifestsAndConfigs().size());
    ManifestAndConfigTemplate savedManifestAndConfig1 = savedMetadata.getManifestsAndConfigs().get(0);
    ManifestAndConfigTemplate savedManifestAndConfig2 = savedMetadata.getManifestsAndConfigs().get(1);
    V22ManifestTemplate savedManifest1 = (V22ManifestTemplate) savedManifestAndConfig1.getManifest();
    V22ManifestTemplate savedManifest2 = (V22ManifestTemplate) savedManifestAndConfig2.getManifest();
    Assert.assertEquals(2, savedManifest1.getSchemaVersion());
    Assert.assertEquals(2, savedManifest2.getSchemaVersion());
    Assert.assertEquals(1, savedManifest1.getLayers().size());
    Assert.assertEquals("4945ba5011739b0b98c4a41afe224e417f47c7c99b2ce76830999c9a0861b236", savedManifest1.getLayers().get(0).getDigest().getHash());
    Assert.assertEquals(Arrays.asList("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"), savedManifest2.getLayers().stream().map(layer -> layer.getDigest().getHash()).collect(Collectors.toList()));
    Assert.assertEquals("8c662931926fa990b41da3c9f42663a537ccd498130030f9149173a0493832ad", savedManifest1.getContainerConfiguration().getDigest().getHash());
    Assert.assertEquals("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", savedManifest2.getContainerConfiguration().getDigest().getHash());
    Assert.assertEquals("wasm", savedManifestAndConfig1.getConfig().getArchitecture());
    Assert.assertEquals("wasm", savedManifestAndConfig2.getConfig().getArchitecture());
}
Also used : Path(java.nio.file.Path) V22ManifestTemplate(com.google.cloud.tools.jib.image.json.V22ManifestTemplate) V22ManifestListTemplate(com.google.cloud.tools.jib.image.json.V22ManifestListTemplate) ImageReference(com.google.cloud.tools.jib.api.ImageReference) ContainerConfigurationTemplate(com.google.cloud.tools.jib.image.json.ContainerConfigurationTemplate) ManifestDescriptorTemplate(com.google.cloud.tools.jib.image.json.V22ManifestListTemplate.ManifestDescriptorTemplate) ManifestAndConfigTemplate(com.google.cloud.tools.jib.image.json.ManifestAndConfigTemplate) ImageMetadataTemplate(com.google.cloud.tools.jib.image.json.ImageMetadataTemplate) Test(org.junit.Test)

Example 8 with ManifestDescriptorTemplate

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

the class PushImageStepTest method setUp.

@Before
public void setUp() {
    when(buildContext.getAllTargetImageTags()).thenReturn(ImmutableSet.of("tag1", "tag2"));
    when(buildContext.getEventHandlers()).thenReturn(EventHandlers.NONE);
    when(buildContext.getContainerConfiguration()).thenReturn(containerConfig);
    doReturn(V22ManifestTemplate.class).when(buildContext).getTargetFormat();
    when(containerConfig.getPlatforms()).thenReturn(ImmutableSet.of(new Platform("amd64", "linux"), new Platform("arm64", "windows")));
    when(progressDispatcherFactory.create(anyString(), anyLong())).thenReturn(progressDispatcher);
    when(progressDispatcher.newChildProducer()).thenReturn(progressDispatcherFactory);
    ManifestDescriptorTemplate manifest = new ManifestDescriptorTemplate();
    manifest.setSize(100);
    manifest.setDigest("sha256:1f25787aab4669d252bdae09a72b9c345d2a7b8c64c8dbfba4c82af4834dbccc");
    manifestList.addManifest(manifest);
}
Also used : Platform(com.google.cloud.tools.jib.api.buildplan.Platform) ManifestDescriptorTemplate(com.google.cloud.tools.jib.image.json.V22ManifestListTemplate.ManifestDescriptorTemplate) Before(org.junit.Before)

Example 9 with ManifestDescriptorTemplate

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

the class ManifestListGenerator method getManifestListTemplate.

/**
 * Generates a manifest list JSON for the given {@link Image}s.
 *
 * @param <T> child type of {@link BuildableManifestTemplate}
 * @param manifestTemplateClass the JSON template to translate the image to
 * @return a manifest list JSON
 * @throws IOException if generating a manifest list fails due to an I/O error when computing
 *     digests
 */
public <T extends BuildableManifestTemplate> ManifestTemplate getManifestListTemplate(Class<T> manifestTemplateClass) throws IOException {
    Preconditions.checkArgument(manifestTemplateClass == V22ManifestTemplate.class, "Build an OCI image index is not yet supported");
    Preconditions.checkState(!images.isEmpty(), "no images given");
    V22ManifestListTemplate manifestList = new V22ManifestListTemplate();
    for (Image image : images) {
        ImageToJsonTranslator imageTranslator = new ImageToJsonTranslator(image);
        BlobDescriptor configDescriptor = Digests.computeDigest(imageTranslator.getContainerConfiguration());
        BuildableManifestTemplate manifestTemplate = imageTranslator.getManifestTemplate(manifestTemplateClass, configDescriptor);
        BlobDescriptor manifestDescriptor = Digests.computeDigest(manifestTemplate);
        ManifestDescriptorTemplate manifest = new ManifestDescriptorTemplate();
        manifest.setMediaType(manifestTemplate.getManifestMediaType());
        manifest.setSize(manifestDescriptor.getSize());
        manifest.setDigest(manifestDescriptor.getDigest().toString());
        manifest.setPlatform(image.getArchitecture(), image.getOs());
        manifestList.addManifest(manifest);
    }
    return manifestList;
}
Also used : BlobDescriptor(com.google.cloud.tools.jib.blob.BlobDescriptor) ManifestDescriptorTemplate(com.google.cloud.tools.jib.image.json.V22ManifestListTemplate.ManifestDescriptorTemplate) Image(com.google.cloud.tools.jib.image.Image)

Example 10 with ManifestDescriptorTemplate

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

the class V22ManifestListTemplateTest method testFromJson.

@Test
public void testFromJson() throws IOException, URISyntaxException {
    Path jsonFile = Paths.get(Resources.getResource("core/json/v22manifest_list.json").toURI());
    V22ManifestListTemplate manifestListJson = JsonTemplateMapper.readJsonFromFile(jsonFile, V22ManifestListTemplate.class);
    Assert.assertEquals(2, manifestListJson.getSchemaVersion());
    List<ManifestDescriptorTemplate> manifests = manifestListJson.getManifests();
    Assert.assertEquals(3, manifests.size());
    List<String> validPlatformPpc = manifestListJson.getDigestsForPlatform("ppc64le", "linux");
    Assert.assertEquals(1, validPlatformPpc.size());
    Assert.assertEquals("sha256:e692418e4cbaf90ca69d05a66403747baa33ee08806650b51fab815ad7fc331f", validPlatformPpc.get(0));
    List<String> validPlatformAmd = manifestListJson.getDigestsForPlatform("amd64", "linux");
    Assert.assertEquals(2, validPlatformAmd.size());
    Assert.assertEquals("sha256:5b0bcabd1ed22e9fb1310cf6c2dec7cdef19f0ad69efa1f392e94a4333501270", validPlatformAmd.get(0));
    Assert.assertEquals("sha256:cccbcabd1ed22e9fb1310cf6c2dec7cdef19f0ad69efa1f392e94a4333501999", validPlatformAmd.get(1));
    List<String> invalidArch = manifestListJson.getDigestsForPlatform("amd72", "linux");
    Assert.assertEquals(0, invalidArch.size());
    List<String> invalidOs = manifestListJson.getDigestsForPlatform("amd64", "minix");
    Assert.assertEquals(0, invalidOs.size());
}
Also used : Path(java.nio.file.Path) ManifestDescriptorTemplate(com.google.cloud.tools.jib.image.json.V22ManifestListTemplate.ManifestDescriptorTemplate) Test(org.junit.Test)

Aggregations

ManifestDescriptorTemplate (com.google.cloud.tools.jib.image.json.V22ManifestListTemplate.ManifestDescriptorTemplate)10 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 V22ManifestListTemplate (com.google.cloud.tools.jib.image.json.V22ManifestListTemplate)4 V22ManifestTemplate (com.google.cloud.tools.jib.image.json.V22ManifestTemplate)4 Path (java.nio.file.Path)4 ImageReference (com.google.cloud.tools.jib.api.ImageReference)2 Platform (com.google.cloud.tools.jib.api.buildplan.Platform)2 BlobDescriptor (com.google.cloud.tools.jib.blob.BlobDescriptor)2 Image (com.google.cloud.tools.jib.image.Image)2 ContainerConfigurationTemplate (com.google.cloud.tools.jib.image.json.ContainerConfigurationTemplate)2 Before (org.junit.Before)2