use of com.google.cloud.tools.jib.image.json.V22ManifestListTemplate in project jib by GoogleContainerTools.
the class ManifestPullerIntegrationTest method testPull_v22ManifestList.
@Test
public void testPull_v22ManifestList() throws IOException, RegistryException {
RegistryClient registryClient = RegistryClient.factory(EventHandlers.NONE, "gcr.io", "distroless/base", httpClient).newRegistryClient();
// Ensure ":latest" is a manifest list
V22ManifestListTemplate manifestListTargeted = registryClient.pullManifest("latest", V22ManifestListTemplate.class).getManifest();
Assert.assertEquals(2, manifestListTargeted.getSchemaVersion());
Assert.assertTrue(manifestListTargeted.getManifests().size() > 0);
// Generic call to ":latest" pulls a manifest list
ManifestTemplate manifestListGeneric = registryClient.pullManifest("latest").getManifest();
Assert.assertEquals(2, manifestListGeneric.getSchemaVersion());
MatcherAssert.assertThat(manifestListGeneric, CoreMatchers.instanceOf(V22ManifestListTemplate.class));
Assert.assertTrue(((V22ManifestListTemplate) manifestListGeneric).getManifests().size() > 0);
// Referencing a manifest list by sha256, should return a manifest list
ManifestTemplate manifestListSha256 = registryClient.pullManifest(KNOWN_MANIFEST_LIST_SHA).getManifest();
Assert.assertEquals(2, manifestListSha256.getSchemaVersion());
MatcherAssert.assertThat(manifestListSha256, CoreMatchers.instanceOf(V22ManifestListTemplate.class));
Assert.assertTrue(((V22ManifestListTemplate) manifestListSha256).getManifests().size() > 0);
// Call to ":latest" targeting a manifest pulls a manifest.
V22ManifestTemplate manifestTargeted = registryClient.pullManifest("latest", V22ManifestTemplate.class).getManifest();
Assert.assertEquals(2, manifestTargeted.getSchemaVersion());
}
use of com.google.cloud.tools.jib.image.json.V22ManifestListTemplate in project jib by GoogleContainerTools.
the class PullBaseImageStepTest method testGetCachedBaseImages_v22ManifestListCached_onlyPlatforms.
@Test
public void testGetCachedBaseImages_v22ManifestListCached_onlyPlatforms() throws InvalidImageReferenceException, IOException, CacheCorruptedException, UnlistedPlatformInManifestListException, BadContainerConfigurationFormatException, LayerCountMismatchException {
ImageReference imageReference = ImageReference.parse("cat");
Mockito.when(buildContext.getBaseImageConfiguration()).thenReturn(ImageConfiguration.builder(imageReference).build());
V22ManifestListTemplate manifestList = Mockito.mock(V22ManifestListTemplate.class);
Mockito.when(manifestList.getDigestsForPlatform("target-arch", "target-os")).thenReturn(Arrays.asList("sha256:target-digest"));
ContainerConfigurationTemplate containerConfigJson = new ContainerConfigurationTemplate();
containerConfigJson.setContainerUser("target-user");
ManifestAndConfigTemplate targetManifestAndConfig = new ManifestAndConfigTemplate(new V22ManifestTemplate(), containerConfigJson, "sha256:target-digest");
ManifestAndConfigTemplate unrelatedManifestAndConfig = new ManifestAndConfigTemplate(new V22ManifestTemplate(), new ContainerConfigurationTemplate(), "sha256:unrelated-digest");
ImageMetadataTemplate imageMetadata = new ImageMetadataTemplate(manifestList, Arrays.asList(unrelatedManifestAndConfig, targetManifestAndConfig, unrelatedManifestAndConfig));
Mockito.when(cache.retrieveMetadata(imageReference)).thenReturn(Optional.of(imageMetadata));
Mockito.when(containerConfig.getPlatforms()).thenReturn(ImmutableSet.of(new Platform("target-arch", "target-os")));
List<Image> images = pullBaseImageStep.getCachedBaseImages();
Assert.assertEquals(1, images.size());
Assert.assertEquals("target-user", images.get(0).getUser());
}
use of com.google.cloud.tools.jib.image.json.V22ManifestListTemplate in project jib by GoogleContainerTools.
the class PullBaseImageStepTest method testGetCachedBaseImages_v22ManifestListCached_partialMatches.
@Test
public void testGetCachedBaseImages_v22ManifestListCached_partialMatches() throws InvalidImageReferenceException, IOException, CacheCorruptedException, UnlistedPlatformInManifestListException, BadContainerConfigurationFormatException, LayerCountMismatchException {
ImageReference imageReference = ImageReference.parse("cat");
Mockito.when(buildContext.getBaseImageConfiguration()).thenReturn(ImageConfiguration.builder(imageReference).build());
V22ManifestListTemplate manifestList = Mockito.mock(V22ManifestListTemplate.class);
Mockito.when(manifestList.getDigestsForPlatform("arch1", "os1")).thenReturn(Arrays.asList("sha256:digest1"));
Mockito.when(manifestList.getDigestsForPlatform("arch2", "os2")).thenReturn(Arrays.asList("sha256:digest2"));
ImageMetadataTemplate imageMetadata = new ImageMetadataTemplate(manifestList, Arrays.asList(new ManifestAndConfigTemplate(new V22ManifestTemplate(), new ContainerConfigurationTemplate(), "sha256:digest1")));
Mockito.when(cache.retrieveMetadata(imageReference)).thenReturn(Optional.of(imageMetadata));
Mockito.when(containerConfig.getPlatforms()).thenReturn(ImmutableSet.of(new Platform("arch1", "os1"), new Platform("arch2", "os2")));
Assert.assertEquals(Arrays.asList(), pullBaseImageStep.getCachedBaseImages());
}
use of com.google.cloud.tools.jib.image.json.V22ManifestListTemplate in project jib by GoogleContainerTools.
the class PullBaseImageStepTest method testGetCachedBaseImages_v22ManifestListCached.
@Test
public void testGetCachedBaseImages_v22ManifestListCached() throws InvalidImageReferenceException, IOException, CacheCorruptedException, UnlistedPlatformInManifestListException, BadContainerConfigurationFormatException, LayerCountMismatchException {
ImageReference imageReference = ImageReference.parse("cat");
Mockito.when(buildContext.getBaseImageConfiguration()).thenReturn(ImageConfiguration.builder(imageReference).build());
ContainerConfigurationTemplate containerConfigJson1 = new ContainerConfigurationTemplate();
ContainerConfigurationTemplate containerConfigJson2 = new ContainerConfigurationTemplate();
containerConfigJson1.setContainerUser("user1");
containerConfigJson2.setContainerUser("user2");
V22ManifestListTemplate manifestList = Mockito.mock(V22ManifestListTemplate.class);
Mockito.when(manifestList.getDigestsForPlatform("arch1", "os1")).thenReturn(Arrays.asList("sha256:digest1"));
Mockito.when(manifestList.getDigestsForPlatform("arch2", "os2")).thenReturn(Arrays.asList("sha256:digest2"));
ImageMetadataTemplate imageMetadata = new ImageMetadataTemplate(manifestList, Arrays.asList(new ManifestAndConfigTemplate(new V22ManifestTemplate(), containerConfigJson1, "sha256:digest1"), new ManifestAndConfigTemplate(new V22ManifestTemplate(), containerConfigJson2, "sha256:digest2")));
Mockito.when(cache.retrieveMetadata(imageReference)).thenReturn(Optional.of(imageMetadata));
Mockito.when(containerConfig.getPlatforms()).thenReturn(ImmutableSet.of(new Platform("arch1", "os1"), new Platform("arch2", "os2")));
List<Image> images = pullBaseImageStep.getCachedBaseImages();
Assert.assertEquals(2, images.size());
Assert.assertEquals("user1", images.get(0).getUser());
Assert.assertEquals("user2", images.get(1).getUser());
}
use of com.google.cloud.tools.jib.image.json.V22ManifestListTemplate in project jib by GoogleContainerTools.
the class CacheStorageReaderTest method testVerifyImageMetadata_schema1ManifestsCorrupted_manifestListExists.
@Test
public void testVerifyImageMetadata_schema1ManifestsCorrupted_manifestListExists() {
ManifestAndConfigTemplate manifestAndConfig = new ManifestAndConfigTemplate(new V21ManifestTemplate(), null);
ImageMetadataTemplate metadata = new ImageMetadataTemplate(new V22ManifestListTemplate(), 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"));
}
}
Aggregations