From e2b82697a04d12bcafefbe3abe17e873f76f1b4b Mon Sep 17 00:00:00 2001 From: "nicolas.dorier" Date: Thu, 17 May 2018 01:31:36 +0900 Subject: [PATCH] add build scripts for custom docker-compose --- .gitignore | 2 +- Generated/.gitignore | 1 + README.md | 51 +++++++++++++++++++ ...ate-docker-compose.ps1 => build-pregen.ps1 | 0 generate-docker-compose.sh => build-pregen.sh | 0 build.ps1 | 17 +++++++ build.sh | 18 +++++++ .../src/DockerComposition.cs | 2 +- docker-compose-generator/src/Program.cs | 6 ++- 9 files changed, 94 insertions(+), 3 deletions(-) create mode 100644 Generated/.gitignore rename generate-docker-compose.ps1 => build-pregen.ps1 (100%) mode change 100644 => 100755 rename generate-docker-compose.sh => build-pregen.sh (100%) create mode 100755 build.ps1 create mode 100755 build.sh diff --git a/.gitignore b/.gitignore index ca3fc1d..6faab1d 100644 --- a/.gitignore +++ b/.gitignore @@ -295,4 +295,4 @@ BTCPayServer/wwwroot/bundles/* Production/.env .env .vscode/ -/docker-compose.generated.yml + diff --git a/Generated/.gitignore b/Generated/.gitignore new file mode 100644 index 0000000..ad30bfe --- /dev/null +++ b/Generated/.gitignore @@ -0,0 +1 @@ +*.yml \ No newline at end of file diff --git a/README.md b/README.md index f1a5bab..8a04d8c 100644 --- a/README.md +++ b/README.md @@ -71,3 +71,54 @@ Wait a little bit, then you can now browse `https://btcpay.example.com/`. The files in `Production` and `Production-NoReverseProxy` are generated by a dotnet program located in `docker-compose-generator`. It is meant to generate a wide range a configuration from `docker-compose-generator/docker-fragments` without repeating myself. + +# No docker-compose suit my need, what should I do? + +All `docker-compose` files in [Production](Production) and [Production-NoReverseProxy](Production-NoReverseProxy) are generated by running the [build-pregen.sh](build-pregen.sh) (or [build-pregen.ps1](build-pregen.ps1)) scripts from the fragments located in [docker-compose-generator/docker-fragments](docker-compose-generator/docker-fragments). + +The pre-generated `docker-compose` files cover `btc`, `ltc`, `clightning` for configuration with or without `nginx `reverse proxy. + +If you want any other configuration, you need to run [build.sh](build.sh) (or [build.ps1](build.ps1)) with environment variables correctly set. + +To configure your custom docker-compose, the following environment variables are supported: + +* `BTCPAYGEN_CRYPTO1` to `BTCPAYGEN_CRYPTO9`: Specify support for a crypto currency. (Valid value: `btc`, `ltc`) +* `BTCPAYGEN_REVERSEPROXY`: Specify the reverse proxy to use (Valid value: `nginx`, `none`) +* `BTCPAYGEN_LIGHTNING`: Specify the lightning network implementation (Valid value: `clightning`, `none`) +* `BTCPAYGEN_SUBNAME`: The sub name of the generated docker-compose file, where the full name will be `Generated/docker-compose.SUBNAME.yml` (Default: `generated`) + +Then, running [build.sh](build.sh) (or [build.ps1](build.ps1)) will then generate a `docker-compose.generated.yml` in the root folder of this repository. +For example, if you want `btc` and `ltc` support with `nginx` and `clightning` inside `Generate/docker-compose.custom.yml`: + +On Windows: + +``` +Invoke-Command { + $BTCPAYGEN_CRYPTO1="btc" + $BTCPAYGEN_CRYPTO2="ltc" + $BTCPAYGEN_REVERSEPROXY="nginx" + $BTCPAYGEN_LIGHTNING="clightning" + $BTCPAYGEN_SUBNAME="custom" + . .\build.ps1 +} +``` + +On Linux: + +``` +BTCPAYGEN_CRYPTO1=btc \ +BTCPAYGEN_CRYPTO2=ltc \ +BTCPAYGEN_REVERSEPROXY=nginx \ +BTCPAYGEN_LIGHTNING=cligthning \ +BTCPAYGEN_SUBNAME=custom \ +./build.sh +``` + +# How to extend with my own crypto? + +1. Support for your crypto on [NBitcoin](https://github.com/MetacoSA/NBitcoin/tree/master/NBitcoin.Altcoins)/[NBxplorer](https://github.com/dgarage/NBXplorer)/[BTCPay Server](https://github.com/btcpayserver/btcpayserver). (Take example on other coins) +2. Create your own docker image ([Example for BTC](https://hub.docker.com/r/nicolasdorier/docker-bitcoin/)) +3. Create a docker-compose fragment ([Example for BTC](docker-compose-generator/docker-fragments/bitcoin.yml)) +4. Add your Crypto Definition ([Example for BTC](docker-compose-generator/CryptoDefinition.cs)) + +Congratulation! \ No newline at end of file diff --git a/generate-docker-compose.ps1 b/build-pregen.ps1 old mode 100644 new mode 100755 similarity index 100% rename from generate-docker-compose.ps1 rename to build-pregen.ps1 diff --git a/generate-docker-compose.sh b/build-pregen.sh similarity index 100% rename from generate-docker-compose.sh rename to build-pregen.sh diff --git a/build.ps1 b/build.ps1 new file mode 100755 index 0000000..73683e9 --- /dev/null +++ b/build.ps1 @@ -0,0 +1,17 @@ +# This script will run docker-compose-generator in a container to generate the yml files + +docker build -t btcpayserver/docker-compose-generator "$(Get-Location)\docker-compose-generator" +docker run -v "$(Get-Location)\Generated:/app/Generated" ` + -e "BTCPAYGEN_CRYPTO1=$BTCPAYGEN_CRYPTO1" ` + -e "BTCPAYGEN_CRYPTO2=$BTCPAYGEN_CRYPTO2" ` + -e "BTCPAYGEN_CRYPTO3=$BTCPAYGEN_CRYPTO3" ` + -e "BTCPAYGEN_CRYPTO4=$BTCPAYGEN_CRYPTO4" ` + -e "BTCPAYGEN_CRYPTO5=$BTCPAYGEN_CRYPTO5" ` + -e "BTCPAYGEN_CRYPTO6=$BTCPAYGEN_CRYPTO6" ` + -e "BTCPAYGEN_CRYPTO7=$BTCPAYGEN_CRYPTO7" ` + -e "BTCPAYGEN_CRYPTO8=$BTCPAYGEN_CRYPTO8" ` + -e "BTCPAYGEN_CRYPTO9=$BTCPAYGEN_CRYPTO9" ` + -e "BTCPAYGEN_REVERSEPROXY=$BTCPAYGEN_REVERSEPROXY" ` + -e "BTCPAYGEN_LIGHTNING=$BTCPAYGEN_LIGHTNING" ` + -e "BTCPAYGEN_SUBNAME=$BTCPAYGEN_SUBNAME" ` + --rm btcpayserver/docker-compose-generator \ No newline at end of file diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..7e6e86a --- /dev/null +++ b/build.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +# This script will run docker-compose-generator in a container to generate the yml files +docker build -t btcpayserver/docker-compose-generator "$(pwd)/docker-compose-generator" +docker run -v "$(pwd)/Generated:/app/Generated" \ + -e "BTCPAYGEN_CRYPTO1=$(BTCPAYGEN_CRYPTO1)" \ + -e "BTCPAYGEN_CRYPTO2=$(BTCPAYGEN_CRYPTO2)" \ + -e "BTCPAYGEN_CRYPTO3=$(BTCPAYGEN_CRYPTO3)" \ + -e "BTCPAYGEN_CRYPTO4=$(BTCPAYGEN_CRYPTO4)" \ + -e "BTCPAYGEN_CRYPTO5=$(BTCPAYGEN_CRYPTO5)" \ + -e "BTCPAYGEN_CRYPTO6=$(BTCPAYGEN_CRYPTO6)" \ + -e "BTCPAYGEN_CRYPTO7=$(BTCPAYGEN_CRYPTO7)" \ + -e "BTCPAYGEN_CRYPTO8=$(BTCPAYGEN_CRYPTO8)" \ + -e "BTCPAYGEN_CRYPTO9=$(BTCPAYGEN_CRYPTO9)" \ + -e "BTCPAYGEN_REVERSEPROXY=$(BTCPAYGEN_REVERSEPROXY)" \ + -e "BTCPAYGEN_LIGHTNING=$(BTCPAYGEN_LIGHTNING)" \ + -e "BTCPAYGEN_SUBNAME=$(BTCPAYGEN_SUBNAME)" \ + --rm btcpayserver/docker-compose-generator \ No newline at end of file diff --git a/docker-compose-generator/src/DockerComposition.cs b/docker-compose-generator/src/DockerComposition.cs index b4df35b..5880064 100644 --- a/docker-compose-generator/src/DockerComposition.cs +++ b/docker-compose-generator/src/DockerComposition.cs @@ -30,7 +30,7 @@ namespace DockerGenerator { var selectedCrypto = Environment.GetEnvironmentVariable("BTCPAYGEN_CRYPTO" + i); if(string.IsNullOrEmpty(selectedCrypto)) - break; + continue; composition.SelectedCryptos.Add(selectedCrypto.ToLowerInvariant()); } composition.SelectedProxy = (Environment.GetEnvironmentVariable("BTCPAYGEN_REVERSEPROXY") ?? "").ToLowerInvariant(); diff --git a/docker-compose-generator/src/Program.cs b/docker-compose-generator/src/Program.cs index 9c0e159..6e35bd9 100644 --- a/docker-compose-generator/src/Program.cs +++ b/docker-compose-generator/src/Program.cs @@ -52,7 +52,11 @@ namespace DockerGenerator Console.WriteLine("Crypto: " + string.Join(", ", composition.SelectedCryptos.ToArray())); Console.WriteLine("Lightning: " + composition.SelectedLN); Console.WriteLine("ReverseProxy: " + composition.SelectedProxy); - new Program().Run(composition, "generated", root); + 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); } }