public void PullImage(string image, bool isDryRun)
 {
     _pulledImages.GetOrAdd(image, _ =>
     {
         _inner.PullImage(image, isDryRun);
         return(true);
     });
 }
Esempio n. 2
0
        //This method is called when the program is started and makes sure to pull the image and prune unwanted containers
        //it then starts aTaskFactory to make a new thread which UpdateFromDocker runs on independently from the main thread
        //lastly it starts to listen for incoming messages in queue in the messagebroker specified by the queueName parameter
        public async Task Start(string queueName)
        {
            await _dockerService.PullImage();

            await _dockerService.PruneContainers();

            TaskFactory taskFactory = new TaskFactory();

            taskFactory.StartNew(UpdateFromDocker);
            ListenToQueue(queueName);
        }
Esempio n. 3
0
        private void CheckStatus()
        {
            IEnumerable <(string Tag, string Platform)> platformTags = Manifest.GetFilteredPlatforms()
                                                                       .Select(platform =>
            {
                // Find the last FROM image that's an external image. This is not the same as the last
                // ExternalFromImage because that could be the first FROM listed in the Dockerfile which is
                // not what we want.
                string?tag = platform.FinalStageFromImage is not null && platform.IsInternalFromImage(platform.FinalStageFromImage) ?
                             null : platform.FinalStageFromImage;
                return(Tag: tag, Platform: platform.PlatformLabel);
            })
                                                                       .Where(image => image.Tag != null)
                                                                       .Cast <(string, string)>()
                                                                       .Distinct()
                                                                       .ToList();

            _loggerService.WriteHeading("PULLING LATEST BASE IMAGES");
            foreach ((string Tag, string Platform)imageTag in platformTags)
            {
                _dockerService.PullImage(imageTag.Tag, imageTag.Platform, Options.IsDryRun);
            }

            _loggerService.WriteHeading("QUERYING STATUS");
            var statuses = platformTags
                           .Select(imageTag => new
            {
                Tag         = imageTag.Tag,
                DateCreated = _dockerService.GetCreatedDate(imageTag.Tag, Options.IsDryRun)
            })
                           .ToList();

            _loggerService.WriteHeading("BASE IMAGE STATUS SUMMARY");
            foreach (var status in statuses)
            {
                TimeSpan timeDiff = DateTime.Now - status.DateCreated;

                string days = string.Empty;
                // Use TotalDays so that years are represented in terms of days
                int totalDays = (int)timeDiff.TotalDays;
                if (totalDays > 0)
                {
                    days = $"{totalDays} days, ";
                }

                _loggerService.WriteSubheading(status.Tag);
                _loggerService.WriteMessage($"Created {days}{timeDiff.Minutes} minutes ago");
                _loggerService.WriteMessage();
            }
        }
Esempio n. 4
0
        public override Task ExecuteAsync()
        {
            IEnumerable <(string Tag, string Platform)> platformTags;

            if (string.IsNullOrEmpty(Options.ImageInfoPath))
            {
                platformTags = Manifest.GetFilteredPlatforms()
                               .Where(platform => platform.Tags.Any())
                               .Select(platform => (platform.Tags.First().FullyQualifiedName, platform.PlatformLabel));
            }
            else
            {
                // We want to apply manifest filtering to the loading of the image info file. This allows, for example,
                // only images of a specific architecture to be pulled.
                ImageArtifactDetails imageArtifactDetails = ImageInfoHelper.LoadFromFile(
                    Options.ImageInfoPath, Manifest, skipManifestValidation: true, useFilteredManifest: true);
                platformTags = imageArtifactDetails.Repos
                               .SelectMany(repo => repo.Images)
                               .SelectMany(image => image.Platforms)
                               // If the platform doesn't have an associated manifest instance, it means the manifest filter
                               // options had filtered out the platform. In that case, it doesn't apply and shouldn't be pulled.
                               .Where(platform => platform.PlatformInfo is not null && platform.SimpleTags.Any())
                               .Select(platform => (
                                           TagInfo.GetFullyQualifiedName(platform.PlatformInfo !.FullRepoModelName, platform.SimpleTags.First()),
                                           platform.PlatformInfo !.PlatformLabel));
            }

            platformTags = platformTags
                           .Distinct()
                           .ToList();

            _loggerService.WriteHeading("PULLING IMAGES");
            foreach ((string tag, string platform) in platformTags)
            {
                _dockerService.PullImage(tag, platform, Options.IsDryRun);
            }

            if (Options.OutputVariableName is not null)
            {
                _loggerService.WriteMessage(
                    PipelineHelper.FormatOutputVariable(
                        Options.OutputVariableName,
                        string.Join(',', platformTags.Select(platformTag => platformTag.Tag))));
            }

            return(Task.CompletedTask);
        }
Esempio n. 5
0
        public static void PullBaseImages(this IDockerService dockerService, ManifestInfo manifest, bool isDryRun)
        {
            Logger.WriteHeading("PULLING LATEST BASE IMAGES");
            IEnumerable <string> baseImages = manifest.GetExternalFromImages().ToArray();

            if (baseImages.Any())
            {
                foreach (string fromImage in baseImages)
                {
                    dockerService.PullImage(fromImage, isDryRun);
                }
            }
            else
            {
                Logger.WriteMessage("No external base images to pull");
            }
        }