Search in sources :

Example 1 with CacheWriter

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);
    }
}
Also used : CountingOutputStream(com.google.common.io.CountingOutputStream) Timer(com.google.cloud.tools.jib.Timer) CacheWriter(com.google.cloud.tools.jib.cache.CacheWriter) CachedLayer(com.google.cloud.tools.jib.cache.CachedLayer) RegistryClient(com.google.cloud.tools.jib.registry.RegistryClient) CacheReader(com.google.cloud.tools.jib.cache.CacheReader)

Example 2 with CacheWriter

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;
        }
    });
}
Also used : Timer(com.google.cloud.tools.jib.Timer) LayerBuilder(com.google.cloud.tools.jib.image.LayerBuilder) CacheWriter(com.google.cloud.tools.jib.cache.CacheWriter) CachedLayer(com.google.cloud.tools.jib.cache.CachedLayer) CacheReader(com.google.cloud.tools.jib.cache.CacheReader)

Aggregations

Timer (com.google.cloud.tools.jib.Timer)2 CacheReader (com.google.cloud.tools.jib.cache.CacheReader)2 CacheWriter (com.google.cloud.tools.jib.cache.CacheWriter)2 CachedLayer (com.google.cloud.tools.jib.cache.CachedLayer)2 LayerBuilder (com.google.cloud.tools.jib.image.LayerBuilder)1 RegistryClient (com.google.cloud.tools.jib.registry.RegistryClient)1 CountingOutputStream (com.google.common.io.CountingOutputStream)1