Search in sources :

Example 6 with CachedLayer

use of com.google.cloud.tools.jib.cache.CachedLayer in project jib by google.

the class PushImageStep method afterPushBaseImageLayerFuturesFuture.

/**
 * Depends on {@code pushAuthorizationFuture}, {@code pushBaseImageLayerFuturesFuture.get()},
 * {@code pushApplicationLayerFutures}, and (@code
 * containerConfigurationBlobDescriptorFutureFuture.get()}.
 */
private Void afterPushBaseImageLayerFuturesFuture() throws IOException, RegistryException, ExecutionException, InterruptedException, LayerPropertyNotFoundException {
    try (Timer ignored = new Timer(buildConfiguration.getBuildLogger(), DESCRIPTION)) {
        RegistryClient registryClient = new RegistryClient(NonBlockingFutures.get(pushAuthorizationFuture), buildConfiguration.getTargetRegistry(), buildConfiguration.getTargetRepository());
        // TODO: Consolidate with BuildAndPushContainerConfigurationStep.
        // 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));
        }
        ImageToJsonTranslator imageToJsonTranslator = new ImageToJsonTranslator(image);
        // Pushes the image manifest.
        BuildableManifestTemplate manifestTemplate = imageToJsonTranslator.getManifestTemplate(buildConfiguration.getTargetFormat(), NonBlockingFutures.get(NonBlockingFutures.get(containerConfigurationBlobDescriptorFutureFuture)));
        registryClient.pushManifest(manifestTemplate, buildConfiguration.getTargetTag());
    }
    return null;
}
Also used : 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) BuildableManifestTemplate(com.google.cloud.tools.jib.image.json.BuildableManifestTemplate)

Example 7 with CachedLayer

use of com.google.cloud.tools.jib.cache.CachedLayer 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

CachedLayer (com.google.cloud.tools.jib.cache.CachedLayer)7 Timer (com.google.cloud.tools.jib.Timer)6 RegistryClient (com.google.cloud.tools.jib.registry.RegistryClient)4 CacheReader (com.google.cloud.tools.jib.cache.CacheReader)3 Image (com.google.cloud.tools.jib.image.Image)3 Cache (com.google.cloud.tools.jib.cache.Cache)2 CacheWriter (com.google.cloud.tools.jib.cache.CacheWriter)2 ImageToJsonTranslator (com.google.cloud.tools.jib.image.json.ImageToJsonTranslator)2 Blob (com.google.cloud.tools.jib.blob.Blob)1 BlobDescriptor (com.google.cloud.tools.jib.blob.BlobDescriptor)1 Caches (com.google.cloud.tools.jib.cache.Caches)1 CountingDigestOutputStream (com.google.cloud.tools.jib.hash.CountingDigestOutputStream)1 Authorization (com.google.cloud.tools.jib.http.Authorization)1 DescriptorDigest (com.google.cloud.tools.jib.image.DescriptorDigest)1 ImageLayers (com.google.cloud.tools.jib.image.ImageLayers)1 LayerBuilder (com.google.cloud.tools.jib.image.LayerBuilder)1 BuildableManifestTemplate (com.google.cloud.tools.jib.image.json.BuildableManifestTemplate)1 CountingOutputStream (com.google.common.io.CountingOutputStream)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 ListeningExecutorService (com.google.common.util.concurrent.ListeningExecutorService)1