Ejemplo n.º 1
0
        public async Task TestTag_fail()
        {
            DockerClient testDockerClient =
                new DockerClient(
                    subcommand =>
            {
                Assert.AreEqual(new[] { "tag", "original", "new" }, subcommand);
                return(mockProcessBuilder);
            });

            Mock.Get(mockProcess).Setup(m => m.WaitFor()).Returns(1);

            Mock.Get(mockProcess).Setup(m => m.GetErrorStream()).Returns(new MemoryStream(Encoding.UTF8.GetBytes("error")));

            try
            {
                ImageReference originalImageReference = ImageReference.Of(null, "original", null);
                ImageReference newImageReference      = ImageReference.Parse("new");
                await testDockerClient.TagAsync(originalImageReference, newImageReference).ConfigureAwait(false);

                Assert.Fail("docker tag should have failed");
            }
            catch (IOException ex)
            {
                Assert.AreEqual("'docker tag' command failed with error: error", ex.Message);
            }
        }
Ejemplo n.º 2
0
        public async Task TestTag()
        {
            DockerClient testDockerClient =
                new DockerClient(
                    subcommand =>
            {
                Assert.AreEqual(new[] { "tag", "original", "new" }, subcommand);
                return(mockProcessBuilder);
            });

            Mock.Get(mockProcess).Setup(m => m.WaitFor()).Returns(0);

            ImageReference originalImageReference = ImageReference.Of(null, "original", null);
            ImageReference newImageReference      = ImageReference.Parse("new");
            await testDockerClient.TagAsync(originalImageReference, newImageReference).ConfigureAwait(false);
        }
Ejemplo n.º 3
0
        public async Task <BuildResult> CallAsync()
        {
            await pullAndCacheBaseImageLayersStep.GetFuture().ConfigureAwait(false);

            await buildAndCacheApplicationLayersStep.GetFuture().ConfigureAwait(false);

            await buildImageStep.GetFuture().ConfigureAwait(false);

            buildConfiguration
            .GetEventHandlers()
            .Dispatch(LogEvent.Progress(Resources.LoadDockerStepDescription));

            using (progressEventDispatcherFactory.Create(Resources.LoadDockerStepDescription, 1))
            {
                Image image = await buildImageStep.GetFuture().ConfigureAwait(false);

                IImageReference targetImageReference =
                    buildConfiguration.GetTargetImageConfiguration().GetImage();

                // Load the image to docker daemon.
                buildConfiguration
                .GetEventHandlers()
                .Dispatch(
                    LogEvent.Debug(await dockerClient.LoadAsync(new ImageTarball(image, targetImageReference)).ConfigureAwait(false)));

                // Tags the image with all the additional tags, skipping the one 'docker load' already loaded.
                foreach (string tag in buildConfiguration.GetAllTargetImageTags())
                {
                    if (tag.Equals(targetImageReference.GetTag(), StringComparison.Ordinal))
                    {
                        continue;
                    }

                    ImageReference taggedImageReference = targetImageReference.WithTag(tag);
                    await dockerClient.TagAsync(targetImageReference, taggedImageReference).ConfigureAwait(false);
                }

                return(await BuildResult.FromImageAsync(image, buildConfiguration.GetTargetFormat()).ConfigureAwait(false));
            }
        }