コード例 #1
0
        private bool Run(Options options)
        {
            var fragmentDirectory           = Path.GetFullPath(Path.Combine(FindRoot("contrib"), "..", "docker-compose-generator", "docker-fragments"));
            List <Task <bool> > downloading = new List <Task <bool> >();
            List <DockerInfo>   dockerInfos = new List <DockerInfo>();

            foreach (var image in new[]
            {
                Image.Parse("btcpayserver/docker-compose-generator"),
                Image.Parse("btcpayserver/docker-compose-builder:1.23.2"),
            }.Concat(GetImages(fragmentDirectory)))
            {
                Console.WriteLine($"Image: {image.ToString()}");
                var info = GetDockerInfo(image);
                if (info == null)
                {
                    Console.WriteLine($"Missing image info: {image}");
                    return(false);
                }
                dockerInfos.Add(info);
                downloading.Add(CheckLink(info, info.DockerFilePath));
                downloading.Add(CheckLink(info, info.DockerFilePathARM32v7));
                downloading.Add(CheckLink(info, info.DockerFilePathARM64v8));
            }

            Task.WaitAll(downloading.ToArray());
            var canDownloadEverything = downloading.All(o => o.Result);

            if (!canDownloadEverything)
            {
                return(false);
            }
            var builder = new StringBuilderEx();

            builder.AppendLine("#!/bin/bash");
            builder.AppendLine();
            builder.AppendLine("# This file is automatically generated by the DockerFileBuildHelper tool, run DockerFileBuildHelper/update-repo.sh to update it");
            builder.AppendLine("set -e");
            builder.AppendLine("DOCKERFILE=\"\"");
            builder.AppendLine();
            builder.AppendLine();
            foreach (var info in dockerInfos)
            {
                builder.AppendLine($"# Build {info.Image.Name}");
                bool mightBeUnavailable = false;
                if (info.DockerFilePath != null)
                {
                    var dockerFile = DockerFile.Parse(info.DockerFilePath);
                    builder.AppendLine($"# {info.GetGithubLinkOf(dockerFile.DockerFullPath)}");
                    builder.AppendLine($"DOCKERFILE=\"{dockerFile.DockerFullPath}\"");
                }
                else
                {
                    builder.AppendLine($"DOCKERFILE=\"\"");
                    mightBeUnavailable = true;
                }
                if (info.DockerFilePathARM32v7 != null)
                {
                    var dockerFile = DockerFile.Parse(info.DockerFilePathARM32v7);
                    builder.AppendLine($"# {info.GetGithubLinkOf(dockerFile.DockerFullPath)}");
                    builder.AppendLine($"[[ \"$(uname -m)\" == \"armv7l\" ]] && DOCKERFILE=\"{dockerFile.DockerFullPath}\"");
                }
                if (info.DockerFilePathARM64v8 != null)
                {
                    var dockerFile = DockerFile.Parse(info.DockerFilePathARM64v8);
                    builder.AppendLine($"# {info.GetGithubLinkOf(dockerFile.DockerFullPath)}");
                    builder.AppendLine($"[[ \"$(uname -m)\" == \"aarch64\" ]] && DOCKERFILE=\"{dockerFile.DockerFullPath}\"");
                }
                if (mightBeUnavailable)
                {
                    builder.AppendLine($"if [[ \"$DOCKERFILE\" ]]; then");
                    builder.Indent++;
                }
                builder.AppendLine($"echo \"Building {info.Image.ToString()}\"");
                builder.AppendLine($"git clone {info.GitLink} {info.Image.Name}");
                builder.AppendLine($"cd {info.Image.Name}");
                builder.AppendLine($"git checkout {info.GitRef}");
                builder.AppendLine($"cd \"$(dirname $DOCKERFILE)\"");
                builder.AppendLine($"docker build -f \"$DOCKERFILE\" -t \"{info.Image}\" .");
                builder.AppendLine($"cd - && cd ..");
                if (mightBeUnavailable)
                {
                    builder.Indent--;
                    builder.AppendLine($"fi");
                }
                builder.AppendLine();
                builder.AppendLine();
            }
            var script = builder.ToString().Replace("\r\n", "\n");

            if (string.IsNullOrEmpty(options.BuildAllScriptOutput))
            {
                options.BuildAllScriptOutput = "build-all.sh";
            }
            File.WriteAllText(options.BuildAllScriptOutput, script);
            Console.WriteLine($"Generated file \"{Path.GetFullPath(options.BuildAllScriptOutput)}\"");

            if (!string.IsNullOrEmpty(options.READMEOutput))
            {
                var readme = File.ReadAllText(options.READMEOutput);
                var start  = readme.IndexOf("| Source |");
                var end    = start;
                for (; end < readme.Length; end++)
                {
                    if (readme[end] == '\r' && readme[end + 1] == '\n' && readme[end + 2] != '|')
                    {
                        end += 2;
                        break;
                    }
                    if (readme[end] == '\n' && readme[end + 1] != '|')
                    {
                        end += 1;
                        break;
                    }
                }

                StringBuilder tb = new StringBuilder();
                tb.Append(readme.Substring(0, start));
                tb.AppendLine("| Source | Image | Version | x64 | arm32v7 | links |");
                tb.AppendLine("|---|---|---|:-:|:-:|:-:|");
                dockerInfos = dockerInfos.OrderBy(i => i.Image.Source).ToList();

                // Make sure bitcoin appears before shitcoin
                PushToEnd(2, dockerInfos);
                PushToEnd(2, dockerInfos);
                PushToEnd(7, dockerInfos);
                PushToEnd(7, dockerInfos);

                foreach (var image in dockerInfos)
                {
                    string source = "*";
                    if (image.Image.Source != null)
                    {
                        source = Path.GetFileName(image.Image.Source);
                    }
                    tb.Append($"| {source} | {image.Image.ToString(false)} | {image.Image.Tag} |");
                    if (!string.IsNullOrEmpty(image.DockerFilePath))
                    {
                        tb.Append($" [✔️]({image.GetGithubLinkOf(image.DockerFilePath)}) |");
                    }
                    else
                    {
                        tb.Append($" ️❌ |");
                    }
                    if (!string.IsNullOrEmpty(image.DockerFilePathARM32v7))
                    {
                        tb.Append($" [✔️]({image.GetGithubLinkOf(image.DockerFilePathARM32v7)}) |");
                    }
                    else
                    {
                        tb.Append($" ️❌ |");
                    }
                    tb.AppendLine($" [Github]({image.GitLink}) - [DockerHub]({image.DockerHubLink}) |");
                }
                tb.Append(readme.Substring(end));
                File.WriteAllText(options.READMEOutput, tb.ToString());
            }


            return(true);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: vswee/btcpayserver-docker
        private bool Run(string outputFile)
        {
            var fragmentDirectory           = Path.GetFullPath(Path.Combine(FindRoot("contrib"), "..", "docker-compose-generator", "docker-fragments"));
            List <Task <bool> > downloading = new List <Task <bool> >();
            List <DockerInfo>   dockerInfos = new List <DockerInfo>();

            foreach (var image in new[]
            {
                Image.Parse("btcpayserver/docker-compose-generator"),
                Image.Parse("btcpayserver/docker-compose-builder:1.23.2"),
            }.Concat(GetImages(fragmentDirectory)))
            {
                Console.WriteLine($"Image: {image.ToString()}");
                var info = GetDockerInfo(image);
                if (info == null)
                {
                    Console.WriteLine($"Missing image info: {image}");
                    return(false);
                }
                dockerInfos.Add(info);
                downloading.Add(CheckLink(info, info.DockerFilePath));
                downloading.Add(CheckLink(info, info.DockerFilePathARM32v7));
                downloading.Add(CheckLink(info, info.DockerFilePathARM64v8));
            }

            Task.WaitAll(downloading.ToArray());
            var canDownloadEverything = downloading.All(o => o.Result);

            if (!canDownloadEverything)
            {
                return(false);
            }
            var builder = new StringBuilderEx();

            builder.AppendLine("#!/bin/bash");
            builder.AppendLine();
            builder.AppendLine("# This file is automatically generated by the DockerFileBuildHelper tool, run DockerFileBuildHelper/update-repo.sh to update it");
            builder.AppendLine("set -e");
            builder.AppendLine("DOCKERFILE=\"\"");
            builder.AppendLine();
            builder.AppendLine();
            foreach (var info in dockerInfos)
            {
                builder.AppendLine($"# Build {info.Image.Name}");
                bool mightBeUnavailable = false;
                if (info.DockerFilePath != null)
                {
                    var dockerFile = DockerFile.Parse(info.DockerFilePath);
                    builder.AppendLine($"# {info.GetGithubLinkOf(dockerFile.DockerFullPath)}");
                    builder.AppendLine($"DOCKERFILE=\"{dockerFile.DockerFullPath}\"");
                }
                else
                {
                    builder.AppendLine($"DOCKERFILE=\"\"");
                    mightBeUnavailable = true;
                }
                if (info.DockerFilePathARM32v7 != null)
                {
                    var dockerFile = DockerFile.Parse(info.DockerFilePathARM32v7);
                    builder.AppendLine($"# {info.GetGithubLinkOf(dockerFile.DockerFullPath)}");
                    builder.AppendLine($"[[ \"$(uname -m)\" == \"armv7l\" ]] && DOCKERFILE=\"{dockerFile.DockerFullPath}\"");
                }
                if (info.DockerFilePathARM64v8 != null)
                {
                    var dockerFile = DockerFile.Parse(info.DockerFilePathARM64v8);
                    builder.AppendLine($"# {info.GetGithubLinkOf(dockerFile.DockerFullPath)}");
                    builder.AppendLine($"[[ \"$(uname -m)\" == \"aarch64\" ]] && DOCKERFILE=\"{dockerFile.DockerFullPath}\"");
                }
                if (mightBeUnavailable)
                {
                    builder.AppendLine($"if [[ \"$DOCKERFILE\" ]]; then");
                    builder.Indent++;
                }
                builder.AppendLine($"echo \"Building {info.Image.ToString()}\"");
                builder.AppendLine($"git clone {info.GitLink} {info.Image.Name}");
                builder.AppendLine($"cd {info.Image.Name}");
                builder.AppendLine($"git checkout {info.GitRef}");
                builder.AppendLine($"cd \"$(dirname $DOCKERFILE)\"");
                builder.AppendLine($"docker build -f \"$DOCKERFILE\" -t \"{info.Image}\" .");
                builder.AppendLine($"cd - && cd ..");
                if (mightBeUnavailable)
                {
                    builder.Indent--;
                    builder.AppendLine($"fi");
                }
                builder.AppendLine();
                builder.AppendLine();
            }
            var script = builder.ToString().Replace("\r\n", "\n");

            if (string.IsNullOrEmpty(outputFile))
            {
                outputFile = "build-all.sh";
            }
            File.WriteAllText(outputFile, script);
            Console.WriteLine($"Generated file \"{Path.GetFullPath(outputFile)}\"");
            return(true);
        }