Search in sources :

Example 16 with DescriptorDigest

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());
}
Also used : CountingDigestOutputStream(com.google.cloud.tools.jib.hash.CountingDigestOutputStream) DescriptorDigest(com.google.cloud.tools.jib.image.DescriptorDigest) V21ManifestTemplate(com.google.cloud.tools.jib.image.json.V21ManifestTemplate) Test(org.junit.Test)

Example 17 with DescriptorDigest

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);
    }
}
Also used : DescriptorDigest(com.google.cloud.tools.jib.image.DescriptorDigest) Layer(com.google.cloud.tools.jib.image.Layer) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 18 with DescriptorDigest

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));
}
Also used : DescriptorDigest(com.google.cloud.tools.jib.image.DescriptorDigest) Test(org.junit.Test)

Example 19 with DescriptorDigest

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);
    }
}
Also used : BlobDescriptor(com.google.cloud.tools.jib.blob.BlobDescriptor) DescriptorDigest(com.google.cloud.tools.jib.image.DescriptorDigest) DigestException(java.security.DigestException)

Aggregations

DescriptorDigest (com.google.cloud.tools.jib.image.DescriptorDigest)19 Test (org.junit.Test)9 BlobDescriptor (com.google.cloud.tools.jib.blob.BlobDescriptor)6 Blob (com.google.cloud.tools.jib.blob.Blob)5 CountingDigestOutputStream (com.google.cloud.tools.jib.hash.CountingDigestOutputStream)5 Layer (com.google.cloud.tools.jib.image.Layer)4 Image (com.google.cloud.tools.jib.image.Image)3 ReferenceLayer (com.google.cloud.tools.jib.image.ReferenceLayer)3 Response (com.google.cloud.tools.jib.http.Response)2 DigestOnlyLayer (com.google.cloud.tools.jib.image.DigestOnlyLayer)2 ReferenceNoDiffIdLayer (com.google.cloud.tools.jib.image.ReferenceNoDiffIdLayer)2 V22ManifestTemplate (com.google.cloud.tools.jib.image.json.V22ManifestTemplate)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 OutputStream (java.io.OutputStream)2 Path (java.nio.file.Path)2 GZIPOutputStream (java.util.zip.GZIPOutputStream)2 Timer (com.google.cloud.tools.jib.Timer)1 CachedLayer (com.google.cloud.tools.jib.cache.CachedLayer)1 LayerCountMismatchException (com.google.cloud.tools.jib.image.LayerCountMismatchException)1 UnwrittenLayer (com.google.cloud.tools.jib.image.UnwrittenLayer)1