Search in sources :

Example 66 with DescriptorDigest

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

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 67 with DescriptorDigest

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

the class CheckManifestStep method call.

@Override
public Optional<ManifestAndDigest<ManifestTemplate>> call() throws IOException, RegistryException {
    DescriptorDigest manifestDigest = Digests.computeJsonDigest(manifestTemplate);
    EventHandlers eventHandlers = buildContext.getEventHandlers();
    try (TimerEventDispatcher ignored = new TimerEventDispatcher(eventHandlers, DESCRIPTION);
        ProgressEventDispatcher ignored2 = progressEventDispatcherFactory.create("checking existence of manifest for " + manifestDigest, 1)) {
        eventHandlers.dispatch(LogEvent.info("Checking existence of manifest for " + manifestDigest + "..."));
        if (!JibSystemProperties.skipExistingImages()) {
            eventHandlers.dispatch(LogEvent.info("Skipping manifest existence check; system property set to false"));
            return Optional.empty();
        }
        return registryClient.checkManifest(manifestDigest.toString());
    }
}
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) EventHandlers(com.google.cloud.tools.jib.event.EventHandlers)

Example 68 with DescriptorDigest

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

the class ObtainBaseImageLayerStep method call.

@Override
public PreparedLayer call() throws IOException, CacheCorruptedException, RegistryException {
    EventHandlers eventHandlers = buildContext.getEventHandlers();
    DescriptorDigest layerDigest = layer.getBlobDescriptor().getDigest();
    try (ProgressEventDispatcher progressEventDispatcher = progressEventDispatcherFactory.create("checking base image layer " + layerDigest, 1);
        TimerEventDispatcher ignored = new TimerEventDispatcher(eventHandlers, String.format(DESCRIPTION, layerDigest))) {
        StateInTarget stateInTarget = blobExistenceChecker.check(layerDigest);
        if (stateInTarget == StateInTarget.EXISTING) {
            eventHandlers.dispatch(LogEvent.info("Skipping pull; BLOB already exists on target registry : " + layer.getBlobDescriptor()));
            return new PreparedLayer.Builder(layer).setStateInTarget(stateInTarget).build();
        }
        Cache cache = buildContext.getBaseImageLayersCache();
        // Checks if the layer already exists in the cache.
        Optional<CachedLayer> optionalCachedLayer = cache.retrieve(layerDigest);
        if (optionalCachedLayer.isPresent()) {
            CachedLayer cachedLayer = optionalCachedLayer.get();
            return new PreparedLayer.Builder(cachedLayer).setStateInTarget(stateInTarget).build();
        } else if (buildContext.isOffline()) {
            throw new IOException("Cannot run Jib in offline mode; local Jib cache for base image is missing image layer " + layerDigest + ". Rerun Jib in online mode with \"-Djib.alwaysCacheBaseImage=true\" to " + "re-download the base image layers.");
        }
        try (ThrottledProgressEventDispatcherWrapper progressEventDispatcherWrapper = new ThrottledProgressEventDispatcherWrapper(progressEventDispatcher.newChildProducer(), "pulling base image layer " + layerDigest)) {
            CachedLayer cachedLayer = cache.writeCompressedLayer(Verify.verifyNotNull(registryClient).pullBlob(layerDigest, progressEventDispatcherWrapper::setProgressTarget, progressEventDispatcherWrapper::dispatchProgress));
            return new PreparedLayer.Builder(cachedLayer).setStateInTarget(stateInTarget).build();
        }
    }
}
Also used : ProgressEventDispatcher(com.google.cloud.tools.jib.builder.ProgressEventDispatcher) DescriptorDigest(com.google.cloud.tools.jib.api.DescriptorDigest) StateInTarget(com.google.cloud.tools.jib.builder.steps.PreparedLayer.StateInTarget) TimerEventDispatcher(com.google.cloud.tools.jib.builder.TimerEventDispatcher) CachedLayer(com.google.cloud.tools.jib.cache.CachedLayer) EventHandlers(com.google.cloud.tools.jib.event.EventHandlers) IOException(java.io.IOException) Cache(com.google.cloud.tools.jib.cache.Cache)

Example 69 with DescriptorDigest

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

the class BlobCheckerIntegrationTest method testCheck_doesNotExist.

@Test
public void testCheck_doesNotExist() throws IOException, RegistryException, DigestException {
    RegistryClient registryClient = RegistryClient.factory(EventHandlers.NONE, "gcr.io", "distroless/base", httpClient).newRegistryClient();
    DescriptorDigest fakeBlobDigest = DescriptorDigest.fromHash("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
    Assert.assertFalse(registryClient.checkBlob(fakeBlobDigest).isPresent());
}
Also used : DescriptorDigest(com.google.cloud.tools.jib.api.DescriptorDigest) Test(org.junit.Test)

Example 70 with DescriptorDigest

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

the class BlobPullerIntegrationTest method testPull_unknownBlob.

@Test
public void testPull_unknownBlob() throws IOException, DigestException {
    DescriptorDigest nonexistentDigest = DescriptorDigest.fromHash("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
    RegistryClient registryClient = RegistryClient.factory(EventHandlers.NONE, "gcr.io", "distroless/base", httpClient).newRegistryClient();
    try {
        registryClient.pullBlob(nonexistentDigest, ignored -> {
        }, ignored -> {
        }).writeTo(ByteStreams.nullOutputStream());
        Assert.fail("Trying to pull nonexistent blob should have errored");
    } catch (IOException ex) {
        if (!(ex.getCause() instanceof RegistryErrorException)) {
            throw ex;
        }
        MatcherAssert.assertThat(ex.getMessage(), CoreMatchers.containsString("pull BLOB for gcr.io/distroless/base with digest " + nonexistentDigest));
    }
}
Also used : LongAdder(java.util.concurrent.atomic.LongAdder) CoreMatchers(org.hamcrest.CoreMatchers) Blob(com.google.cloud.tools.jib.blob.Blob) FailoverHttpClient(com.google.cloud.tools.jib.http.FailoverHttpClient) IOException(java.io.IOException) Test(org.junit.Test) RegistryException(com.google.cloud.tools.jib.api.RegistryException) DescriptorDigest(com.google.cloud.tools.jib.api.DescriptorDigest) V22ManifestTemplate(com.google.cloud.tools.jib.image.json.V22ManifestTemplate) MatcherAssert(org.hamcrest.MatcherAssert) ByteStreams(com.google.common.io.ByteStreams) DigestException(java.security.DigestException) EventHandlers(com.google.cloud.tools.jib.event.EventHandlers) Assert(org.junit.Assert) DescriptorDigest(com.google.cloud.tools.jib.api.DescriptorDigest) IOException(java.io.IOException) Test(org.junit.Test)

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