From 82b076edfe00bf41eb57bec85e3c5d9bf507c587 Mon Sep 17 00:00:00 2001 From: Kukks Date: Mon, 8 Apr 2019 08:38:42 +0200 Subject: [PATCH] Introduce Exclude Fragments option Allows you to exclude any fragments that get added. Good use case: do not deploy litecoin lightning node when using btc lightning Should also help users with advanced customization scenarios --- README.md | 1 + btcpay-setup.sh | 3 +++ build.ps1 | 1 + build.sh | 1 + docker-compose-generator/src/DockerComposition.cs | 10 ++++++++++ docker-compose-generator/src/Program.cs | 3 ++- 6 files changed, 18 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4d465db..e0b94d3 100644 --- a/README.md +++ b/README.md @@ -129,6 +129,7 @@ You can read [the article](https://medium.com/@BtcpayServer/hosting-btcpay-serve * `BTCPAY_SSHTRUSTEDFINGERPRINTS`: Optional, BTCPay will ensure that it is connecting to the expected SSH server by checking the host's public key against these fingerprints * `BTCPAYGEN_DOCKER_IMAGE`: Optional, Specify which generator image to use if you have customized the C# generator. Set to `btcpayserver/docker-compose-generator:local` to build the generator locally at runtime. * `BTCPAY_IMAGE`: Optional, Specify which btcpayserver image to use if you have a customized btcpayserver. +* `BTCPAYGEN_EXCLUDE_FRAGMENTS`: Semicolon-separated list of fragments you want to forcefully exclude(eg. `litecoin-clightning`) Additionally, there are specific environment variables for some addons: diff --git a/btcpay-setup.sh b/btcpay-setup.sh index ad55836..5e03ad8 100755 --- a/btcpay-setup.sh +++ b/btcpay-setup.sh @@ -66,6 +66,7 @@ Environment variables: Add-on specific variables: LIBREPATRON_HOST: If libre patron is activated with opt-add-librepatron, the hostname of your libre patron website (eg. librepatron.example.com) WOOCOMMERCE_HOST: If woocommerce is activated with opt-add-woocommerce, the hostname of your woocommerce website (eg. store.example.com) + BTCPAYGEN_EXCLUDE_FRAGMENTS: Semicolon-separated list of fragments you want to forcefully exclude(eg. litecoin-clightning) END } @@ -161,6 +162,7 @@ BTCPAYGEN_CRYPTO9:$BTCPAYGEN_CRYPTO9 BTCPAYGEN_REVERSEPROXY:$BTCPAYGEN_REVERSEPROXY BTCPAYGEN_LIGHTNING:$BTCPAYGEN_LIGHTNING BTCPAYGEN_ADDITIONAL_FRAGMENTS:$BTCPAYGEN_ADDITIONAL_FRAGMENTS +BTCPAYGEN_EXCLUDE_FRAGMENTS:$BTCPAYGEN_EXCLUDE_FRAGMENTS BTCPAY_IMAGE:$BTCPAY_IMAGE ACME_CA_URI:$ACME_CA_URI ---------------------- @@ -200,6 +202,7 @@ export BTCPAYGEN_CRYPTO9=\"$BTCPAYGEN_CRYPTO9\" export BTCPAYGEN_LIGHTNING=\"$BTCPAYGEN_LIGHTNING\" export BTCPAYGEN_REVERSEPROXY=\"$BTCPAYGEN_REVERSEPROXY\" export BTCPAYGEN_ADDITIONAL_FRAGMENTS=\"$BTCPAYGEN_ADDITIONAL_FRAGMENTS\" +export BTCPAYGEN_EXCLUDE_FRAGMENTS=\"$BTCPAYGEN_EXCLUDE_FRAGMENTS\" export BTCPAY_DOCKER_COMPOSE=\"$BTCPAY_DOCKER_COMPOSE\" export BTCPAY_BASE_DIRECTORY=\"$BTCPAY_BASE_DIRECTORY\" export BTCPAY_ENV_FILE=\"$BTCPAY_ENV_FILE\" diff --git a/build.ps1 b/build.ps1 index 0b5d052..44e5a61 100755 --- a/build.ps1 +++ b/build.ps1 @@ -21,6 +21,7 @@ docker run -v "$(Get-Location)\Generated:/app/Generated" ` -e "BTCPAYGEN_CRYPTO9=$BTCPAYGEN_CRYPTO9" ` -e "BTCPAYGEN_REVERSEPROXY=$BTCPAYGEN_REVERSEPROXY" ` -e "BTCPAYGEN_ADDITIONAL_FRAGMENTS=$BTCPAYGEN_ADDITIONAL_FRAGMENTS" ` + -e "BTCPAYGEN_EXCLUDE_FRAGMENTS=$BTCPAYGEN_EXCLUDE_FRAGMENTS" ` -e "BTCPAYGEN_LIGHTNING=$BTCPAYGEN_LIGHTNING" ` -e "BTCPAYGEN_SUBNAME=$BTCPAYGEN_SUBNAME" ` --rm $BTCPAYGEN_DOCKER_IMAGE diff --git a/build.sh b/build.sh index 799eafa..40805f1 100755 --- a/build.sh +++ b/build.sh @@ -22,6 +22,7 @@ docker run -v "$(pwd)/Generated:/app/Generated" \ -e "BTCPAYGEN_CRYPTO9=$BTCPAYGEN_CRYPTO9" \ -e "BTCPAYGEN_REVERSEPROXY=$BTCPAYGEN_REVERSEPROXY" \ -e "BTCPAYGEN_ADDITIONAL_FRAGMENTS=$BTCPAYGEN_ADDITIONAL_FRAGMENTS" \ + -e "BTCPAYGEN_EXCLUDE_FRAGMENTS=$BTCPAYGEN_EXCLUDE_FRAGMENTS" \ -e "BTCPAYGEN_LIGHTNING=$BTCPAYGEN_LIGHTNING" \ -e "BTCPAYGEN_SUBNAME=$BTCPAYGEN_SUBNAME" \ --rm $BTCPAYGEN_DOCKER_IMAGE diff --git a/docker-compose-generator/src/DockerComposition.cs b/docker-compose-generator/src/DockerComposition.cs index 8a924ed..e147be2 100644 --- a/docker-compose-generator/src/DockerComposition.cs +++ b/docker-compose-generator/src/DockerComposition.cs @@ -27,6 +27,11 @@ namespace DockerGenerator get; set; } = new string[0]; + public string[] ExcludeFragments + { + get; + set; + } = new string[0]; public static DockerComposition FromEnvironmentVariables() { @@ -46,6 +51,11 @@ namespace DockerGenerator .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; } } diff --git a/docker-compose-generator/src/Program.cs b/docker-compose-generator/src/Program.cs index 95ef99c..50d5246 100644 --- a/docker-compose-generator/src/Program.cs +++ b/docker-compose-generator/src/Program.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -72,6 +72,7 @@ namespace DockerGenerator { 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;