Search in sources :

Example 36 with V22ManifestListTemplate

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

the class PullBaseImageStepTest method testLookUpPlatformSpecificImageManifest.

@Test
public void testLookUpPlatformSpecificImageManifest() throws IOException, UnlistedPlatformInManifestListException {
    String manifestListJson = " {\n" + "   \"schemaVersion\": 2,\n" + "   \"mediaType\": \"application/vnd.docker.distribution.manifest.list.v2+json\",\n" + "   \"manifests\": [\n" + "      {\n" + "         \"mediaType\": \"application/vnd.docker.distribution.manifest.v2+json\",\n" + "         \"size\": 424,\n" + "         \"digest\": \"sha256:1111111111111111111111111111111111111111111111111111111111111111\",\n" + "         \"platform\": {\n" + "            \"architecture\": \"arm64\",\n" + "            \"os\": \"linux\"\n" + "         }\n" + "      },\n" + "      {\n" + "         \"mediaType\": \"application/vnd.docker.distribution.manifest.v2+json\",\n" + "         \"size\": 425,\n" + "         \"digest\": \"sha256:2222222222222222222222222222222222222222222222222222222222222222\",\n" + "         \"platform\": {\n" + "            \"architecture\": \"targetArchitecture\",\n" + "            \"os\": \"targetOS\"\n" + "         }\n" + "      }\n" + "   ]\n" + "}";
    V22ManifestListTemplate manifestList = JsonTemplateMapper.readJson(manifestListJson, V22ManifestListTemplate.class);
    String manifestDigest = pullBaseImageStep.lookUpPlatformSpecificImageManifest(manifestList, new Platform("targetArchitecture", "targetOS"));
    Assert.assertEquals("sha256:2222222222222222222222222222222222222222222222222222222222222222", manifestDigest);
}
Also used : V22ManifestListTemplate(com.google.cloud.tools.jib.image.json.V22ManifestListTemplate) Platform(com.google.cloud.tools.jib.api.buildplan.Platform) Test(org.junit.Test)

Example 37 with V22ManifestListTemplate

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

the class ManifestPullerTest method testHandleResponse_v22ManifestList.

@Test
public void testHandleResponse_v22ManifestList() throws URISyntaxException, IOException, UnknownManifestFormatException {
    Path v22ManifestListFile = Paths.get(Resources.getResource("core/json/v22manifest_list.json").toURI());
    InputStream v22ManifestList = new ByteArrayInputStream(Files.readAllBytes(v22ManifestListFile));
    DescriptorDigest expectedDigest = Digests.computeDigest(v22ManifestList).getDigest();
    v22ManifestList.reset();
    Mockito.when(mockResponse.getBody()).thenReturn(v22ManifestList);
    ManifestAndDigest<V22ManifestListTemplate> manifestAndDigest = new ManifestPuller<>(fakeRegistryEndpointRequestProperties, "test-image-tag", V22ManifestListTemplate.class).handleResponse(mockResponse);
    V22ManifestListTemplate manifestTemplate = manifestAndDigest.getManifest();
    MatcherAssert.assertThat(manifestTemplate, CoreMatchers.instanceOf(V22ManifestListTemplate.class));
    Assert.assertTrue(manifestTemplate.getManifests().size() > 0);
    Assert.assertEquals(expectedDigest, manifestAndDigest.getDigest());
}
Also used : Path(java.nio.file.Path) V22ManifestListTemplate(com.google.cloud.tools.jib.image.json.V22ManifestListTemplate) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) DescriptorDigest(com.google.cloud.tools.jib.api.DescriptorDigest) Test(org.junit.Test)

Example 38 with V22ManifestListTemplate

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

the class RegistryClientTest method testPullManifest_manifestList.

