WriteMessage() public static method

public static WriteMessage ( ) : void
return void
Beispiel #1
0
        private static Process ExecuteWithRetry(ProcessStartInfo info, Func <ProcessStartInfo, Process> executor)
        {
            const int maxRetries = 5;
            const int waitFactor = 5;

            int retryCount = 0;

            Process process = executor(info);

            while (process.ExitCode != 0)
            {
                retryCount++;
                if (retryCount >= maxRetries)
                {
                    break;
                }

                int waitTime = Convert.ToInt32(Math.Pow(waitFactor, retryCount - 1));
                Logger.WriteMessage($"Retry {retryCount}/{maxRetries}, retrying in {waitTime} seconds...");
                Thread.Sleep(waitTime * 1000);
                process = executor(info);
            }

            return(process);
        }
Beispiel #2
0
        public static void PullBaseImages(ManifestInfo manifest, Options options)
        {
            Logger.WriteHeading("PULLING LATEST BASE IMAGES");
            IEnumerable <string> baseImages = manifest.GetExternalFromImages().ToArray();

            if (baseImages.Any())
            {
                foreach (string fromImage in baseImages)
                {
                    ExecuteHelper.ExecuteWithRetry("docker", $"pull {fromImage}", options.IsDryRun);
                }
            }
            else
            {
                Logger.WriteMessage("No external base images to pull");
            }
        }
Beispiel #3
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");
            }
        }
Beispiel #4
0
        public static async Task ExecuteGitOperationsWithRetryAsync(Func <Task> execute,
                                                                    int maxTries = DefaultMaxTries, int retryMillisecondsDelay = DefaultRetryMillisecondsDelay)
        {
            for (int i = 0; i < maxTries; i++)
            {
                try
                {
                    await execute();

                    break;
                }
                catch (HttpRequestException ex) when(i < (maxTries - 1))
                {
                    Logger.WriteMessage($"Encountered exception interacting with GitHub: {ex.Message}");
                    Logger.WriteMessage($"Trying again in {retryMillisecondsDelay}ms. {maxTries - i - 1} tries left.");
                    await Task.Delay(retryMillisecondsDelay);
                }
            }
        }
Beispiel #5
0
        public static async Task <GitReference> PushChangesAsync(IGitHubClient client, IGitOptionsHost options, string commitMessage, Func <GitHubBranch, Task <IEnumerable <GitObject> > > getChanges)
        {
            GitOptions    gitOptions = options.GitOptions;
            GitHubProject project    = new GitHubProject(gitOptions.Repo, gitOptions.Owner);
            GitHubBranch  branch     = new GitHubBranch(gitOptions.Branch, project);

            IEnumerable <GitObject> changes = await getChanges(branch);

            if (!changes.Any())
            {
                return(null);
            }

            string       masterRef     = $"heads/{gitOptions.Branch}";
            GitReference currentMaster = await client.GetReferenceAsync(project, masterRef);

            string masterSha = currentMaster.Object.Sha;

            if (!options.IsDryRun)
            {
                GitTree tree = await client.PostTreeAsync(project, masterSha, changes.ToArray());

                GitCommit commit = await client.PostCommitAsync(
                    project, commitMessage, tree.Sha, new[] { masterSha });

                // Only fast-forward. Don't overwrite other changes: throw exception instead.
                return(await client.PatchReferenceAsync(project, masterRef, commit.Sha, force : false));
            }
            else
            {
                Logger.WriteMessage($"The following files would have been updated at {gitOptions.Owner}/{gitOptions.Repo}/{gitOptions.Branch}:");
                Logger.WriteMessage();
                foreach (GitObject gitObject in changes)
                {
                    Logger.WriteMessage($"{gitObject.Path}:");
                    Logger.WriteMessage(gitObject.Content);
                    Logger.WriteMessage();
                }

                return(null);
            }
        }
        private string Execute()
        {
            Logger.WriteHeading("GENERATING MCR TAGS METADATA");

            _imageDocInfos = _repo.FilteredImages
                             .SelectMany(image =>
                                         image.AllPlatforms.SelectMany(platform => ImageDocumentationInfo.Create(image, platform)))
                             .Where(info => info.DocumentedTags.Any())
                             .ToList();

            StringBuilder yaml = new StringBuilder();

            yaml.AppendLine("repos:");

            string templatePath = Path.Combine(_manifest.Directory, _repo.Model.McrTagsMetadataTemplate);

            string template = File.ReadAllText(templatePath);

            yaml.Append(_manifest.VariableHelper.SubstituteValues(template, GetVariableValue));

            if (_imageDocInfos.Any())
            {
                string missingTags = string.Join(
                    Environment.NewLine, _imageDocInfos.Select(info => info.FormattedDocumentedTags));
                throw new InvalidOperationException(
                          $"The following tags are not included in the tags metadata: {Environment.NewLine}{missingTags}");
            }

            string metadata = yaml.ToString();

            Logger.WriteSubheading("Generated Metadata:");
            Logger.WriteMessage(metadata);

            // Validate that the YAML is in a valid format
            new DeserializerBuilder()
            .WithNamingConvention(CamelCaseNamingConvention.Instance)
            .Build()
            .Deserialize <TagsMetadata>(metadata);

            return(metadata);
        }
        public static string GetOSDisplayName(PlatformInfo platform)
        {
            string displayName;
            string os = platform.Model.OsVersion;

            Logger.WriteMessage($"os: {os}");
            Logger.WriteMessage($"osType: {platform.Model.OS}");

            if (platform.Model.OS == OS.Windows)
            {
                if (os.Contains("2016"))
                {
                    displayName = "Windows Server 2016";
                }
                else if (os.Contains("2019") || os.Contains("1809"))
                {
                    displayName = "Windows Server 2019";
                }
                else
                {
                    string version = os.Split('-')[1];
                    displayName = $"Windows Server, version {version}";
                }
            }
            else
            {
                if (os.Contains("jessie"))
                {
                    displayName = "Debian 8";
                }
                else if (os.Contains("stretch"))
                {
                    displayName = "Debian 9";
                }
                else if (os.Contains("buster"))
                {
                    displayName = "Debian 10";
                }
                else if (os.Contains("bionic"))
                {
                    displayName = "Ubuntu 18.04";
                }
                else if (os.Contains("disco"))
                {
                    displayName = "Ubuntu 19.04";
                }
                else if (os.Contains("focal"))
                {
                    displayName = "Ubuntu 20.04";
                }
                else if (os.Contains("alpine"))
                {
                    int versionIndex = os.IndexOfAny(new char[] { '1', '2', '3', '4', '5', '6', '7', '8', '9', '0' });
                    if (versionIndex != -1)
                    {
                        os = os.Insert(versionIndex, " ");
                    }

                    displayName = os.FirstCharToUpper();
                }
                else
                {
                    throw new InvalidOperationException($"The OS version '{os}' is not supported.");
                }
            }

            return(displayName);
        }
Beispiel #8
0
 public void WriteMessage(string message)
 {
     Logger.WriteMessage(message);
 }
Beispiel #9
0
 public void WriteMessage()
 {
     Logger.WriteMessage();
 }