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();
}
}
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();
}
}
Aggregations