use of com.google.cloud.tools.jib.image.DescriptorDigest in project jib by google.
the class BlobPullerIntegrationTest method testPull.
@Test
public void testPull() throws IOException, RegistryException {
// Pulls the busybox image.
RegistryClient registryClient = new RegistryClient(null, "localhost:5000", "busybox");
V21ManifestTemplate manifestTemplate = registryClient.pullManifest("latest", V21ManifestTemplate.class);
DescriptorDigest realDigest = manifestTemplate.getLayerDigests().get(0);
// Pulls a layer BLOB of the busybox image.
CountingDigestOutputStream layerOutputStream = new CountingDigestOutputStream(ByteStreams.nullOutputStream());
registryClient.pullBlob(realDigest, layerOutputStream);
Assert.assertEquals(realDigest, layerOutputStream.toBlobDescriptor().getDigest());
}
use of com.google.cloud.tools.jib.image.DescriptorDigest in project jib by google.
the class ImageToJsonTranslator method getManifestTemplate.
/**
* Gets the manifest as a JSON template. The {@code containerConfigurationBlobDescriptor} must be
* the [@link BlobDescriptor} obtained by writing out the container configuration {@link Blob}
* returned from {@link #getContainerConfigurationBlob()}.
*/
public <T extends BuildableManifestTemplate> T getManifestTemplate(Class<T> manifestTemplateClass, BlobDescriptor containerConfigurationBlobDescriptor) throws LayerPropertyNotFoundException {
try {
// Set up the JSON template.
T template = manifestTemplateClass.getDeclaredConstructor().newInstance();
// Adds the container configuration reference.
DescriptorDigest containerConfigurationDigest = containerConfigurationBlobDescriptor.getDigest();
long containerConfigurationSize = containerConfigurationBlobDescriptor.getSize();
template.setContainerConfiguration(containerConfigurationSize, containerConfigurationDigest);
// Adds the layers.
for (Layer layer : image.getLayers()) {
template.addLayer(layer.getBlobDescriptor().getSize(), layer.getBlobDescriptor().getDigest());
}
// Serializes into JSON.
return template;
} catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException ex) {
throw new IllegalArgumentException(manifestTemplateClass + " cannot be instantiated", ex);
}
}
use of com.google.cloud.tools.jib.image.DescriptorDigest in project jib by google.
the class BlobCheckerIntegrationTest method testCheck_doesNotExist.
@Test
public void testCheck_doesNotExist() throws IOException, RegistryException, DigestException {
RegistryClient registryClient = new RegistryClient(null, "localhost:5000", "busybox");
DescriptorDigest fakeBlobDigest = DescriptorDigest.fromHash("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
Assert.assertEquals(null, registryClient.checkBlob(fakeBlobDigest));
}
use of com.google.cloud.tools.jib.image.DescriptorDigest in project jib by google.
the class CountingDigestOutputStream method toBlobDescriptor.
/**
* Builds a {@link BlobDescriptor} with the hash and size of the bytes written.
*/
public BlobDescriptor toBlobDescriptor() {
try {
byte[] hashedBytes = digest.digest();
// Encodes each hashed byte into 2-character hexadecimal representation.
StringBuilder stringBuilder = new StringBuilder(2 * hashedBytes.length);
for (byte b : hashedBytes) {
stringBuilder.append(String.format("%02x", b));
}
String hash = stringBuilder.toString();
DescriptorDigest digest = DescriptorDigest.fromHash(hash);
return new BlobDescriptor(totalBytes, digest);
} catch (DigestException ex) {
throw new RuntimeException("SHA-256 algorithm produced invalid hash: " + ex.getMessage(), ex);
}
}
Aggregations