public async Task TestPush_missingBlobsAsync() { localRegistry.PullAndPushToLocal("busybox", "busybox"); RegistryClient registryClient = RegistryClient.CreateFactory(EVENT_HANDLERS, "gcr.io", "distroless/java").NewRegistryClient(); IManifestTemplate manifestTemplate = await registryClient.PullManifestAsync("latest").ConfigureAwait(false); registryClient = RegistryClient.CreateFactory(EVENT_HANDLERS, "localhost:5000", "busybox") .SetAllowInsecureRegistries(true) .NewRegistryClient(); try { await registryClient.PushManifestAsync((V22ManifestTemplate)manifestTemplate, "latest").ConfigureAwait(false); Assert.Fail("Pushing manifest without its BLOBs should fail"); } catch (RegistryErrorException ex) { HttpResponseMessage httpResponse = ex.Cause; Assert.AreEqual( HttpStatusCode.BadRequest, httpResponse.StatusCode); } }
/** * Retrieves the cached base image. * * @return the cached image * @throws IOException when an I/O exception occurs * @throws CacheCorruptedException if the cache is corrupted * @throws LayerPropertyNotFoundException if adding image layers fails * @throws BadContainerConfigurationFormatException if the container configuration is in a bad * format */ private Image PullBaseImageOffline() { IImageReference baseImage = buildConfiguration.GetBaseImageConfiguration().GetImage(); Maybe <ManifestAndConfig> metadata = buildConfiguration.GetBaseImageLayersCache().RetrieveMetadata(baseImage); if (!metadata.IsPresent()) { throw new IOException( "Cannot run Fib in offline mode; " + baseImage + " not found in local Fib cache"); } IManifestTemplate manifestTemplate = metadata.Get().GetManifest(); if (manifestTemplate is V21ManifestTemplate v21ManifestTemplate) { return(JsonToImageTranslator.ToImage(v21ManifestTemplate)); } ContainerConfigurationTemplate configurationTemplate = metadata.Get().GetConfig().OrElseThrow(() => new InvalidOperationException()); return(JsonToImageTranslator.ToImage( (IBuildableManifestTemplate)manifestTemplate, configurationTemplate)); }
public async Task TestPull_v22Async() { localRegistry.PullAndPushToLocal("busybox", "busybox"); RegistryClient registryClient = RegistryClient.CreateFactory(EventHandlers.NONE, "gcr.io", "distroless/java").NewRegistryClient(); IManifestTemplate manifestTemplate = await registryClient.PullManifestAsync("latest").ConfigureAwait(false); Assert.AreEqual(2, manifestTemplate.SchemaVersion); V22ManifestTemplate v22ManifestTemplate = (V22ManifestTemplate)manifestTemplate; Assert.IsTrue(v22ManifestTemplate.Layers.Count > 0); }
/** * Pulls the image manifest for a specific tag. * * @param <T> child type of ManifestTemplate * @param imageTag the tag to pull on * @param manifestTemplateClass the specific version of manifest template to pull, or {@link * ManifestTemplate} to pull either {@link V22ManifestTemplate} or {@link V21ManifestTemplate} * @return the manifest template * @throws IOException if communicating with the endpoint fails * @throws RegistryException if communicating with the endpoint fails */ public async Task <IManifestTemplate> PullAnyManifestAsync(string imageTag) { ManifestPuller manifestPuller = new ManifestPuller(registryEndpointRequestProperties, imageTag); IManifestTemplate manifestTemplate = await CallRegistryEndpointAsync(manifestPuller).ConfigureAwait(false); if (manifestTemplate == null) { throw new InvalidOperationException(Resources.RegistryClientManifestPullerReturnedNullExceptionMessage); } return(manifestTemplate); }
public async Task TestHandleResponse_v22Async() { SystemPath v22ManifestFile = Paths.Get(TestResources.GetResource("core/json/v22manifest.json").ToURI()); Stream v22Manifest = new MemoryStream(Files.ReadAllBytes(v22ManifestFile)); mockResponse = new HttpResponseMessage { Content = new StreamContent(v22Manifest) }; IManifestTemplate manifestTemplate = await new ManifestPuller <V22ManifestTemplate>( fakeRegistryEndpointRequestProperties, "test-image-tag") .HandleResponseAsync(mockResponse).ConfigureAwait(false); Assert.IsInstanceOf <V22ManifestTemplate>(manifestTemplate); }
/** * Pulls the base image. * * @param registryAuthorization authentication credentials to possibly use * @param progressEventDispatcher the {@link ProgressEventDispatcher} for emitting {@link * ProgressEvent}s * @return the pulled image * @throws IOException when an I/O exception occurs during the pulling * @throws RegistryException if communicating with the registry caused a known error * @throws LayerCountMismatchException if the manifest and configuration contain conflicting layer * information * @throws LayerPropertyNotFoundException if adding image layers fails * @throws BadContainerConfigurationFormatException if the container configuration is in a bad * format */ private async Task <Image> PullBaseImageAsync( Authorization registryAuthorization, ProgressEventDispatcher progressEventDispatcher) { RegistryClient registryClient = buildConfiguration .NewBaseImageRegistryClientFactory() .SetAuthorization(registryAuthorization) .NewRegistryClient(); IManifestTemplate manifestTemplate = await registryClient.PullManifestAsync(buildConfiguration.GetBaseImageConfiguration().GetImageTag()).ConfigureAwait(false); // TODO: Make schema version be enum. switch (manifestTemplate.SchemaVersion) { case 1: V21ManifestTemplate v21ManifestTemplate = (V21ManifestTemplate)manifestTemplate; await buildConfiguration .GetBaseImageLayersCache() .WriteMetadataAsync( buildConfiguration.GetBaseImageConfiguration().GetImage(), v21ManifestTemplate).ConfigureAwait(false); return(JsonToImageTranslator.ToImage(v21ManifestTemplate)); case 2: IBuildableManifestTemplate buildableManifestTemplate = (IBuildableManifestTemplate)manifestTemplate; if (buildableManifestTemplate.GetContainerConfiguration() == null || buildableManifestTemplate.GetContainerConfiguration().Digest == null) { throw new UnknownManifestFormatException( "Invalid container configuration in Docker V2.2/OCI manifest: \n" + JsonTemplateMapper.ToUtf8String(buildableManifestTemplate)); } DescriptorDigest containerConfigurationDigest = buildableManifestTemplate.GetContainerConfiguration().Digest; using (ThrottledProgressEventDispatcherWrapper progressEventDispatcherWrapper = new ThrottledProgressEventDispatcherWrapper( progressEventDispatcher.NewChildProducer(), "pull container configuration " + containerConfigurationDigest)) { string containerConfigurationString = await Blobs.WriteToStringAsync( registryClient.PullBlob( containerConfigurationDigest, progressEventDispatcherWrapper.SetProgressTarget, progressEventDispatcherWrapper.DispatchProgress)).ConfigureAwait(false); ContainerConfigurationTemplate containerConfigurationTemplate = JsonTemplateMapper.ReadJson <ContainerConfigurationTemplate>( containerConfigurationString); await buildConfiguration .GetBaseImageLayersCache() .WriteMetadataAsync( buildConfiguration.GetBaseImageConfiguration().GetImage(), buildableManifestTemplate, containerConfigurationTemplate).ConfigureAwait(false); return(JsonToImageTranslator.ToImage( buildableManifestTemplate, containerConfigurationTemplate)); } } throw new InvalidOperationException(Resources.PullBaseImageStepUnknownManifestErrorMessage); }
public ManifestAndConfig( IManifestTemplate manifest, ContainerConfigurationTemplate config) { this.manifest = manifest; this.config = config; }