You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
97 lines
2.8 KiB
97 lines
2.8 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using YamlDotNet.Serialization;
|
|
|
|
namespace DockerGenerator
|
|
{
|
|
class Program
|
|
{
|
|
|
|
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;
|
|
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>();
|
|
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());
|
|
}
|
|
|
|
var def = new DockerComposeDefinition(name, fragments);
|
|
def.FragmentLocation = fragmentLocation;
|
|
def.BuildOutputDirectory = output;
|
|
def.Build();
|
|
}
|
|
|
|
private static string FindRoot(string rootDirectory)
|
|
{
|
|
string directory = Directory.GetCurrentDirectory();
|
|
int i = 0;
|
|
while (true)
|
|
{
|
|
if (i > 10)
|
|
throw new DirectoryNotFoundException(rootDirectory);
|
|
if (directory.EndsWith(rootDirectory))
|
|
return directory;
|
|
directory = Path.GetFullPath(Path.Combine(directory, ".."));
|
|
i++;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|