@Test
public void testPullManifest_manifestList() throws IOException, InterruptedException, GeneralSecurityException, URISyntaxException, RegistryException {
    String manifestResponse = "HTTP/1.1 200 OK\nContent-Length: 403\n\n{\n" + "  \"schemaVersion\": 2,\n" + "  \"mediaType\": \"application/vnd.docker.distribution.manifest.list.v2+json\",\n" + "  \"manifests\": [\n" + "    {\n" + "      \"mediaType\": \"application/vnd.docker.distribution.manifest.v2+json\",\n" + "      \"size\": 7143,\n" + "      \"digest\": \"sha256:e692418e4cbaf90ca69d05a66403747baa33ee08806650b51fab815ad7fc331f\",\n" + "      \"platform\": {\n" + "        \"architecture\": \"amd64\",\n" + "        \"os\": \"linux\"\n" + "      }\n" + "    }\n" + "  ]\n" + "}";
    registry = new TestWebServer(false, Arrays.asList(manifestResponse), 1);
    RegistryClient registryClient = createRegistryClient(null);
    ManifestAndDigest<?> manifestAndDigest = registryClient.pullManifest("image-tag");
    Assert.assertEquals("sha256:a340fa38667f765f8cfd79d4bc684ec8a6f48cdd63abfe36e109f4125ee38488", manifestAndDigest.getDigest().toString());
    Assert.assertTrue(manifestAndDigest.getManifest() instanceof V22ManifestListTemplate);
    V22ManifestListTemplate manifestList = (V22ManifestListTemplate) manifestAndDigest.getManifest();
    Assert.assertEquals(2, manifestList.getSchemaVersion());
    Assert.assertEquals(Arrays.asList("sha256:e692418e4cbaf90ca69d05a66403747baa33ee08806650b51fab815ad7fc331f"), manifestList.getDigestsForPlatform("amd64", "linux"));
    MatcherAssert.assertThat(registry.getInputRead(), CoreMatchers.containsString("GET /v2/foo/bar/manifests/image-tag "));
}
Also used : V22ManifestListTemplate(com.google.cloud.tools.jib.image.json.V22ManifestListTemplate) TestWebServer(com.google.cloud.tools.jib.http.TestWebServer) Test(org.junit.Test)

Aggregations

V22ManifestListTemplate (com.google.cloud.tools.jib.image.json.V22ManifestListTemplate)38 Test (org.junit.Test)34 ImageMetadataTemplate (com.google.cloud.tools.jib.image.json.ImageMetadataTemplate)22 ManifestAndConfigTemplate (com.google.cloud.tools.jib.image.json.ManifestAndConfigTemplate)22 V22ManifestTemplate (com.google.cloud.tools.jib.image.json.V22ManifestTemplate)22 ContainerConfigurationTemplate (com.google.cloud.tools.jib.image.json.ContainerConfigurationTemplate)18 Platform (com.google.cloud.tools.jib.api.buildplan.Platform)14 ManifestTemplate (com.google.cloud.tools.jib.image.json.ManifestTemplate)12 ImageReference (com.google.cloud.tools.jib.api.ImageReference)10 V21ManifestTemplate (com.google.cloud.tools.jib.image.json.V21ManifestTemplate)10 Image (com.google.cloud.tools.jib.image.Image)8 ManifestDescriptorTemplate (com.google.cloud.tools.jib.image.json.V22ManifestListTemplate.ManifestDescriptorTemplate)8 DescriptorDigest (com.google.cloud.tools.jib.api.DescriptorDigest)6 Path (java.nio.file.Path)6 ProgressEventDispatcher (com.google.cloud.tools.jib.builder.ProgressEventDispatcher)4 Cache (com.google.cloud.tools.jib.cache.Cache)4 ImageConfiguration (com.google.cloud.tools.jib.configuration.ImageConfiguration)4 EventHandlers (com.google.cloud.tools.jib.event.EventHandlers)4 BuildableManifestTemplate (com.google.cloud.tools.jib.image.json.BuildableManifestTemplate)4 RegistryClient (com.google.cloud.tools.jib.registry.RegistryClient)4