From 82da850599d42c46ffc5a53548a8e02d56182073 Mon Sep 17 00:00:00 2001 From: "nicolas.dorier" Date: Tue, 20 Mar 2018 11:16:03 +0900 Subject: [PATCH] Remove legacy docker-compose.yml, auto generate the Test docker-compose --- README.md | 4 +- Regtest/README.md | 19 ---- Regtest/docker-bitcoin-cli.ps1 | 1 - Regtest/docker-compose.yml | 45 ---------- Test/README.md | 14 +++ Test/docker-compose.btc-ltc.yml | 89 +++++++++++++++++++ .../docker-compose.btc.yml | 50 +---------- .../docker-fragments/btcpayserver-test.yml | 6 ++ .../src/DockerComposeDefinition.cs | 17 ++-- docker-compose-generator/src/Program.cs | 17 ++-- 10 files changed, 135 insertions(+), 127 deletions(-) delete mode 100644 Regtest/README.md delete mode 100644 Regtest/docker-bitcoin-cli.ps1 delete mode 100644 Regtest/docker-compose.yml create mode 100644 Test/README.md create mode 100644 Test/docker-compose.btc-ltc.yml rename Production/docker-compose.yml => Test/docker-compose.btc.yml (55%) create mode 100644 docker-compose-generator/docker-fragments/btcpayserver-test.yml diff --git a/README.md b/README.md index 5921bff..4780ec7 100644 --- a/README.md +++ b/README.md @@ -12,9 +12,9 @@ As you can see, it depends on several piece of infrastructure, mainly: Setting up the dependencies might be time consuming, this repository is meant to give working example of `docker-compose` file which will setup everything for you. -The [Regtest](Regtest) `docker-compose` can be used for local testing. +The [Test](Test) `docker-compose` are used for local testing. -The [Production](Production) `docker-compose` is used for production environment. It is using NGinx as a reverse proxy and [Let's Encrypt and DockerGen](https://github.com/gilyes/docker-nginx-letsencrypt-sample) to automatically configured HTTPS. +The [Production](Production) `docker-compose` are used for production environment. It adds NGinx as a reverse proxy and [Let's Encrypt and DockerGen](https://github.com/gilyes/docker-nginx-letsencrypt-sample) to automatically configure HTTPS. The production `docker-compose` is used under the hood to deploy an instance of BTCPay on Microsoft Azure in one click: diff --git a/Regtest/README.md b/Regtest/README.md deleted file mode 100644 index 4e5e37a..0000000 --- a/Regtest/README.md +++ /dev/null @@ -1,19 +0,0 @@ -# About this docker-compose - -This `docker-compose` shows how to configure postgres, bitcoind, NBXplorer and BTCPay on regtest. - -![Architecture](https://github.com/btcpayserver/btcpayserver-doc/raw/master/img/Architecture.png) - -It exposes BTCPay on the host address http://localhost:8080/. - -If you need to access bitcoind RPC, you can use bitcoin-cli inside the container: - -On Powershell: -``` -.\docker-bitcoin-cli getblockcount -``` - -On Linux: -``` -docker exec -ti btcpayserver_regtest_bitcoind bitcoin-cli -regtest -conf="/data/bitcoin.conf" -datadir="/data" getblockcount -``` \ No newline at end of file diff --git a/Regtest/docker-bitcoin-cli.ps1 b/Regtest/docker-bitcoin-cli.ps1 deleted file mode 100644 index 5750033..0000000 --- a/Regtest/docker-bitcoin-cli.ps1 +++ /dev/null @@ -1 +0,0 @@ -docker exec -ti btcpayserver_regtest_bitcoind bitcoin-cli -regtest -conf="/data/bitcoin.conf" -datadir="/data" $args \ No newline at end of file diff --git a/Regtest/docker-compose.yml b/Regtest/docker-compose.yml deleted file mode 100644 index f710cdc..0000000 --- a/Regtest/docker-compose.yml +++ /dev/null @@ -1,45 +0,0 @@ -version: "3" - -services: - - btcpayserver: - image: nicolasdorier/btcpayserver:1.0.1.53 - ports: - - 8080:49392 - expose: - - "49392" - environment: - BTCPAY_POSTGRES: "User ID=postgres;Host=postgres;Port=5432;Database=btcpayserver" - BTCPAY_NETWORK: regtest - BTCPAY_EXPLORERURL: http://nbxplorer:32838/ - BTCPAY_BIND: 0.0.0.0:49392 - links: - - nbxplorer - - postgres - - nbxplorer: - image: nicolasdorier/nbxplorer:1.0.1.23 - expose: - - "32838" - environment: - NBXPLORER_NETWORK: regtest - NBXPLORER_RPCURL: http://bitcoind:43782/ - NBXPLORER_RPCUSER: ceiwHEbqWI83 - NBXPLORER_RPCPASSWORD: DwubwWsoo3 - NBXPLORER_NODEENDPOINT: bitcoind:8332 - NBXPLORER_BIND: 0.0.0.0:32838 - NBXPLORER_NOAUTH: 1 - links: - - bitcoind - - bitcoind: - container_name: btcpayserver_regtest_bitcoind - image: nicolasdorier/docker-bitcoin:0.16.0 - environment: - BITCOIN_EXTRA_ARGS: "rpcuser=ceiwHEbqWI83\nrpcpassword=DwubwWsoo3\nregtest=1\nrpcport=43782\nport=8332" - expose: - - "43782" - - "8332" - - postgres: - image: postgres:9.6.5 diff --git a/Test/README.md b/Test/README.md new file mode 100644 index 0000000..e1a5dc1 --- /dev/null +++ b/Test/README.md @@ -0,0 +1,14 @@ +# About this docker-compose + +This `docker-compose` shows how to configure postgres, bitcoind, NBXplorer and BTCPay on regtest. + +![Architecture](https://github.com/btcpayserver/btcpayserver-doc/raw/master/img/Architecture.png) + +This is the same architecture as [Production](../Production) + +The relevant environment variables are: + +* `NBITCOIN_NETWORK`: the blockchain identifier used by NBitcoin (eg., `regtest`, `testnet`, `mainnet`) +* `BTCPAY_HOST`: the external url used to access your server from internet. This domain name must point to this machine for Let's Encrypt to create your certificate. (typically with a CNAME or A record) + +The port `80` is exposed. \ No newline at end of file diff --git a/Test/docker-compose.btc-ltc.yml b/Test/docker-compose.btc-ltc.yml new file mode 100644 index 0000000..4dee718 --- /dev/null +++ b/Test/docker-compose.btc-ltc.yml @@ -0,0 +1,89 @@ +version: "3" +services: + btcpayserver: + restart: always + image: nicolasdorier/btcpayserver:1.0.1.53 + expose: + - "49392" + environment: + BTCPAY_POSTGRES: User ID=postgres;Host=postgres;Port=5432;Database=btcpayserver${NBITCOIN_NETWORK:-regtest} + BTCPAY_NETWORK: ${NBITCOIN_NETWORK:-regtest} + BTCPAY_BIND: 0.0.0.0:49392 + BTCPAY_EXTERNALURL: https://${BTCPAY_HOST}/ + VIRTUAL_NETWORK: nginx-proxy + VIRTUAL_PORT: 49392 + VIRTUAL_HOST: ${BTCPAY_HOST} + LETSENCRYPT_HOST: ${BTCPAY_HOST} + LETSENCRYPT_EMAIL: ${LETSENCRYPT_EMAIL:-yourname@example.com} + BTCPAY_CHAINS: "btc,ltc" + BTCPAY_BTCEXPLORERURL: http://nbxplorer:32838/ + BTCPAY_LTCEXPLORERURL: http://nbxplorer:32838/ + links: + - nbxplorer + - postgres + volumes: + - "btcpay_datadir:/datadir" + - "nbxplorer_datadir:/root/.nbxplorer" + ports: + - "80:49392" + nbxplorer: + restart: always + image: nicolasdorier/nbxplorer:1.0.1.23 + expose: + - "32838" + environment: + NBXPLORER_NETWORK: ${NBITCOIN_NETWORK:-regtest} + NBXPLORER_BIND: 0.0.0.0:32838 + NBXPLORER_CHAINS: "btc,ltc" + NBXPLORER_BTCRPCURL: http://bitcoind:43782/ + NBXPLORER_BTCNODEENDPOINT: bitcoind:39388 + NBXPLORER_LTCRPCURL: http://litecoind:43782/ + NBXPLORER_LTCNODEENDPOINT: litecoind:39388 + volumes: + - "nbxplorer_datadir:/datadir" + - "bitcoin_datadir:/root/.bitcoin" + - "litecoin_datadir:/root/.litecoin" + links: + - bitcoind + - litecoind + postgres: + restart: always + image: postgres:9.6.5 + volumes: + - "postgres_datadir:/var/lib/postgresql/data" + bitcoind: + restart: always + container_name: btcpayserver_bitcoind + image: nicolasdorier/docker-bitcoin:0.16.0 + environment: + BITCOIN_EXTRA_ARGS: | + rpcport=43782 + ${NBITCOIN_NETWORK:-regtest}=1 + port=39388 + whitelist=0.0.0.0/0 + expose: + - "43782" + - "39388" + volumes: + - "bitcoin_datadir:/data" + litecoind: + restart: always + container_name: btcpayserver_litecoind + image: nicolasdorier/docker-litecoin:0.14.2 + environment: + BITCOIN_EXTRA_ARGS: | + rpcport=43782 + ${NBITCOIN_NETWORK:-regtest}=1 + port=39388 + whitelist=0.0.0.0/0 + expose: + - "43782" + - "39388" + volumes: + - "litecoin_datadir:/data" +volumes: + postgres_datadir: + btcpay_datadir: + nbxplorer_datadir: + bitcoin_datadir: + litecoin_datadir: diff --git a/Production/docker-compose.yml b/Test/docker-compose.btc.yml similarity index 55% rename from Production/docker-compose.yml rename to Test/docker-compose.btc.yml index b34a112..e4b7915 100644 --- a/Production/docker-compose.yml +++ b/Test/docker-compose.btc.yml @@ -1,49 +1,5 @@ version: "3" services: - nginx: - restart: always - image: nginx - container_name: nginx - ports: - - "80:80" - - "443:443" - volumes: - - "nginx_conf:/etc/nginx/conf.d" - - "nginx_vhost:/etc/nginx/vhost.d" - - "nginx_html:/usr/share/nginx/html" - - "nginx_certs:/etc/nginx/certs:ro" - links: - - btcpayserver - nginx-gen: - restart: always - image: jwilder/docker-gen - container_name: nginx-gen - volumes: - - "/var/run/docker.sock:/tmp/docker.sock:ro" - - "./nginx.tmpl:/etc/docker-gen/templates/nginx.tmpl:ro" - - "nginx_conf:/etc/nginx/conf.d" - - "nginx_vhost:/etc/nginx/vhost.d" - - "nginx_html:/usr/share/nginx/html" - - "nginx_certs:/etc/nginx/certs:ro" - entrypoint: /usr/local/bin/docker-gen -notify-sighup nginx -watch -wait 5s:30s /etc/docker-gen/templates/nginx.tmpl /etc/nginx/conf.d/default.conf - links: - - nginx - letsencrypt-nginx-proxy-companion: - restart: always - image: jrcs/letsencrypt-nginx-proxy-companion - container_name: letsencrypt-nginx-proxy-companion - volumes: - - "/var/run/docker.sock:/var/run/docker.sock:ro" - - "nginx_conf:/etc/nginx/conf.d" - - "nginx_vhost:/etc/nginx/vhost.d" - - "nginx_html:/usr/share/nginx/html" - - "nginx_certs:/etc/nginx/certs:rw" - environment: - NGINX_DOCKER_GEN_CONTAINER: "nginx-gen" - NGINX_PROXY_CONTAINER: "nginx" - ACME_CA_URI: ${ACME_CA_URI:-https://acme-staging.api.letsencrypt.org/directory} - links: - - nginx btcpayserver: restart: always image: nicolasdorier/btcpayserver:1.0.1.53 @@ -67,6 +23,8 @@ services: volumes: - "btcpay_datadir:/datadir" - "nbxplorer_datadir:/root/.nbxplorer" + ports: + - "80:49392" nbxplorer: restart: always image: nicolasdorier/nbxplorer:1.0.1.23 @@ -104,10 +62,6 @@ services: volumes: - "bitcoin_datadir:/data" volumes: - nginx_conf: - nginx_vhost: - nginx_html: - nginx_certs: postgres_datadir: btcpay_datadir: nbxplorer_datadir: diff --git a/docker-compose-generator/docker-fragments/btcpayserver-test.yml b/docker-compose-generator/docker-fragments/btcpayserver-test.yml new file mode 100644 index 0000000..62525eb --- /dev/null +++ b/docker-compose-generator/docker-fragments/btcpayserver-test.yml @@ -0,0 +1,6 @@ +version: "3" + +services: + btcpayserver: + ports: + - "80:49392" diff --git a/docker-compose-generator/src/DockerComposeDefinition.cs b/docker-compose-generator/src/DockerComposeDefinition.cs index 1fc32e0..439808d 100644 --- a/docker-compose-generator/src/DockerComposeDefinition.cs +++ b/docker-compose-generator/src/DockerComposeDefinition.cs @@ -10,12 +10,15 @@ namespace DockerGenerator { public class DockerComposeDefinition { - string[] _Fragments; + public List Fragments + { + get; set; + } private string _Name; - public DockerComposeDefinition(string name, string[] fragments) + public DockerComposeDefinition(string name, List fragments) { - _Fragments = fragments; + Fragments = fragments; _Name = name; } @@ -39,21 +42,21 @@ namespace DockerGenerator var serializer = new SerializerBuilder().Build(); Console.WriteLine($"With fragments:"); - foreach(var fragment in _Fragments) + foreach(var fragment in Fragments) { Console.WriteLine($"\t{fragment}"); } var services = new List>(); var volumes = new List>(); - foreach(var doc in _Fragments.Select(f => ParseDocument(f))) + foreach(var doc in Fragments.Select(f => ParseDocument(f))) { - if(doc.Children["services"] is YamlMappingNode fragmentServicesRoot) + if(doc.Children.ContainsKey("services") && doc.Children["services"] is YamlMappingNode fragmentServicesRoot) { services.AddRange(fragmentServicesRoot.Children); } - if(doc.Children["volumes"] is YamlMappingNode fragmentVolumesRoot) + if(doc.Children.ContainsKey("volumes") && doc.Children["volumes"] is YamlMappingNode fragmentVolumesRoot) { volumes.AddRange(fragmentVolumesRoot.Children); } diff --git a/docker-compose-generator/src/Program.cs b/docker-compose-generator/src/Program.cs index 76b71d9..673cd59 100644 --- a/docker-compose-generator/src/Program.cs +++ b/docker-compose-generator/src/Program.cs @@ -15,11 +15,10 @@ namespace DockerGenerator private void Run() { List defs = new List(); - var btc = new DockerComposeDefinition("btc", - new string[] { "nginx", "btcpayserver", "bitcoin" }); - defs.Add(btc); + defs.Add(new DockerComposeDefinition("btc", + new List { "nginx", "btcpayserver", "bitcoin" })); defs.Add(new DockerComposeDefinition("btc-ltc", - new string[] { "nginx", "btcpayserver", "bitcoin", "litecoin" })); + new List { "nginx", "btcpayserver", "bitcoin", "litecoin" })); var fragmentLocation = FindLocation("docker-fragments"); var productionLocation = FindLocation("Production"); @@ -29,7 +28,15 @@ namespace DockerGenerator def.BuildOutputDirectory = productionLocation; def.Build(); } - File.Copy(btc.GetFilePath(), Path.Combine(new FileInfo(btc.GetFilePath()).Directory.FullName, "docker-compose.yml"), true); + + var testLocation = FindLocation("Test"); + foreach(var def in defs) + { + def.Fragments.Remove("nginx"); + def.Fragments.Add("btcpayserver-test"); + def.BuildOutputDirectory = testLocation; + def.Build(); + } } private string FindLocation(string path)