Exemplo n.º 1
0
        public async Task <BuildResult> CallAsync()
        {
            IReadOnlyList <BlobDescriptor> baseImageDescriptors = await pushBaseImageLayersStep.GetFuture().ConfigureAwait(false);

            IReadOnlyList <BlobDescriptor> appLayerDescriptors = await pushApplicationLayersStep.GetFuture().ConfigureAwait(false);

            BlobDescriptor containerConfigurationBlobDescriptor = await pushContainerConfigurationStep.GetFuture().ConfigureAwait(false);

            ImmutableHashSet <string> targetImageTags = buildConfiguration.GetAllTargetImageTags();


            using (var progressEventDispatcher =
                       progressEventDispatcherFactory.Create("pushing image manifest", this.Index))
                using (var factory =
                           progressEventDispatcher.NewChildProducer()("[child progress]pushing image manifest", targetImageTags.Count))
                    using (TimerEventDispatcher ignored =
                               new TimerEventDispatcher(buildConfiguration.GetEventHandlers(), DESCRIPTION))
                    {
                        RegistryClient registryClient =
                            buildConfiguration
                            .NewTargetImageRegistryClientFactory()
                            .SetAuthorization(await authenticatePushStep.GetFuture().ConfigureAwait(false))
                            .NewRegistryClient();

                        // Constructs the image.
                        ImageToJsonTranslator imageToJsonTranslator =
                            new ImageToJsonTranslator(await buildImageStep.GetFuture().ConfigureAwait(false));

                        // Gets the image manifest to push.
                        IBuildableManifestTemplate manifestTemplate =
                            imageToJsonTranslator.GetManifestTemplate(
                                buildConfiguration.GetTargetFormat(), containerConfigurationBlobDescriptor);

                        // Pushes to all target image tags.
                        IList <Task <DescriptorDigest> > pushAllTagsFutures = new List <Task <DescriptorDigest> >();
                        var idx = 0;
                        ProgressEventDispatcher.Factory progressEventDispatcherFactory =
                            factory.NewChildProducer();
                        foreach (string tag in targetImageTags)
                        {
                            idx++;
                            using (progressEventDispatcherFactory.Create("tagging with " + tag, idx))
                            {
                                buildConfiguration.GetEventHandlers().Dispatch(LogEvent.Info("Tagging with " + tag + "..."));
                                pushAllTagsFutures.Add(registryClient.PushManifestAsync(manifestTemplate, tag));
                            }
                        }

                        DescriptorDigest imageDigest =
                            await Digests.ComputeJsonDigestAsync(manifestTemplate).ConfigureAwait(false);

                        DescriptorDigest imageId = containerConfigurationBlobDescriptor.GetDigest();
                        BuildResult      result  = new BuildResult(imageDigest, imageId);

                        await Task.WhenAll(pushAllTagsFutures).ConfigureAwait(false);

                        return(result);
                    }
        }
        /** Tests translation of image to {@link BuildableManifestTemplate}. */
        private async Task TestGetManifestAsync(
            ManifestFormat manifestTemplateClass, string translatedJsonFilename)
        {
            // Loads the expected JSON string.
            SystemPath jsonFile     = Paths.Get(TestResources.GetResource(translatedJsonFilename).ToURI());
            string     expectedJson = Encoding.UTF8.GetString(Files.ReadAllBytes(jsonFile));

            // Translates the image to the manifest and writes the JSON string.
            ContainerConfigurationTemplate containerConfiguration = imageToJsonTranslator.GetContainerConfiguration();
            BlobDescriptor blobDescriptor = await Digests.ComputeJsonDescriptorAsync(containerConfiguration).ConfigureAwait(false);

            IBuildableManifestTemplate manifestTemplate =
                imageToJsonTranslator.GetManifestTemplate(manifestTemplateClass, blobDescriptor);

            Assert.AreEqual(expectedJson, JsonTemplateMapper.ToUtf8String(manifestTemplate));
        }
Exemplo n.º 3
0
        /**
         * Gets a {@link BuildResult} from an {@link Image}.
         *
         * @param image the image
         * @param targetFormat the target format of the image
         * @return a new {@link BuildResult} with the image's digest and id
         * @throws IOException if writing the digest or container configuration fails
         */
        public static async Task <BuildResult> FromImageAsync(Image image, ManifestFormat targetFormat)
        {
            ImageToJsonTranslator          imageToJsonTranslator = new ImageToJsonTranslator(image);
            ContainerConfigurationTemplate configurationTemplate = imageToJsonTranslator.GetContainerConfiguration();
            BlobDescriptor containerConfigurationBlobDescriptor  =
                await Digests.ComputeJsonDescriptorAsync(configurationTemplate).ConfigureAwait(false);

            IBuildableManifestTemplate manifestTemplate =
                imageToJsonTranslator.GetManifestTemplate(
                    targetFormat, containerConfigurationBlobDescriptor);
            DescriptorDigest imageDigest =
                await Digests.ComputeJsonDigestAsync(manifestTemplate).ConfigureAwait(false);

            DescriptorDigest imageId = containerConfigurationBlobDescriptor.GetDigest();

            return(new BuildResult(imageDigest, imageId));
        }