Search in sources :

Example 1 with NotifyingOutputStream

use of com.google.cloud.tools.jib.http.NotifyingOutputStream in project jib by GoogleContainerTools.

the class LocalBaseImageSteps method compressAndCacheTarLayer.

private static PreparedLayer compressAndCacheTarLayer(Cache cache, DescriptorDigest diffId, Path layerFile, boolean layersAreCompressed, ProgressEventDispatcher.Factory progressEventDispatcherFactory) throws IOException, CacheCorruptedException {
    try (ProgressEventDispatcher childDispatcher = progressEventDispatcherFactory.create("compressing layer " + diffId, Files.size(layerFile));
        ThrottledAccumulatingConsumer throttledProgressReporter = new ThrottledAccumulatingConsumer(childDispatcher::dispatchProgress)) {
        // Retrieve pre-compressed layer from cache
        Optional<CachedLayer> optionalLayer = cache.retrieveTarLayer(diffId);
        if (optionalLayer.isPresent()) {
            return new PreparedLayer.Builder(optionalLayer.get()).build();
        }
        // Just write layers that are already compressed
        if (layersAreCompressed) {
            return new PreparedLayer.Builder(cache.writeTarLayer(diffId, Blobs.from(layerFile))).build();
        }
        // Compress uncompressed layers while writing
        Blob compressedBlob = Blobs.from(outputStream -> {
            try (GZIPOutputStream compressorStream = new GZIPOutputStream(outputStream);
                NotifyingOutputStream notifyingOutputStream = new NotifyingOutputStream(compressorStream, throttledProgressReporter)) {
                Blobs.from(layerFile).writeTo(notifyingOutputStream);
            }
        }, true);
        return new PreparedLayer.Builder(cache.writeTarLayer(diffId, compressedBlob)).build();
    }
}
Also used : NotifyingOutputStream(com.google.cloud.tools.jib.http.NotifyingOutputStream) Blob(com.google.cloud.tools.jib.blob.Blob) ProgressEventDispatcher(com.google.cloud.tools.jib.builder.ProgressEventDispatcher) GZIPOutputStream(java.util.zip.GZIPOutputStream) CachedLayer(com.google.cloud.tools.jib.cache.CachedLayer) ThrottledAccumulatingConsumer(com.google.cloud.tools.jib.event.progress.ThrottledAccumulatingConsumer)

Example 2 with NotifyingOutputStream

use of com.google.cloud.tools.jib.http.NotifyingOutputStream in project jib by google.

the class LocalBaseImageSteps method compressAndCacheTarLayer.

private static PreparedLayer compressAndCacheTarLayer(Cache cache, DescriptorDigest diffId, Path layerFile, boolean layersAreCompressed, ProgressEventDispatcher.Factory progressEventDispatcherFactory) throws IOException, CacheCorruptedException {
    try (ProgressEventDispatcher childDispatcher = progressEventDispatcherFactory.create("compressing layer " + diffId, Files.size(layerFile));
        ThrottledAccumulatingConsumer throttledProgressReporter = new ThrottledAccumulatingConsumer(childDispatcher::dispatchProgress)) {
        // Retrieve pre-compressed layer from cache
        Optional<CachedLayer> optionalLayer = cache.retrieveTarLayer(diffId);
        if (optionalLayer.isPresent()) {
            return new PreparedLayer.Builder(optionalLayer.get()).build();
        }
        // Just write layers that are already compressed
        if (layersAreCompressed) {
            return new PreparedLayer.Builder(cache.writeTarLayer(diffId, Blobs.from(layerFile))).build();
        }
        // Compress uncompressed layers while writing
        Blob compressedBlob = Blobs.from(outputStream -> {
            try (GZIPOutputStream compressorStream = new GZIPOutputStream(outputStream);
                NotifyingOutputStream notifyingOutputStream = new NotifyingOutputStream(compressorStream, throttledProgressReporter)) {
                Blobs.from(layerFile).writeTo(notifyingOutputStream);
            }
        }, true);
        return new PreparedLayer.Builder(cache.writeTarLayer(diffId, compressedBlob)).build();
    }
}
Also used : NotifyingOutputStream(com.google.cloud.tools.jib.http.NotifyingOutputStream) Blob(com.google.cloud.tools.jib.blob.Blob) ProgressEventDispatcher(com.google.cloud.tools.jib.builder.ProgressEventDispatcher) GZIPOutputStream(java.util.zip.GZIPOutputStream) CachedLayer(com.google.cloud.tools.jib.cache.CachedLayer) ThrottledAccumulatingConsumer(com.google.cloud.tools.jib.event.progress.ThrottledAccumulatingConsumer)

Aggregations

Blob (com.google.cloud.tools.jib.blob.Blob)2 ProgressEventDispatcher (com.google.cloud.tools.jib.builder.ProgressEventDispatcher)2 CachedLayer (com.google.cloud.tools.jib.cache.CachedLayer)2 ThrottledAccumulatingConsumer (com.google.cloud.tools.jib.event.progress.ThrottledAccumulatingConsumer)2 NotifyingOutputStream (com.google.cloud.tools.jib.http.NotifyingOutputStream)2 GZIPOutputStream (java.util.zip.GZIPOutputStream)2