Beispiel #1
0
        public string GetNormalizedImageName()
        {
            // If DockerLoad option is used, the image must be set to the one used to build it
            if (!string.IsNullOrEmpty(DockerLoad))
            {
                return(DockerImageName);
            }

            if (!string.IsNullOrEmpty(DockerImageName))
            {
                // If the docker image name already starts with benchmarks, reuse it
                // This prefix is used to clean any dangling container that would not have been stopped automatically
                if (DockerImageName.StartsWith("benchmarks_"))
                {
                    return(DockerImageName);
                }
                else
                {
                    return($"benchmarks_{DockerImageName}".ToLowerInvariant());
                }
            }
            else
            {
                return($"benchmarks_{Path.GetFileNameWithoutExtension(DockerFile)}".ToLowerInvariant());
            }
        }
        private async Task PullImage(CancellationToken ct)
        {
            if (ct.IsCancellationRequested)
            {
                return;
            }

            // todo: write a test for this
            var images = await DockerClient.Images.ListImagesAsync(new ImagesListParameters(), ct);

            if (images.Any(image => image.RepoTags != null && image.RepoTags.Contains(DockerImageName)))
            {
                _logger.LogDebug("Image already exists, not pulling: {}", DockerImageName);
                return;
            }

            _logger.LogInformation("Pulling container image: {}", DockerImageName);
            var createParameters = new ImagesCreateParameters
            {
                FromImage = DockerImageName,
                Tag       = DockerImageName.Split(':').Last(),
            };

            await DockerClient.Images.CreateImageAsync(
                createParameters,
                new AuthConfig(),
                new Progress <JSONMessage>(),
                ct);
        }