use of com.google.cloud.tools.jib.event.progress.ThrottledAccumulatingConsumer in project jib by google.
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.progress.ThrottledAccumulatingConsumer in project jib by google.
the class LoadDockerStep method call.
@Override
public BuildResult call() throws InterruptedException, IOException {
EventHandlers eventHandlers = buildContext.getEventHandlers();
try (TimerEventDispatcher ignored = new TimerEventDispatcher(eventHandlers, "Loading to Docker daemon")) {
eventHandlers.dispatch(LogEvent.progress("Loading to Docker daemon..."));
ImageTarball imageTarball = new ImageTarball(builtImage, buildContext.getTargetImageConfiguration().getImage(), buildContext.getAllTargetImageTags());
// See https://github.com/GoogleContainerTools/jib/pull/1960#discussion_r321898390
try (ProgressEventDispatcher progressEventDispatcher = progressEventDispatcherFactory.create("loading to Docker daemon", imageTarball.getTotalLayerSize());
ThrottledAccumulatingConsumer throttledProgressReporter = new ThrottledAccumulatingConsumer(progressEventDispatcher::dispatchProgress)) {
// Load the image to docker daemon.
eventHandlers.dispatch(LogEvent.debug(dockerClient.load(imageTarball, throttledProgressReporter)));
return BuildResult.fromImage(builtImage, buildContext.getTargetFormat());
}
}
}
use of com.google.cloud.tools.jib.event.progress.ThrottledAccumulatingConsumer in project jib by GoogleContainerTools.
the class LoadDockerStep method call.
@Override
public BuildResult call() throws InterruptedException, IOException {
EventHandlers eventHandlers = buildContext.getEventHandlers();
try (TimerEventDispatcher ignored = new TimerEventDispatcher(eventHandlers, "Loading to Docker daemon")) {
eventHandlers.dispatch(LogEvent.progress("Loading to Docker daemon..."));
ImageTarball imageTarball = new ImageTarball(builtImage, buildContext.getTargetImageConfiguration().getImage(), buildContext.getAllTargetImageTags());
// See https://github.com/GoogleContainerTools/jib/pull/1960#discussion_r321898390
try (ProgressEventDispatcher progressEventDispatcher = progressEventDispatcherFactory.create("loading to Docker daemon", imageTarball.getTotalLayerSize());
ThrottledAccumulatingConsumer throttledProgressReporter = new ThrottledAccumulatingConsumer(progressEventDispatcher::dispatchProgress)) {
// Load the image to docker daemon.
eventHandlers.dispatch(LogEvent.debug(dockerClient.load(imageTarball, throttledProgressReporter)));
return BuildResult.fromImage(builtImage, buildContext.getTargetFormat());
}
}
}
use of com.google.cloud.tools.jib.event.progress.ThrottledAccumulatingConsumer in project jib by GoogleContainerTools.
the class ThrottledProgressEventDispatcherWrapper method setProgressTarget.
void setProgressTarget(long allocationUnits) {
Preconditions.checkState(progressEventDispatcher == null);
progressEventDispatcher = progressEventDispatcherFactory.create(description, allocationUnits);
throttledDispatcher = new ThrottledAccumulatingConsumer(progressEventDispatcher::dispatchProgress);
}
use of com.google.cloud.tools.jib.event.progress.ThrottledAccumulatingConsumer in project jib by GoogleContainerTools.
the class NotifyingOutputStreamTest method testDelay.
@Test
public void testDelay() throws IOException {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
List<Long> byteCounts = new ArrayList<>();
Queue<Instant> instantQueue = new ArrayDeque<>();
instantQueue.add(Instant.EPOCH);
try (ThrottledAccumulatingConsumer byteCounter = new ThrottledAccumulatingConsumer(byteCounts::add, Duration.ofSeconds(3), instantQueue::remove);
NotifyingOutputStream notifyingOutputStream = new NotifyingOutputStream(byteArrayOutputStream, byteCounter)) {
instantQueue.add(Instant.EPOCH);
notifyingOutputStream.write(100);
instantQueue.add(Instant.EPOCH);
notifyingOutputStream.write(new byte[] { 101, 102, 103 });
instantQueue.add(Instant.EPOCH.plusSeconds(4));
notifyingOutputStream.write(new byte[] { 104, 105, 106 });
instantQueue.add(Instant.EPOCH.plusSeconds(10));
notifyingOutputStream.write(new byte[] { 107, 108 });
instantQueue.add(Instant.EPOCH.plusSeconds(10));
notifyingOutputStream.write(new byte[] { 109 });
instantQueue.add(Instant.EPOCH.plusSeconds(13));
notifyingOutputStream.write(new byte[] { 0, 110 }, 1, 1);
}
Assert.assertEquals(Arrays.asList(7L, 2L, 2L), byteCounts);
Assert.assertArrayEquals(new byte[] { 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110 }, byteArrayOutputStream.toByteArray());
}
Aggregations