use of com.google.cloud.tools.jib.api.DescriptorDigest in project jib by GoogleContainerTools.
the class BlobCheckerIntegrationTest method testCheck_exists.
@Test
public void testCheck_exists() throws IOException, RegistryException {
RegistryClient registryClient = RegistryClient.factory(EventHandlers.NONE, "gcr.io", "distroless/base", httpClient).newRegistryClient();
V22ManifestTemplate manifestTemplate = registryClient.pullManifest("latest", V22ManifestTemplate.class).getManifest();
DescriptorDigest blobDigest = manifestTemplate.getLayers().get(0).getDigest();
Assert.assertEquals(blobDigest, registryClient.checkBlob(blobDigest).get().getDigest());
}
use of com.google.cloud.tools.jib.api.DescriptorDigest in project jib by GoogleContainerTools.
the class BlobPullerIntegrationTest method testPull_unknownBlob.
@Test
public void testPull_unknownBlob() throws IOException, DigestException {
DescriptorDigest nonexistentDigest = DescriptorDigest.fromHash("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
RegistryClient registryClient = RegistryClient.factory(EventHandlers.NONE, "gcr.io", "distroless/base", httpClient).newRegistryClient();
try {
registryClient.pullBlob(nonexistentDigest, ignored -> {
}, ignored -> {
}).writeTo(ByteStreams.nullOutputStream());
Assert.fail("Trying to pull nonexistent blob should have errored");
} catch (IOException ex) {
if (!(ex.getCause() instanceof RegistryErrorException)) {
throw ex;
}
MatcherAssert.assertThat(ex.getMessage(), CoreMatchers.containsString("pull BLOB for gcr.io/distroless/base with digest " + nonexistentDigest));
}
}
use of com.google.cloud.tools.jib.api.DescriptorDigest in project jib by GoogleContainerTools.
the class ManifestPusherIntegrationTest method testPush.
/**
* Tests manifest pushing. This test is a comprehensive test of push and pull.
*/
@Test
public void testPush() throws DigestException, IOException, RegistryException {
Blob testLayerBlob = Blobs.from("crepecake");
// Known digest for 'crepecake'
DescriptorDigest testLayerBlobDigest = DescriptorDigest.fromHash("52a9e4d4ba4333ce593707f98564fee1e6d898db0d3602408c0b2a6a424d357c");
Blob testContainerConfigurationBlob = Blobs.from("12345");
DescriptorDigest testContainerConfigurationBlobDigest = DescriptorDigest.fromHash("5994471abb01112afcc18159f6cc74b4f511b99806da59b3caf5a9c173cacfc5");
// Creates a valid image manifest.
V22ManifestTemplate expectedManifestTemplate = new V22ManifestTemplate();
expectedManifestTemplate.addLayer(9, testLayerBlobDigest);
expectedManifestTemplate.setContainerConfiguration(5, testContainerConfigurationBlobDigest);
// Pushes the BLOBs.
RegistryClient registryClient = RegistryClient.factory(EventHandlers.NONE, "localhost:5000", "testimage", httpClient).newRegistryClient();
Assert.assertFalse(registryClient.pushBlob(testLayerBlobDigest, testLayerBlob, null, ignored -> {
}));
Assert.assertFalse(registryClient.pushBlob(testContainerConfigurationBlobDigest, testContainerConfigurationBlob, null, ignored -> {
}));
// Pushes the manifest.
DescriptorDigest imageDigest = registryClient.pushManifest(expectedManifestTemplate, "latest");
// Pulls the manifest.
V22ManifestTemplate manifestTemplate = registryClient.pullManifest("latest", V22ManifestTemplate.class).getManifest();
Assert.assertEquals(1, manifestTemplate.getLayers().size());
Assert.assertEquals(testLayerBlobDigest, manifestTemplate.getLayers().get(0).getDigest());
Assert.assertNotNull(manifestTemplate.getContainerConfiguration());
Assert.assertEquals(testContainerConfigurationBlobDigest, manifestTemplate.getContainerConfiguration().getDigest());
// Pulls the manifest by digest.
V22ManifestTemplate manifestTemplateByDigest = registryClient.pullManifest(imageDigest.toString(), V22ManifestTemplate.class).getManifest();
Assert.assertEquals(Digests.computeJsonDigest(manifestTemplate), Digests.computeJsonDigest(manifestTemplateByDigest));
}
use of com.google.cloud.tools.jib.api.DescriptorDigest in project jib by GoogleContainerTools.
the class ObtainBaseImageLayerStepTest method setUp.
@Before
public void setUp() throws IOException, RegistryException, DigestException {
existingLayerDigest = DescriptorDigest.fromHash("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
freshLayerDigest = DescriptorDigest.fromHash("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb");
DescriptorDigest diffId = Mockito.mock(DescriptorDigest.class);
existingLayer = new ReferenceLayer(new BlobDescriptor(existingLayerDigest), diffId);
freshLayer = new ReferenceLayer(new BlobDescriptor(freshLayerDigest), diffId);
Mockito.when(registryClient.checkBlob(existingLayerDigest)).thenReturn(Optional.of(Mockito.mock(BlobDescriptor.class)));
Mockito.when(registryClient.checkBlob(freshLayerDigest)).thenReturn(Optional.empty());
// necessary to prevent error from classes dealing with progress report
Answer3<Blob, DescriptorDigest, Consumer<Long>, Consumer<Long>> progressSizeSetter = (ignored1, progressSizeConsumer, ignored2) -> {
progressSizeConsumer.accept(Long.valueOf(12345));
return null;
};
Mockito.when(registryClient.pullBlob(Mockito.any(), Mockito.any(), Mockito.any())).thenAnswer(AdditionalAnswers.answer(progressSizeSetter));
}
use of com.google.cloud.tools.jib.api.DescriptorDigest in project jib by GoogleContainerTools.
the class PullBaseImageStepTest method testGetCachedBaseImages_v21ManifestCached.
@Test
public void testGetCachedBaseImages_v21ManifestCached() throws InvalidImageReferenceException, IOException, CacheCorruptedException, UnlistedPlatformInManifestListException, BadContainerConfigurationFormatException, LayerCountMismatchException, DigestException {
ImageReference imageReference = ImageReference.parse("cat");
Mockito.when(buildContext.getBaseImageConfiguration()).thenReturn(ImageConfiguration.builder(imageReference).build());
DescriptorDigest layerDigest = DescriptorDigest.fromHash("1111111111111111111111111111111111111111111111111111111111111111");
V21ManifestTemplate v21Manifest = Mockito.mock(V21ManifestTemplate.class);
Mockito.when(v21Manifest.getLayerDigests()).thenReturn(Arrays.asList(layerDigest));
ImageMetadataTemplate imageMetadata = new ImageMetadataTemplate(null, Arrays.asList(new ManifestAndConfigTemplate(v21Manifest, null)));
Mockito.when(cache.retrieveMetadata(imageReference)).thenReturn(Optional.of(imageMetadata));
List<Image> images = pullBaseImageStep.getCachedBaseImages();
Assert.assertEquals(1, images.size());
Assert.assertEquals(1, images.get(0).getLayers().size());
Assert.assertEquals("1111111111111111111111111111111111111111111111111111111111111111", images.get(0).getLayers().get(0).getBlobDescriptor().getDigest().getHash());
}
Aggregations