Search in sources :

Example 11 with Blob

use of com.google.cloud.tools.jib.blob.Blob in project jib by google.

the class TarStreamBuilderTest method testToBlob_withCompression.

@Test
public void testToBlob_withCompression() throws IOException {
    Blob blob = testTarStreamBuilder.toBlob();
    // Writes the BLOB and captures the output.
    ByteArrayOutputStream tarByteOutputStream = new ByteArrayOutputStream();
    OutputStream compressorStream = new GZIPOutputStream(tarByteOutputStream);
    blob.writeTo(compressorStream);
    // Rearrange the output into input for verification.
    ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(tarByteOutputStream.toByteArray());
    InputStream tarByteInputStream = new GZIPInputStream(byteArrayInputStream);
    TarArchiveInputStream tarArchiveInputStream = new TarArchiveInputStream(tarByteInputStream);
    verifyTarArchive(tarArchiveInputStream);
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) TarArchiveInputStream(org.apache.commons.compress.archivers.tar.TarArchiveInputStream) Blob(com.google.cloud.tools.jib.blob.Blob) GZIPOutputStream(java.util.zip.GZIPOutputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) GZIPInputStream(java.util.zip.GZIPInputStream) TarArchiveInputStream(org.apache.commons.compress.archivers.tar.TarArchiveInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) GZIPOutputStream(java.util.zip.GZIPOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 12 with Blob

use of com.google.cloud.tools.jib.blob.Blob in project jib by google.

the class CacheWriterTest method getExpectedLayer.

/**
 * @return the expected layer to test against, represented by the {@code resourceBlob} resource
 *     file
 */
private ExpectedLayer getExpectedLayer() throws IOException {
    String expectedBlobAString = new String(Files.readAllBytes(resourceBlob), StandardCharsets.UTF_8);
    // Gets the expected content descriptor, diff ID, and compressed BLOB.
    ByteArrayOutputStream compressedBlobOutputStream = new ByteArrayOutputStream();
    CountingDigestOutputStream compressedDigestOutputStream = new CountingDigestOutputStream(compressedBlobOutputStream);
    CountingDigestOutputStream uncompressedDigestOutputStream;
    try (GZIPOutputStream compressorStream = new GZIPOutputStream(compressedDigestOutputStream)) {
        uncompressedDigestOutputStream = new CountingDigestOutputStream(compressorStream);
        uncompressedDigestOutputStream.write(expectedBlobAString.getBytes(StandardCharsets.UTF_8));
    }
    BlobDescriptor expectedBlobADescriptor = compressedDigestOutputStream.toBlobDescriptor();
    DescriptorDigest expectedBlobADiffId = uncompressedDigestOutputStream.toBlobDescriptor().getDigest();
    ByteArrayInputStream compressedBlobInputStream = new ByteArrayInputStream(compressedBlobOutputStream.toByteArray());
    Blob blob = Blobs.from(compressedBlobInputStream);
    return new ExpectedLayer(expectedBlobADescriptor, expectedBlobADiffId, blob);
}
Also used : CountingDigestOutputStream(com.google.cloud.tools.jib.hash.CountingDigestOutputStream) BlobDescriptor(com.google.cloud.tools.jib.blob.BlobDescriptor) Blob(com.google.cloud.tools.jib.blob.Blob) GZIPOutputStream(java.util.zip.GZIPOutputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) DescriptorDigest(com.google.cloud.tools.jib.image.DescriptorDigest) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 13 with Blob

use of com.google.cloud.tools.jib.blob.Blob in project jib by google.

the class BuildAndPushContainerConfigurationStep method afterBaseImageLayerFuturesFuture.

/**
 * Depends on {@code pushAuthorizationFuture}, {@code pullBaseImageLayerFuturesFuture.get()}, and
 * {@code buildApplicationLayerFutures}.
 */
private BlobDescriptor afterBaseImageLayerFuturesFuture() throws ExecutionException, InterruptedException, LayerPropertyNotFoundException, IOException, RegistryException {
    try (Timer timer = new Timer(buildConfiguration.getBuildLogger(), DESCRIPTION)) {
        RegistryClient registryClient = new RegistryClient(NonBlockingFutures.get(pushAuthorizationFuture), buildConfiguration.getTargetRegistry(), buildConfiguration.getTargetRepository()).setTimer(timer);
        // Constructs the image.
        Image image = new Image();
        for (Future<CachedLayer> cachedLayerFuture : NonBlockingFutures.get(pullBaseImageLayerFuturesFuture)) {
            image.addLayer(NonBlockingFutures.get(cachedLayerFuture));
        }
        for (Future<CachedLayer> cachedLayerFuture : buildApplicationLayerFutures) {
            image.addLayer(NonBlockingFutures.get(cachedLayerFuture));
        }
        image.setEnvironment(buildConfiguration.getEnvironment());
        image.setEntrypoint(entrypoint);
        ImageToJsonTranslator imageToJsonTranslator = new ImageToJsonTranslator(image);
        // Gets the container configuration content descriptor.
        Blob containerConfigurationBlob = imageToJsonTranslator.getContainerConfigurationBlob();
        CountingDigestOutputStream digestOutputStream = new CountingDigestOutputStream(ByteStreams.nullOutputStream());
        containerConfigurationBlob.writeTo(digestOutputStream);
        BlobDescriptor containerConfigurationBlobDescriptor = digestOutputStream.toBlobDescriptor();
        timer.lap("Pushing container configuration " + containerConfigurationBlobDescriptor.getDigest());
        // TODO: Use PushBlobStep.
        // Pushes the container configuration.
        registryClient.pushBlob(containerConfigurationBlobDescriptor.getDigest(), containerConfigurationBlob);
        return containerConfigurationBlobDescriptor;
    }
}
Also used : CountingDigestOutputStream(com.google.cloud.tools.jib.hash.CountingDigestOutputStream) Blob(com.google.cloud.tools.jib.blob.Blob) BlobDescriptor(com.google.cloud.tools.jib.blob.BlobDescriptor) Timer(com.google.cloud.tools.jib.Timer) ImageToJsonTranslator(com.google.cloud.tools.jib.image.json.ImageToJsonTranslator) CachedLayer(com.google.cloud.tools.jib.cache.CachedLayer) RegistryClient(com.google.cloud.tools.jib.registry.RegistryClient) Image(com.google.cloud.tools.jib.image.Image)

Aggregations

Blob (com.google.cloud.tools.jib.blob.Blob)13 Test (org.junit.Test)10 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 DescriptorDigest (com.google.cloud.tools.jib.image.DescriptorDigest)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 Path (java.nio.file.Path)4 BlobDescriptor (com.google.cloud.tools.jib.blob.BlobDescriptor)3 CountingDigestOutputStream (com.google.cloud.tools.jib.hash.CountingDigestOutputStream)2 Response (com.google.cloud.tools.jib.http.Response)2 GZIPOutputStream (java.util.zip.GZIPOutputStream)2 TarArchiveInputStream (org.apache.commons.compress.archivers.tar.TarArchiveInputStream)2 HttpResponse (com.google.api.client.http.HttpResponse)1 Timer (com.google.cloud.tools.jib.Timer)1 CachedLayer (com.google.cloud.tools.jib.cache.CachedLayer)1 Image (com.google.cloud.tools.jib.image.Image)1 ImageToJsonTranslator (com.google.cloud.tools.jib.image.json.ImageToJsonTranslator)1 V22ManifestTemplate (com.google.cloud.tools.jib.image.json.V22ManifestTemplate)1 RegistryClient (com.google.cloud.tools.jib.registry.RegistryClient)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1