Search in sources :

Example 16 with DescriptorDigest

use of com.google.cloud.tools.jib.api.DescriptorDigest in project jib by GoogleContainerTools.

the class PushImageStep method makeListForManifestList.

static ImmutableList<PushImageStep> makeListForManifestList(BuildContext buildContext, ProgressEventDispatcher.Factory progressEventDispatcherFactory, RegistryClient registryClient, ManifestTemplate manifestList, boolean manifestListAlreadyExists) throws IOException {
    Set<String> tags = buildContext.getAllTargetImageTags();
    EventHandlers eventHandlers = buildContext.getEventHandlers();
    try (TimerEventDispatcher ignored = new TimerEventDispatcher(eventHandlers, "Preparing manifest list pushers");
        ProgressEventDispatcher progressEventDispatcher = progressEventDispatcherFactory.create("launching manifest list pushers", tags.size())) {
        boolean singlePlatform = buildContext.getContainerConfiguration().getPlatforms().size() == 1;
        if (singlePlatform) {
            // single image; no need to push a manifest list
            return ImmutableList.of();
        }
        if (JibSystemProperties.skipExistingImages() && manifestListAlreadyExists) {
            eventHandlers.dispatch(LogEvent.info("Skipping pushing manifest list; already exists."));
            return ImmutableList.of();
        }
        DescriptorDigest manifestListDigest = Digests.computeJsonDigest(manifestList);
        return tags.stream().map(tag -> new PushImageStep(buildContext, progressEventDispatcher.newChildProducer(), registryClient, manifestList, tag, manifestListDigest, // return value and type.
        manifestListDigest)).collect(ImmutableList.toImmutableList());
    }
}
Also used : TimerEventDispatcher(com.google.cloud.tools.jib.builder.TimerEventDispatcher) BuildableManifestTemplate(com.google.cloud.tools.jib.image.json.BuildableManifestTemplate) ImageToJsonTranslator(com.google.cloud.tools.jib.image.json.ImageToJsonTranslator) Set(java.util.Set) IOException(java.io.IOException) Callable(java.util.concurrent.Callable) RegistryException(com.google.cloud.tools.jib.api.RegistryException) BuildContext(com.google.cloud.tools.jib.configuration.BuildContext) Collectors(java.util.stream.Collectors) BlobDescriptor(com.google.cloud.tools.jib.blob.BlobDescriptor) DescriptorDigest(com.google.cloud.tools.jib.api.DescriptorDigest) Digests(com.google.cloud.tools.jib.hash.Digests) RegistryClient(com.google.cloud.tools.jib.registry.RegistryClient) LogEvent(com.google.cloud.tools.jib.api.LogEvent) ImmutableList(com.google.common.collect.ImmutableList) JibSystemProperties(com.google.cloud.tools.jib.global.JibSystemProperties) ManifestTemplate(com.google.cloud.tools.jib.image.json.ManifestTemplate) ProgressEventDispatcher(com.google.cloud.tools.jib.builder.ProgressEventDispatcher) EventHandlers(com.google.cloud.tools.jib.event.EventHandlers) Collections(java.util.Collections) Image(com.google.cloud.tools.jib.image.Image) ProgressEventDispatcher(com.google.cloud.tools.jib.builder.ProgressEventDispatcher) DescriptorDigest(com.google.cloud.tools.jib.api.DescriptorDigest) TimerEventDispatcher(com.google.cloud.tools.jib.builder.TimerEventDispatcher) EventHandlers(com.google.cloud.tools.jib.event.EventHandlers)

Example 17 with DescriptorDigest

use of com.google.cloud.tools.jib.api.DescriptorDigest in project jib by GoogleContainerTools.

the class PushImageStep method makeList.

