Search in sources :

Example 6 with ThrottledAccumulatingConsumer

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;
    }
}
Also used : ProgressEventDispatcher(com.google.cloud.tools.jib.builder.ProgressEventDispatcher) DescriptorDigest(com.google.cloud.tools.jib.api.DescriptorDigest) TimerEventDispatcher(com.google.cloud.tools.jib.builder.TimerEventDispatcher) ThrottledAccumulatingConsumer(com.google.cloud.tools.jib.event.progress.ThrottledAccumulatingConsumer) EventHandlers(com.google.cloud.tools.jib.event.EventHandlers)

Example 7 with ThrottledAccumulatingConsumer

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());
        }
    }
}
Also used : ProgressEventDispatcher(com.google.cloud.tools.jib.builder.ProgressEventDispatcher) ImageTarball(com.google.cloud.tools.jib.image.ImageTarball) TimerEventDispatcher(com.google.cloud.tools.jib.builder.TimerEventDispatcher) ThrottledAccumulatingConsumer(com.google.cloud.tools.jib.event.progress.ThrottledAccumulatingConsumer) EventHandlers(com.google.cloud.tools.jib.event.EventHandlers)

Example 8 with ThrottledAccumulatingConsumer

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());
        }
    }
}
Also used : ProgressEventDispatcher(com.google.cloud.tools.jib.builder.ProgressEventDispatcher) ImageTarball(com.google.cloud.tools.jib.image.ImageTarball) TimerEventDispatcher(com.google.cloud.tools.jib.builder.TimerEventDispatcher) ThrottledAccumulatingConsumer(com.google.cloud.tools.jib.event.progress.ThrottledAccumulatingConsumer) EventHandlers(com.google.cloud.tools.jib.event.EventHandlers)

Example 9 with ThrottledAccumulatingConsumer

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);
}
Also used : ThrottledAccumulatingConsumer(com.google.cloud.tools.jib.event.progress.ThrottledAccumulatingConsumer)

Example 10 with ThrottledAccumulatingConsumer

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());
}
Also used : Instant(java.time.Instant) ArrayList(java.util.ArrayList) ThrottledAccumulatingConsumer(com.google.cloud.tools.jib.event.progress.ThrottledAccumulatingConsumer) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ArrayDeque(java.util.ArrayDeque) Test(org.junit.Test)

Aggregations

ThrottledAccumulatingConsumer (com.google.cloud.tools.jib.event.progress.ThrottledAccumulatingConsumer)10 ProgressEventDispatcher (com.google.cloud.tools.jib.builder.ProgressEventDispatcher)6 TimerEventDispatcher (com.google.cloud.tools.jib.builder.TimerEventDispatcher)4 EventHandlers (com.google.cloud.tools.jib.event.EventHandlers)4 DescriptorDigest (com.google.cloud.tools.jib.api.DescriptorDigest)2 Blob (com.google.cloud.tools.jib.blob.Blob)2 CachedLayer (com.google.cloud.tools.jib.cache.CachedLayer)2 NotifyingOutputStream (com.google.cloud.tools.jib.http.NotifyingOutputStream)2 ImageTarball (com.google.cloud.tools.jib.image.ImageTarball)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 Instant (java.time.Instant)2 ArrayDeque (java.util.ArrayDeque)2 ArrayList (java.util.ArrayList)2 GZIPOutputStream (java.util.zip.GZIPOutputStream)2 Test (org.junit.Test)2