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());
}
}
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());
}
}
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;
}
}
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);
}
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()));
}
Aggregations