use of com.google.cloud.tools.jib.event.EventHandlers in project jib by GoogleContainerTools.
the class PushBlobStep method call.
@Override
public BlobDescriptor call() throws IOException, RegistryException {
EventHandlers eventHandlers = buildContext.getEventHandlers();
DescriptorDigest blobDigest = blobDescriptor.getDigest();
try (ProgressEventDispatcher progressEventDispatcher = progressEventDispatcherFactory.create("pushing blob " + blobDigest, blobDescriptor.getSize());
TimerEventDispatcher ignored = new TimerEventDispatcher(eventHandlers, DESCRIPTION + blobDescriptor);
ThrottledAccumulatingConsumer throttledProgressReporter = new ThrottledAccumulatingConsumer(progressEventDispatcher::dispatchProgress)) {
// check if the BLOB is available
if (!forcePush && registryClient.checkBlob(blobDigest).isPresent()) {
eventHandlers.dispatch(LogEvent.info("Skipping push; BLOB already exists on target registry : " + blobDescriptor));
return blobDescriptor;
}
// If base and target images are in the same registry, then use mount/from to try mounting the
// BLOB from the base image repository to the target image repository and possibly avoid
// having to push the BLOB. See
// https://docs.docker.com/registry/spec/api/#cross-repository-blob-mount for details.
String baseRegistry = buildContext.getBaseImageConfiguration().getImageRegistry();
String baseRepository = buildContext.getBaseImageConfiguration().getImageRepository();
String targetRegistry = buildContext.getTargetImageConfiguration().getImageRegistry();
String sourceRepository = targetRegistry.equals(baseRegistry) ? baseRepository : null;
registryClient.pushBlob(blobDigest, blob, sourceRepository, throttledProgressReporter);
return blobDescriptor;
}
}
use of com.google.cloud.tools.jib.event.EventHandlers 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.event.EventHandlers 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.event.EventHandlers in project jib by GoogleContainerTools.
the class BuildManifestListOrSingleManifestStep method call.
@Override
public ManifestTemplate call() throws IOException {
Preconditions.checkState(!builtImages.isEmpty(), "no images given");
EventHandlers eventHandlers = buildContext.getEventHandlers();
try (TimerEventDispatcher ignored = new TimerEventDispatcher(eventHandlers, DESCRIPTION);
ProgressEventDispatcher ignored2 = progressEventDispatcherFactory.create("building a manifest list or a single manifest", 1)) {
if (builtImages.size() == 1) {
eventHandlers.dispatch(LogEvent.info("Building a single manifest"));
ImageToJsonTranslator imageTranslator = new ImageToJsonTranslator(builtImages.get(0));
BlobDescriptor configDescriptor = Digests.computeDigest(imageTranslator.getContainerConfiguration());
return imageTranslator.getManifestTemplate(buildContext.getTargetFormat(), configDescriptor);
}
eventHandlers.dispatch(LogEvent.info("Building a manifest list"));
return new ManifestListGenerator(builtImages).getManifestListTemplate(buildContext.getTargetFormat());
}
}
use of com.google.cloud.tools.jib.event.EventHandlers in project jib by GoogleContainerTools.
the class BuildAndCacheApplicationLayerStep method call.
@Override
public PreparedLayer call() throws IOException, CacheCorruptedException {
String description = String.format(DESCRIPTION, layerName);
EventHandlers eventHandlers = buildContext.getEventHandlers();
eventHandlers.dispatch(LogEvent.progress(description + "..."));
try (ProgressEventDispatcher ignored = progressEventDispatcherFactory.create("building " + layerName + " layer", 1);
TimerEventDispatcher ignored2 = new TimerEventDispatcher(eventHandlers, description)) {
Cache cache = buildContext.getApplicationLayersCache();
ImmutableList<FileEntry> layerEntries = ImmutableList.copyOf(layerConfiguration.getEntries());
// Don't build the layer if it exists already.
Optional<CachedLayer> optionalCachedLayer = cache.retrieve(layerEntries);
if (optionalCachedLayer.isPresent()) {
return new PreparedLayer.Builder(optionalCachedLayer.get()).setName(layerName).build();
}
Blob layerBlob = new ReproducibleLayerBuilder(layerEntries).build();
CachedLayer cachedLayer = cache.writeUncompressedLayer(layerBlob, layerEntries);
eventHandlers.dispatch(LogEvent.debug(description + " built " + cachedLayer.getDigest()));
return new PreparedLayer.Builder(cachedLayer).setName(layerName).build();
}
}
Aggregations