static ImmutableList<PushImageStep> makeList(BuildContext buildContext, ProgressEventDispatcher.Factory progressEventDispatcherFactory, RegistryClient registryClient, BlobDescriptor containerConfigurationDigestAndSize, Image builtImage, boolean manifestAlreadyExists) throws IOException {
    // Gets the image manifest to push.
    BuildableManifestTemplate manifestTemplate = new ImageToJsonTranslator(builtImage).getManifestTemplate(buildContext.getTargetFormat(), containerConfigurationDigestAndSize);
    DescriptorDigest manifestDigest = Digests.computeJsonDigest(manifestTemplate);
    Set<String> imageQualifiers = getImageQualifiers(buildContext, builtImage, manifestDigest);
    EventHandlers eventHandlers = buildContext.getEventHandlers();
    try (TimerEventDispatcher ignored = new TimerEventDispatcher(eventHandlers, "Preparing manifest pushers");
        ProgressEventDispatcher progressDispatcher = progressEventDispatcherFactory.create("launching manifest pushers", imageQualifiers.size())) {
        if (JibSystemProperties.skipExistingImages() && manifestAlreadyExists) {
            eventHandlers.dispatch(LogEvent.info("Skipping pushing manifest; already exists."));
            return ImmutableList.of();
        }
        return imageQualifiers.stream().map(qualifier -> new PushImageStep(buildContext, progressDispatcher.newChildProducer(), registryClient, manifestTemplate, qualifier, manifestDigest, containerConfigurationDigestAndSize.getDigest())).collect(ImmutableList.toImmutableList());
    }
}
Also used : TimerEventDispatcher(com.google.cloud.tools.jib.builder.TimerEventDispatcher) BuildableManifestTemplate(com.google.cloud.tools.jib.image.json.BuildableManifestTemplate) ImageToJsonTranslator(com.google.cloud.tools.jib.image.json.ImageToJsonTranslator) Set(java.util.Set) IOException(java.io.IOException) Callable(java.util.concurrent.Callable) RegistryException(com.google.cloud.tools.jib.api.RegistryException) BuildContext(com.google.cloud.tools.jib.configuration.BuildContext) Collectors(java.util.stream.Collectors) BlobDescriptor(com.google.cloud.tools.jib.blob.BlobDescriptor) DescriptorDigest(com.google.cloud.tools.jib.api.DescriptorDigest) Digests(com.google.cloud.tools.jib.hash.Digests) RegistryClient(com.google.cloud.tools.jib.registry.RegistryClient) LogEvent(com.google.cloud.tools.jib.api.LogEvent) ImmutableList(com.google.common.collect.ImmutableList) JibSystemProperties(com.google.cloud.tools.jib.global.JibSystemProperties) ManifestTemplate(com.google.cloud.tools.jib.image.json.ManifestTemplate) ProgressEventDispatcher(com.google.cloud.tools.jib.builder.ProgressEventDispatcher) EventHandlers(com.google.cloud.tools.jib.event.EventHandlers) Collections(java.util.Collections) Image(com.google.cloud.tools.jib.image.Image) ProgressEventDispatcher(com.google.cloud.tools.jib.builder.ProgressEventDispatcher) ImageToJsonTranslator(com.google.cloud.tools.jib.image.json.ImageToJsonTranslator) DescriptorDigest(com.google.cloud.tools.jib.api.DescriptorDigest) TimerEventDispatcher(com.google.cloud.tools.jib.builder.TimerEventDispatcher) EventHandlers(com.google.cloud.tools.jib.event.EventHandlers) BuildableManifestTemplate(com.google.cloud.tools.jib.image.json.BuildableManifestTemplate)

Example 18 with DescriptorDigest

use of com.google.cloud.tools.jib.api.DescriptorDigest in project jib by GoogleContainerTools.

the class StepsRunner method obtainBaseImageLayers.

// This method updates the given "preparedLayersCache" and should not be called concurrently.
@VisibleForTesting
List<Future<PreparedLayer>> obtainBaseImageLayers(Image baseImage, boolean layersRequiredLocally, Map<DescriptorDigest, Future<PreparedLayer>> preparedLayersCache, ProgressEventDispatcher.Factory progressDispatcherFactory) throws InterruptedException, ExecutionException {
    List<Future<PreparedLayer>> preparedLayers = new ArrayList<>();
    try (ProgressEventDispatcher progressDispatcher = progressDispatcherFactory.create("launching base image layer pullers", baseImage.getLayers().size())) {
        for (Layer layer : baseImage.getLayers()) {
            DescriptorDigest digest = layer.getBlobDescriptor().getDigest();
            Future<PreparedLayer> preparedLayer = preparedLayersCache.get(digest);
            if (preparedLayer != null) {
                progressDispatcher.dispatchProgress(1);
            } else {
                // If we haven't obtained this layer yet, launcher a puller.
                preparedLayer = executorService.submit(layersRequiredLocally ? ObtainBaseImageLayerStep.forForcedDownload(buildContext, progressDispatcher.newChildProducer(), layer, results.baseImagesAndRegistryClient.get().registryClient) : ObtainBaseImageLayerStep.forSelectiveDownload(buildContext, progressDispatcher.newChildProducer(), layer, results.baseImagesAndRegistryClient.get().registryClient, results.targetRegistryClient.get()));
                preparedLayersCache.put(digest, preparedLayer);
            }
            preparedLayers.add(preparedLayer);
        }
        return preparedLayers;
    }
}
Also used : ProgressEventDispatcher(com.google.cloud.tools.jib.builder.ProgressEventDispatcher) DescriptorDigest(com.google.cloud.tools.jib.api.DescriptorDigest) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) Layer(com.google.cloud.tools.jib.image.Layer) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 19 with DescriptorDigest

