use of com.google.cloud.tools.jib.cache.CacheWriter in project jib by google.
the class PullAndCacheBaseImageLayerStep method call.
/**
* Depends on {@code pullAuthorizationFuture}.
*/
@Override
public CachedLayer call() throws IOException, RegistryException, LayerPropertyNotFoundException, ExecutionException, InterruptedException {
try (Timer ignored = new Timer(buildConfiguration.getBuildLogger(), String.format(DESCRIPTION, layerDigest))) {
RegistryClient registryClient = new RegistryClient(pullAuthorizationFuture.get(), buildConfiguration.getBaseImageRegistry(), buildConfiguration.getBaseImageRepository());
// Checks if the layer already exists in the cache.
CachedLayer cachedLayer = new CacheReader(cache).getLayer(layerDigest);
if (cachedLayer != null) {
return cachedLayer;
}
CacheWriter cacheWriter = new CacheWriter(cache);
CountingOutputStream layerOutputStream = cacheWriter.getLayerOutputStream(layerDigest);
registryClient.pullBlob(layerDigest, layerOutputStream);
return cacheWriter.getCachedLayer(layerDigest, layerOutputStream);
}
}
use of com.google.cloud.tools.jib.cache.CacheWriter in project jib by google.
the class BuildAndCacheApplicationLayersStep method buildAndCacheLayerAsync.
private ListenableFuture<CachedLayer> buildAndCacheLayerAsync(String layerType, List<Path> sourceFiles, String extractionPath) {
String description = "Building " + layerType + " layer";
return listeningExecutorService.submit(() -> {
try (Timer ignored = new Timer(buildConfiguration.getBuildLogger(), description)) {
// Don't build the layer if it exists already.
CachedLayer cachedLayer = new CacheReader(cache).getUpToDateLayerBySourceFiles(sourceFiles);
if (cachedLayer != null) {
return cachedLayer;
}
LayerBuilder layerBuilder = new LayerBuilder(sourceFiles, extractionPath, buildConfiguration.getEnableReproducibleBuilds());
cachedLayer = new CacheWriter(cache).writeLayer(layerBuilder);
// TODO: Remove
buildConfiguration.getBuildLogger().debug(description + " built " + cachedLayer.getBlobDescriptor().getDigest());
return cachedLayer;
}
});
}
Aggregations