Search in sources :

Example 1 with StateInTarget

use of com.google.cloud.tools.jib.builder.steps.PreparedLayer.StateInTarget in project jib by google.

the class ObtainBaseImageLayerStep method call.

@Override
public PreparedLayer call() throws IOException, CacheCorruptedException, RegistryException {
    EventHandlers eventHandlers = buildContext.getEventHandlers();
    DescriptorDigest layerDigest = layer.getBlobDescriptor().getDigest();
    try (ProgressEventDispatcher progressEventDispatcher = progressEventDispatcherFactory.create("checking base image layer " + layerDigest, 1);
        TimerEventDispatcher ignored = new TimerEventDispatcher(eventHandlers, String.format(DESCRIPTION, layerDigest))) {
        StateInTarget stateInTarget = blobExistenceChecker.check(layerDigest);
        if (stateInTarget == StateInTarget.EXISTING) {
            eventHandlers.dispatch(LogEvent.info("Skipping pull; BLOB already exists on target registry : " + layer.getBlobDescriptor()));
            return new PreparedLayer.Builder(layer).setStateInTarget(stateInTarget).build();
        }
        Cache cache = buildContext.getBaseImageLayersCache();
        // Checks if the layer already exists in the cache.
        Optional<CachedLayer> optionalCachedLayer = cache.retrieve(layerDigest);
        if (optionalCachedLayer.isPresent()) {
            CachedLayer cachedLayer = optionalCachedLayer.get();
            return new PreparedLayer.Builder(cachedLayer).setStateInTarget(stateInTarget).build();
        } else if (buildContext.isOffline()) {
            throw new IOException("Cannot run Jib in offline mode; local Jib cache for base image is missing image layer " + layerDigest + ". Rerun Jib in online mode with \"-Djib.alwaysCacheBaseImage=true\" to " + "re-download the base image layers.");
        }
        try (ThrottledProgressEventDispatcherWrapper progressEventDispatcherWrapper = new ThrottledProgressEventDispatcherWrapper(progressEventDispatcher.newChildProducer(), "pulling base image layer " + layerDigest)) {
            CachedLayer cachedLayer = cache.writeCompressedLayer(Verify.verifyNotNull(registryClient).pullBlob(layerDigest, progressEventDispatcherWrapper::setProgressTarget, progressEventDispatcherWrapper::dispatchProgress));
            return new PreparedLayer.Builder(cachedLayer).setStateInTarget(stateInTarget).build();
        }
    }
}
Also used : ProgressEventDispatcher(com.google.cloud.tools.jib.builder.ProgressEventDispatcher) DescriptorDigest(com.google.cloud.tools.jib.api.DescriptorDigest) StateInTarget(com.google.cloud.tools.jib.builder.steps.PreparedLayer.StateInTarget) TimerEventDispatcher(com.google.cloud.tools.jib.builder.TimerEventDispatcher) CachedLayer(com.google.cloud.tools.jib.cache.CachedLayer) EventHandlers(com.google.cloud.tools.jib.event.EventHandlers) IOException(java.io.IOException) Cache(com.google.cloud.tools.jib.cache.Cache)

Example 2 with StateInTarget

use of com.google.cloud.tools.jib.builder.steps.PreparedLayer.StateInTarget in project jib by GoogleContainerTools.

the class ObtainBaseImageLayerStep method call.

@Override
public PreparedLayer call() throws IOException, CacheCorruptedException, RegistryException {
    EventHandlers eventHandlers = buildContext.getEventHandlers();
    DescriptorDigest layerDigest = layer.getBlobDescriptor().getDigest();
    try (ProgressEventDispatcher progressEventDispatcher = progressEventDispatcherFactory.create("checking base image layer " + layerDigest, 1);
        TimerEventDispatcher ignored = new TimerEventDispatcher(eventHandlers, String.format(DESCRIPTION, layerDigest))) {
        StateInTarget stateInTarget = blobExistenceChecker.check(layerDigest);
        if (stateInTarget == StateInTarget.EXISTING) {
            eventHandlers.dispatch(LogEvent.info("Skipping pull; BLOB already exists on target registry : " + layer.getBlobDescriptor()));
            return new PreparedLayer.Builder(layer).setStateInTarget(stateInTarget).build();
        }
        Cache cache = buildContext.getBaseImageLayersCache();
        // Checks if the layer already exists in the cache.
        Optional<CachedLayer> optionalCachedLayer = cache.retrieve(layerDigest);
        if (optionalCachedLayer.isPresent()) {
            CachedLayer cachedLayer = optionalCachedLayer.get();
            return new PreparedLayer.Builder(cachedLayer).setStateInTarget(stateInTarget).build();
        } else if (buildContext.isOffline()) {
            throw new IOException("Cannot run Jib in offline mode; local Jib cache for base image is missing image layer " + layerDigest + ". Rerun Jib in online mode with \"-Djib.alwaysCacheBaseImage=true\" to " + "re-download the base image layers.");
        }
        try (ThrottledProgressEventDispatcherWrapper progressEventDispatcherWrapper = new ThrottledProgressEventDispatcherWrapper(progressEventDispatcher.newChildProducer(), "pulling base image layer " + layerDigest)) {
            CachedLayer cachedLayer = cache.writeCompressedLayer(Verify.verifyNotNull(registryClient).pullBlob(layerDigest, progressEventDispatcherWrapper::setProgressTarget, progressEventDispatcherWrapper::dispatchProgress));
            return new PreparedLayer.Builder(cachedLayer).setStateInTarget(stateInTarget).build();
        }
    }
}
Also used : ProgressEventDispatcher(com.google.cloud.tools.jib.builder.ProgressEventDispatcher) DescriptorDigest(com.google.cloud.tools.jib.api.DescriptorDigest) StateInTarget(com.google.cloud.tools.jib.builder.steps.PreparedLayer.StateInTarget) TimerEventDispatcher(com.google.cloud.tools.jib.builder.TimerEventDispatcher) CachedLayer(com.google.cloud.tools.jib.cache.CachedLayer) EventHandlers(com.google.cloud.tools.jib.event.EventHandlers) IOException(java.io.IOException) Cache(com.google.cloud.tools.jib.cache.Cache)

Aggregations

DescriptorDigest (com.google.cloud.tools.jib.api.DescriptorDigest)2 ProgressEventDispatcher (com.google.cloud.tools.jib.builder.ProgressEventDispatcher)2 TimerEventDispatcher (com.google.cloud.tools.jib.builder.TimerEventDispatcher)2 StateInTarget (com.google.cloud.tools.jib.builder.steps.PreparedLayer.StateInTarget)2 Cache (com.google.cloud.tools.jib.cache.Cache)2 CachedLayer (com.google.cloud.tools.jib.cache.CachedLayer)2 EventHandlers (com.google.cloud.tools.jib.event.EventHandlers)2 IOException (java.io.IOException)2