public async Task <BlobDescriptor> CallAsync() { Authorization authorization = await authenticatePushStep.GetFuture().ConfigureAwait(false); using (ProgressEventDispatcher progressEventDispatcher = progressEventDipatcherFactory.Create( "pushing blob " + blobDescriptor.GetDigest(), blobDescriptor.GetSize())) using (TimerEventDispatcher ignored = new TimerEventDispatcher( buildConfiguration.GetEventHandlers(), DESCRIPTION + blobDescriptor)) using (ThrottledAccumulatingConsumer throttledProgressReporter = new ThrottledAccumulatingConsumer(progressEventDispatcher.DispatchProgress)) { RegistryClient registryClient = buildConfiguration .NewTargetImageRegistryClientFactory() .SetAuthorization(authorization) .NewRegistryClient(); // check if the BLOB is available if (await registryClient.CheckBlobAsync(blobDescriptor).ConfigureAwait(false)) { buildConfiguration .GetEventHandlers() .Dispatch(LogEvent.Info("BLOB : " + blobDescriptor + " already exists on registry")); return(blobDescriptor); } // todo: leverage cross-repository mounts await registryClient.PushBlobAsync(blobDescriptor.GetDigest(), blob, null, throttledProgressReporter.Accept).ConfigureAwait(false); return(blobDescriptor); } }
public async Task TestCheck_doesNotExistAsync() { localRegistry.PullAndPushToLocal("busybox", "busybox"); RegistryClient registryClient = RegistryClient.CreateFactory(EventHandlers.NONE, "localhost:5000", "busybox") .SetAllowInsecureRegistries(true) .NewRegistryClient(); DescriptorDigest fakeBlobDigest = DescriptorDigest.FromHash( "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); Assert.IsFalse(await registryClient.CheckBlobAsync(new BlobDescriptor(fakeBlobDigest)).ConfigureAwait(false)); }
public async Task TestCheck_existsAsync() { localRegistry.PullAndPushToLocal("busybox", "busybox"); RegistryClient registryClient = RegistryClient.CreateFactory(EventHandlers.NONE, "localhost:5000", "busybox") .SetAllowInsecureRegistries(true) .NewRegistryClient(); V22ManifestTemplate manifestTemplate = await registryClient.PullManifestAsync <V22ManifestTemplate>("latest").ConfigureAwait(false); DescriptorDigest blobDigest = manifestTemplate.Layers[0].Digest; Assert.IsTrue(await registryClient.CheckBlobAsync(new BlobDescriptor(blobDigest)).ConfigureAwait(false)); }