use of com.google.cloud.tools.jib.api.DescriptorDigest in project jib by GoogleContainerTools.

the class BuildResult method fromImage.

/**
 * Gets a {@link BuildResult} from an {@link Image}.
 *
 * @param image the image
 * @param targetFormat the target format of the image
 * @return a new {@link BuildResult} with the image's digest and id
 * @throws IOException if writing the digest or container configuration fails
 */
static BuildResult fromImage(Image image, Class<? extends BuildableManifestTemplate> targetFormat) throws IOException {
    ImageToJsonTranslator imageToJsonTranslator = new ImageToJsonTranslator(image);
    BlobDescriptor containerConfigurationBlobDescriptor = Digests.computeDigest(imageToJsonTranslator.getContainerConfiguration());
    BuildableManifestTemplate manifestTemplate = imageToJsonTranslator.getManifestTemplate(targetFormat, containerConfigurationBlobDescriptor);
    DescriptorDigest imageDigest = Digests.computeJsonDigest(manifestTemplate);
    DescriptorDigest imageId = containerConfigurationBlobDescriptor.getDigest();
    return new BuildResult(imageDigest, imageId);
}
Also used : BlobDescriptor(com.google.cloud.tools.jib.blob.BlobDescriptor) ImageToJsonTranslator(com.google.cloud.tools.jib.image.json.ImageToJsonTranslator) DescriptorDigest(com.google.cloud.tools.jib.api.DescriptorDigest) BuildableManifestTemplate(com.google.cloud.tools.jib.image.json.BuildableManifestTemplate)

Example 20 with DescriptorDigest

use of com.google.cloud.tools.jib.api.DescriptorDigest in project jib by GoogleContainerTools.

the class LocalBaseImageSteps method getCachedDockerImage.

@VisibleForTesting
static Optional<LocalImage> getCachedDockerImage(Cache cache, DockerImageDetails dockerImageDetails) throws DigestException, IOException, CacheCorruptedException {
    // Get config
    Optional<ContainerConfigurationTemplate> cachedConfig = cache.retrieveLocalConfig(dockerImageDetails.getImageId());
    if (!cachedConfig.isPresent()) {
        return Optional.empty();
    }
    // Get layers
    List<Future<PreparedLayer>> cachedLayers = new ArrayList<>();
    for (DescriptorDigest diffId : dockerImageDetails.getDiffIds()) {
        Optional<CachedLayer> cachedLayer = cache.retrieveTarLayer(diffId);
        if (!cachedLayer.isPresent()) {
            return Optional.empty();
        }
        CachedLayer layer = cachedLayer.get();
        cachedLayers.add(Futures.immediateFuture(new PreparedLayer.Builder(layer).build()));
    }
    return Optional.of(new LocalImage(cachedLayers, cachedConfig.get()));
}
Also used : ContainerConfigurationTemplate(com.google.cloud.tools.jib.image.json.ContainerConfigurationTemplate) DescriptorDigest(com.google.cloud.tools.jib.api.DescriptorDigest) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) CachedLayer(com.google.cloud.tools.jib.cache.CachedLayer) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

DescriptorDigest (com.google.cloud.tools.jib.api.DescriptorDigest)112 Test (org.junit.Test)68 Path (java.nio.file.Path)28 BlobDescriptor (com.google.cloud.tools.jib.blob.BlobDescriptor)24 Blob (com.google.cloud.tools.jib.blob.Blob)18 ProgressEventDispatcher (com.google.cloud.tools.jib.builder.ProgressEventDispatcher)16 EventHandlers (com.google.cloud.tools.jib.event.EventHandlers)16 V22ManifestTemplate (com.google.cloud.tools.jib.image.json.V22ManifestTemplate)16 Image (com.google.cloud.tools.jib.image.Image)14 ByteArrayInputStream (java.io.ByteArrayInputStream)14 IOException (java.io.IOException)14 InputStream (java.io.InputStream)14 RegistryException (com.google.cloud.tools.jib.api.RegistryException)12 TimerEventDispatcher (com.google.cloud.tools.jib.builder.TimerEventDispatcher)12 ManifestTemplate (com.google.cloud.tools.jib.image.json.ManifestTemplate)10 RegistryClient (com.google.cloud.tools.jib.registry.RegistryClient)10 DigestException (java.security.DigestException)10 FailoverHttpClient (com.google.cloud.tools.jib.http.FailoverHttpClient)8 Layer (com.google.cloud.tools.jib.image.Layer)8 OutputStream (java.io.OutputStream)8