Beispiel #1
0
        private async Task <IEnumerable <string> > GetPathsToRebuildAsync(Subscription subscription)
        {
            // If the command is filtered with an OS type that does not match the OsType filter of the subscription,
            // then there are no images that need to be inspected.
            string osTypeRegexPattern = ManifestFilter.GetFilterRegexPattern(Options.FilterOptions.OsType);

            if (!string.IsNullOrEmpty(subscription.OsType) &&
                !Regex.IsMatch(subscription.OsType, osTypeRegexPattern, RegexOptions.IgnoreCase))
            {
                return(Enumerable.Empty <string>());
            }

            _loggerService.WriteMessage($"Processing subscription:  {subscription.Id}");

            string repoPath = await GetGitRepoPath(subscription);

            TempManifestOptions manifestOptions = new TempManifestOptions(Options.FilterOptions)
            {
                Manifest = Path.Combine(repoPath, subscription.Manifest.Path)
            };

            ManifestInfo manifest = ManifestInfo.Load(manifestOptions);

            ImageArtifactDetails imageArtifactDetails = await GetImageInfoForSubscriptionAsync(subscription, manifest);

            List <string> pathsToRebuild = new List <string>();

            IEnumerable <PlatformInfo> allPlatforms = manifest.GetAllPlatforms().ToList();

            foreach (RepoInfo repo in manifest.FilteredRepos)
            {
                IEnumerable <PlatformInfo> platforms = repo.FilteredImages
                                                       .SelectMany(image => image.FilteredPlatforms)
                                                       .Where(platform => !platform.IsInternalFromImage(platform.FinalStageFromImage));

                RepoData repoData = imageArtifactDetails.Repos
                                    .FirstOrDefault(s => s.Repo == repo.Name);

                foreach (PlatformInfo platform in platforms)
                {
                    pathsToRebuild.AddRange(GetPathsToRebuild(allPlatforms, platform, repoData));
                }
            }

            return(pathsToRebuild.Distinct().ToList());
        }
Beispiel #2
0
        private async Task <IEnumerable <string> > GetPathsToRebuildAsync(Subscription subscription)
        {
            // If the command is filtered with an OS type that does not match the OsType filter of the subscription,
            // then there are no images that need to be inspected.
            string osTypeRegexPattern = ManifestFilter.GetFilterRegexPattern(Options.FilterOptions.OsType);

            if (!String.IsNullOrEmpty(subscription.OsType) &&
                !Regex.IsMatch(subscription.OsType, osTypeRegexPattern, RegexOptions.IgnoreCase))
            {
                return(Enumerable.Empty <string>());
            }

            RepoData[] repos = await GetImageInfoForSubscriptionAsync(subscription);

            string repoPath = await GetGitRepoPath(subscription);

            TempManifestOptions manifestOptions = new TempManifestOptions(Options.FilterOptions)
            {
                Manifest = Path.Combine(repoPath, subscription.ManifestPath)
            };

            ManifestInfo manifest = ManifestInfo.Load(manifestOptions);

            List <string> pathsToRebuild = new List <string>();

            IEnumerable <PlatformInfo> allPlatforms = manifest.GetAllPlatforms().ToList();

            foreach (RepoInfo repo in manifest.FilteredRepos)
            {
                IEnumerable <PlatformInfo> platforms = repo.FilteredImages
                                                       .SelectMany(image => image.FilteredPlatforms);

                RepoData repoData = repos
                                    .FirstOrDefault(s => s.Repo == repo.Model.Name);

                foreach (var platform in platforms)
                {
                    if (repoData != null &&
                        repoData.Images != null &&
                        repoData.Images.TryGetValue(platform.DockerfilePathRelativeToManifest, out ImageData imageData))
                    {
                        bool hasDigestChanged = false;

                        foreach (string fromImage in platform.ExternalFromImages)
                        {
                            string currentDigest;

                            await this.imageDigestsSemaphore.WaitAsync();

                            try
                            {
                                if (!this.imageDigests.TryGetValue(fromImage, out currentDigest))
                                {
                                    this.dockerService.PullImage(fromImage, Options.IsDryRun);
                                    currentDigest = this.dockerService.GetImageDigest(fromImage, Options.IsDryRun);
                                    this.imageDigests.Add(fromImage, currentDigest);
                                }
                            }
                            finally
                            {
                                this.imageDigestsSemaphore.Release();
                            }

                            string lastDigest = null;
                            imageData.BaseImages?.TryGetValue(fromImage, out lastDigest);

                            if (lastDigest != currentDigest)
                            {
                                hasDigestChanged = true;
                                break;
                            }
                        }

                        if (hasDigestChanged)
                        {
                            IEnumerable <PlatformInfo> dependentPlatforms = platform.GetDependencyGraph(allPlatforms);
                            pathsToRebuild.AddRange(dependentPlatforms.Select(p => p.Model.Dockerfile));
                        }
                    }
                    else
                    {
                        this.loggerService.WriteMessage(
                            $"WARNING: Image info not found for '{platform.DockerfilePath}'. Adding path to build to be queued anyway.");
                        pathsToRebuild.Add(platform.Model.Dockerfile);
                    }
                }
            }

            return(pathsToRebuild.Distinct().ToList());
        }