static void Main(string[] args) { var root = Environment.GetEnvironmentVariable("INSIDE_CONTAINER") == "1" ? FindRoot("app") : Path.GetFullPath(Path.Combine(FindRoot("docker-compose-generator"), "..")); var composition = DockerComposition.FromEnvironmentVariables(); Console.WriteLine("Crypto: " + string.Join(", ", composition.SelectedCryptos.ToArray())); Console.WriteLine("Lightning: " + composition.SelectedLN); Console.WriteLine("ReverseProxy: " + composition.SelectedProxy); var generatedLocation = Path.GetFullPath(Path.Combine(root, "Generated")); var name = Environment.GetEnvironmentVariable("BTCPAYGEN_SUBNAME"); name = string.IsNullOrEmpty(name) ? "generated" : name; try { new Program().Run(composition, name, generatedLocation); } catch (YamlBuildException ex) { ConsoleUtils.WriteLine(ex.Message, ConsoleColor.Red); Environment.ExitCode = 1; } }
private void Run(DockerComposition composition, string name, string output) { var fragmentLocation = Environment.GetEnvironmentVariable("INSIDE_CONTAINER") == "1" ? "app" : "docker-compose-generator"; fragmentLocation = FindRoot(fragmentLocation); fragmentLocation = Path.GetFullPath(Path.Combine(fragmentLocation, "docker-fragments")); var fragments = new HashSet <string>(); switch (composition.SelectedProxy) { case "nginx": fragments.Add("nginx"); fragments.Add("btcpayserver-nginx"); break; case "traefik": fragments.Add("traefik"); fragments.Add("traefik-labels"); break; case "no-reverseproxy": case "none": case "": fragments.Add("btcpayserver-noreverseproxy"); break; } fragments.Add("btcpayserver"); fragments.Add("nbxplorer"); fragments.Add("postgres"); foreach (var crypto in CryptoDefinition.GetDefinitions()) { if (!composition.SelectedCryptos.Contains(crypto.Crypto)) { continue; } fragments.Add(crypto.CryptoFragment); if (composition.SelectedLN == "clightning" && crypto.CLightningFragment != null) { fragments.Add(crypto.CLightningFragment); } if (composition.SelectedLN == "lnd" && crypto.LNDFragment != null) { fragments.Add(crypto.LNDFragment); } } foreach (var fragment in composition.AdditionalFragments) { fragments.Add(fragment.Trim()); } fragments = fragments.Where(s => !composition.ExcludeFragments.Contains(s)).ToHashSet(); var def = new DockerComposeDefinition(name, fragments.ToList()); def.FragmentLocation = fragmentLocation; def.BuildOutputDirectory = output; def.Build(); }
public static DockerComposition FromEnvironmentVariables() { DockerComposition composition = new DockerComposition(); composition.SelectedCryptos = new HashSet <string>(); for (int i = 1; i < 10; i++) { var selectedCrypto = Environment.GetEnvironmentVariable("BTCPAYGEN_CRYPTO" + i); if (string.IsNullOrEmpty(selectedCrypto)) { continue; } composition.SelectedCryptos.Add(selectedCrypto.ToLowerInvariant()); } composition.SelectedProxy = (Environment.GetEnvironmentVariable("BTCPAYGEN_REVERSEPROXY") ?? "").ToLowerInvariant(); composition.SelectedLN = (Environment.GetEnvironmentVariable("BTCPAYGEN_LIGHTNING") ?? "").ToLowerInvariant(); composition.AdditionalFragments = (Environment.GetEnvironmentVariable("BTCPAYGEN_ADDITIONAL_FRAGMENTS") ?? "").ToLowerInvariant() .Split(new char[] { ';', ',' }) .Where(t => !string.IsNullOrWhiteSpace(t)) .Select(t => t.EndsWith(".yml") ? t.Substring(0, t.Length - ".yml".Length) : t) .ToArray(); composition.ExcludeFragments = (Environment.GetEnvironmentVariable("BTCPAYGEN_EXCLUDE_FRAGMENTS") ?? "").ToLowerInvariant() .Split(new char[] { ';', ',' }) .Where(t => !string.IsNullOrWhiteSpace(t)) .Select(t => t.EndsWith(".yml") ? t.Substring(0, t.Length - ".yml".Length) : t) .ToArray(); return(composition); }
static void Main(string[] args) { var root = Environment.GetEnvironmentVariable("INSIDE_CONTAINER") == "1" ? FindRoot("app") : Path.GetFullPath(Path.Combine(FindRoot("docker-compose-generator"), "..")); if (args.Any(a => a == "pregen")) { var productionLocation = Path.GetFullPath(Path.Combine(root, "Production")); var testLocation = Path.GetFullPath(Path.Combine(root, "Production-NoReverseProxy")); foreach (var proxy in new[] { "nginx", "no-reverseproxy" }) { foreach (var lightning in new[] { "clightning", "" }) { foreach (var btc in new[] { "btc", "" }) { foreach (var ltc in new[] { "ltc", "" }) { if (btc == "" && ltc == "") { continue; } string name = $"{btc}-{ltc}-{lightning}".Replace("--", "-"); if (name.EndsWith("-")) { name = name.Substring(0, name.Length - 1); } if (name.StartsWith("-")) { name = name.Substring(1, name.Length - 1); } var composition = new DockerComposition(); composition.SelectedCryptos = new HashSet <string>(); composition.SelectedCryptos.Add(btc); composition.SelectedCryptos.Add(ltc); composition.SelectedLN = lightning; composition.SelectedProxy = proxy; new Program().Run(composition, name, proxy == "nginx" ? productionLocation : testLocation); } } } } } else { var composition = DockerComposition.FromEnvironmentVariables(); Console.WriteLine("Crypto: " + string.Join(", ", composition.SelectedCryptos.ToArray())); Console.WriteLine("Lightning: " + composition.SelectedLN); Console.WriteLine("ReverseProxy: " + composition.SelectedProxy); var generatedLocation = Path.GetFullPath(Path.Combine(root, "Generated")); var name = Environment.GetEnvironmentVariable("BTCPAYGEN_SUBNAME"); name = string.IsNullOrEmpty(name) ? "generated" : name; new Program().Run(composition, name, generatedLocation); } }
private void Run(DockerComposition composition, string name, string output) { var fragmentLocation = Environment.GetEnvironmentVariable("INSIDE_CONTAINER") == "1" ? "app" : "docker-compose-generator"; fragmentLocation = FindRoot(fragmentLocation); fragmentLocation = Path.GetFullPath(Path.Combine(fragmentLocation, "docker-fragments")); var fragments = new List <string>(); if (composition.SelectedProxy == "nginx") { fragments.Add("nginx"); } else { fragments.Add("btcpayserver-noreverseproxy"); } fragments.Add("btcpayserver"); foreach (var crypto in CryptoDefinition.GetDefinitions()) { if (!composition.SelectedCryptos.Contains(crypto.Crypto)) { continue; } fragments.Add(crypto.CryptoFragment); if (composition.SelectedLN == "clightning" && crypto.CLightningFragment != null) { fragments.Add(crypto.CLightningFragment); } if (composition.SelectedLN == "lnd" && crypto.LNDFragment != null) { fragments.Add(crypto.LNDFragment); } } foreach (var fragment in composition.AdditionalFragments) { fragments.Add(fragment.Trim()); } var def = new DockerComposeDefinition(name, fragments); def.FragmentLocation = fragmentLocation; def.BuildOutputDirectory = output; def.Build(); }
public static DockerComposition FromEnvironmentVariables() { DockerComposition composition = new DockerComposition(); composition.SelectedCryptos = new HashSet <string>(); for (int i = 1; i < 10; i++) { var selectedCrypto = Environment.GetEnvironmentVariable("BTCPAYGEN_CRYPTO" + i); if (string.IsNullOrEmpty(selectedCrypto)) { continue; } composition.SelectedCryptos.Add(selectedCrypto.ToLowerInvariant()); } composition.SelectedProxy = (Environment.GetEnvironmentVariable("BTCPAYGEN_REVERSEPROXY") ?? "").ToLowerInvariant(); composition.SelectedLN = (Environment.GetEnvironmentVariable("BTCPAYGEN_LIGHTNING") ?? "").ToLowerInvariant(); return(composition); }
private void Run(DockerComposition composition, string name, string output) { var root = Environment.GetEnvironmentVariable("INSIDE_CONTAINER") == "1" ? "app" : "docker-compose-generator"; root = FindRoot(root); var fragmentLocation = Path.GetFullPath(Path.Combine(root, "docker-fragments")); var cryptoDefinitionsLocation = Path.GetFullPath(Path.Combine(root, "crypto-definitions.json")); var cryptoDefinitions = JsonSerializer.Deserialize <CryptoDefinition[]>(File.ReadAllText(cryptoDefinitionsLocation)); var fragments = new HashSet <string>(); switch (composition.SelectedProxy) { case "nginx": fragments.Add("nginx"); break; case "traefik": fragments.Add("traefik"); break; case "no-reverseproxy": case "none": case "": fragments.Add("btcpayserver-noreverseproxy"); break; } fragments.Add("btcpayserver"); foreach (var crypto in cryptoDefinitions) { if (!composition.SelectedCryptos.Contains(crypto.Crypto)) { continue; } fragments.Add(crypto.CryptoFragment); if (composition.SelectedLN == "clightning" && crypto.CLightningFragment != null) { fragments.Add(crypto.CLightningFragment); } if (composition.SelectedLN == "lnd" && crypto.LNDFragment != null) { fragments.Add(crypto.LNDFragment); } if (composition.SelectedLN == "eclair" && crypto.EclairFragment != null) { fragments.Add(crypto.EclairFragment); } } foreach (var fragment in composition.AdditionalFragments) { fragments.Add(fragment); } var def = new DockerComposeDefinition(name, fragments.Select(f => new FragmentName(f)).ToHashSet()) { ExcludeFragments = composition.ExcludeFragments.Select(f => new FragmentName(f)).ToHashSet() }; def.FragmentLocation = fragmentLocation; def.BuildOutputDirectory = output; def.Build(); }