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