From 7b3faa71c27337883d2aea33510c57cdd08ee926 Mon Sep 17 00:00:00 2001 From: "nicolas.dorier" Date: Sat, 19 May 2018 14:50:48 +0900 Subject: [PATCH] Migration to new deployment system --- .gitignore | 1 + Generated/.gitignore | 3 +- .../docker-compose.btc-clightning.yml | 10 +- .../docker-compose.btc-ltc-clightning.yml | 14 +- .../docker-compose.btc-ltc.yml | 10 +- .../docker-compose.btc.yml | 8 +- .../docker-compose.ltc-clightning.yml | 10 +- .../docker-compose.ltc.yml | 8 +- Production/docker-compose.btc-clightning.yml | 16 +- .../docker-compose.btc-ltc-clightning.yml | 20 +- Production/docker-compose.btc-ltc.yml | 16 +- Production/docker-compose.btc.yml | 14 +- Production/docker-compose.ltc-clightning.yml | 16 +- Production/docker-compose.ltc.yml | 14 +- README.md | 247 ++++++++++++++---- btcpay-restart.sh | 7 + btcpay-setup.sh | 149 ++++++++--- btcpay-update.sh | 29 ++ build-pregen.ps1 | 2 +- build-pregen.sh | 2 +- build.ps1 | 9 +- build.sh | 9 +- changedomain.sh | 19 ++ docker-compose-generator/.dockerignore | 1 + docker-compose-generator/Dockerfile | 1 - .../docker-fragments/bgold.yml | 2 +- .../docker-fragments/bitcoin-clightning.yml | 2 +- .../docker-fragments/bitcoin.yml | 2 +- .../docker-fragments/btcpayserver.yml | 6 +- .../docker-fragments/litecoin-clightning.yml | 2 +- .../docker-fragments/litecoin.yml | 2 +- .../docker-fragments/nginx.yml | 6 +- .../src/docker-compose-generator.csproj | 5 +- 33 files changed, 483 insertions(+), 179 deletions(-) create mode 100755 btcpay-restart.sh create mode 100755 btcpay-update.sh create mode 100755 changedomain.sh diff --git a/.gitignore b/.gitignore index 6faab1d..c85785c 100644 --- a/.gitignore +++ b/.gitignore @@ -295,4 +295,5 @@ BTCPayServer/wwwroot/bundles/* Production/.env .env .vscode/ +*docker-compose.generated.yml diff --git a/Generated/.gitignore b/Generated/.gitignore index ad30bfe..5c11526 100644 --- a/Generated/.gitignore +++ b/Generated/.gitignore @@ -1 +1,2 @@ -*.yml \ No newline at end of file +*.yml +*.tmpl \ No newline at end of file diff --git a/Production-NoReverseProxy/docker-compose.btc-clightning.yml b/Production-NoReverseProxy/docker-compose.btc-clightning.yml index 4ce650b..c656987 100644 --- a/Production-NoReverseProxy/docker-compose.btc-clightning.yml +++ b/Production-NoReverseProxy/docker-compose.btc-clightning.yml @@ -1,7 +1,7 @@ version: "3" services: btcpayserver: - restart: always + restart: unless-stopped image: nicolasdorier/btcpayserver:1.0.2.21 expose: - "49392" @@ -31,7 +31,7 @@ services: ports: - "80:49392" nbxplorer: - restart: always + restart: unless-stopped image: nicolasdorier/nbxplorer:1.0.2.7 expose: - "32838" @@ -47,12 +47,12 @@ services: links: - bitcoind postgres: - restart: always + restart: unless-stopped image: postgres:9.6.5 volumes: - "postgres_datadir:/var/lib/postgresql/data" bitcoind: - restart: always + restart: unless-stopped container_name: btcpayserver_bitcoind image: nicolasdorier/docker-bitcoin:0.16.0 environment: @@ -69,7 +69,7 @@ services: clightning_bitcoin: image: nicolasdorier/clightning:0.0.0.16 container_name: btcpayserver_clightning_bitcoin - restart: always + restart: unless-stopped environment: LIGHTNINGD_OPT: | bitcoin-datadir=/etc/bitcoin diff --git a/Production-NoReverseProxy/docker-compose.btc-ltc-clightning.yml b/Production-NoReverseProxy/docker-compose.btc-ltc-clightning.yml index 1c9e32c..c63f3f6 100644 --- a/Production-NoReverseProxy/docker-compose.btc-ltc-clightning.yml +++ b/Production-NoReverseProxy/docker-compose.btc-ltc-clightning.yml @@ -1,7 +1,7 @@ version: "3" services: btcpayserver: - restart: always + restart: unless-stopped image: nicolasdorier/btcpayserver:1.0.2.21 expose: - "49392" @@ -35,7 +35,7 @@ services: ports: - "80:49392" nbxplorer: - restart: always + restart: unless-stopped image: nicolasdorier/nbxplorer:1.0.2.7 expose: - "32838" @@ -55,12 +55,12 @@ services: - litecoind - bitcoind postgres: - restart: always + restart: unless-stopped image: postgres:9.6.5 volumes: - "postgres_datadir:/var/lib/postgresql/data" litecoind: - restart: always + restart: unless-stopped container_name: btcpayserver_litecoind image: nicolasdorier/docker-litecoin:0.15.1 environment: @@ -77,7 +77,7 @@ services: clightning_litecoin: image: nicolasdorier/clightning:0.0.0.16 container_name: btcpayserver_clightning_litecoin - restart: always + restart: unless-stopped environment: LIGHTNINGD_OPT: | bitcoin-datadir=/etc/litecoin @@ -95,7 +95,7 @@ services: links: - litecoind bitcoind: - restart: always + restart: unless-stopped container_name: btcpayserver_bitcoind image: nicolasdorier/docker-bitcoin:0.16.0 environment: @@ -112,7 +112,7 @@ services: clightning_bitcoin: image: nicolasdorier/clightning:0.0.0.16 container_name: btcpayserver_clightning_bitcoin - restart: always + restart: unless-stopped environment: LIGHTNINGD_OPT: | bitcoin-datadir=/etc/bitcoin diff --git a/Production-NoReverseProxy/docker-compose.btc-ltc.yml b/Production-NoReverseProxy/docker-compose.btc-ltc.yml index 649be05..800e8b9 100644 --- a/Production-NoReverseProxy/docker-compose.btc-ltc.yml +++ b/Production-NoReverseProxy/docker-compose.btc-ltc.yml @@ -1,7 +1,7 @@ version: "3" services: btcpayserver: - restart: always + restart: unless-stopped image: nicolasdorier/btcpayserver:1.0.2.21 expose: - "49392" @@ -29,7 +29,7 @@ services: ports: - "80:49392" nbxplorer: - restart: always + restart: unless-stopped image: nicolasdorier/nbxplorer:1.0.2.7 expose: - "32838" @@ -49,12 +49,12 @@ services: - litecoind - bitcoind postgres: - restart: always + restart: unless-stopped image: postgres:9.6.5 volumes: - "postgres_datadir:/var/lib/postgresql/data" litecoind: - restart: always + restart: unless-stopped container_name: btcpayserver_litecoind image: nicolasdorier/docker-litecoin:0.15.1 environment: @@ -69,7 +69,7 @@ services: volumes: - "litecoin_datadir:/data" bitcoind: - restart: always + restart: unless-stopped container_name: btcpayserver_bitcoind image: nicolasdorier/docker-bitcoin:0.16.0 environment: diff --git a/Production-NoReverseProxy/docker-compose.btc.yml b/Production-NoReverseProxy/docker-compose.btc.yml index bc37c9a..fddb829 100644 --- a/Production-NoReverseProxy/docker-compose.btc.yml +++ b/Production-NoReverseProxy/docker-compose.btc.yml @@ -1,7 +1,7 @@ version: "3" services: btcpayserver: - restart: always + restart: unless-stopped image: nicolasdorier/btcpayserver:1.0.2.21 expose: - "49392" @@ -28,7 +28,7 @@ services: ports: - "80:49392" nbxplorer: - restart: always + restart: unless-stopped image: nicolasdorier/nbxplorer:1.0.2.7 expose: - "32838" @@ -44,12 +44,12 @@ services: links: - bitcoind postgres: - restart: always + restart: unless-stopped image: postgres:9.6.5 volumes: - "postgres_datadir:/var/lib/postgresql/data" bitcoind: - restart: always + restart: unless-stopped container_name: btcpayserver_bitcoind image: nicolasdorier/docker-bitcoin:0.16.0 environment: diff --git a/Production-NoReverseProxy/docker-compose.ltc-clightning.yml b/Production-NoReverseProxy/docker-compose.ltc-clightning.yml index b6e1bdd..c110064 100644 --- a/Production-NoReverseProxy/docker-compose.ltc-clightning.yml +++ b/Production-NoReverseProxy/docker-compose.ltc-clightning.yml @@ -1,7 +1,7 @@ version: "3" services: btcpayserver: - restart: always + restart: unless-stopped image: nicolasdorier/btcpayserver:1.0.2.21 expose: - "49392" @@ -31,7 +31,7 @@ services: ports: - "80:49392" nbxplorer: - restart: always + restart: unless-stopped image: nicolasdorier/nbxplorer:1.0.2.7 expose: - "32838" @@ -47,12 +47,12 @@ services: links: - litecoind postgres: - restart: always + restart: unless-stopped image: postgres:9.6.5 volumes: - "postgres_datadir:/var/lib/postgresql/data" litecoind: - restart: always + restart: unless-stopped container_name: btcpayserver_litecoind image: nicolasdorier/docker-litecoin:0.15.1 environment: @@ -69,7 +69,7 @@ services: clightning_litecoin: image: nicolasdorier/clightning:0.0.0.16 container_name: btcpayserver_clightning_litecoin - restart: always + restart: unless-stopped environment: LIGHTNINGD_OPT: | bitcoin-datadir=/etc/litecoin diff --git a/Production-NoReverseProxy/docker-compose.ltc.yml b/Production-NoReverseProxy/docker-compose.ltc.yml index b79258d..f1ca2ce 100644 --- a/Production-NoReverseProxy/docker-compose.ltc.yml +++ b/Production-NoReverseProxy/docker-compose.ltc.yml @@ -1,7 +1,7 @@ version: "3" services: btcpayserver: - restart: always + restart: unless-stopped image: nicolasdorier/btcpayserver:1.0.2.21 expose: - "49392" @@ -28,7 +28,7 @@ services: ports: - "80:49392" nbxplorer: - restart: always + restart: unless-stopped image: nicolasdorier/nbxplorer:1.0.2.7 expose: - "32838" @@ -44,12 +44,12 @@ services: links: - litecoind postgres: - restart: always + restart: unless-stopped image: postgres:9.6.5 volumes: - "postgres_datadir:/var/lib/postgresql/data" litecoind: - restart: always + restart: unless-stopped container_name: btcpayserver_litecoind image: nicolasdorier/docker-litecoin:0.15.1 environment: diff --git a/Production/docker-compose.btc-clightning.yml b/Production/docker-compose.btc-clightning.yml index f8dbed3..a8d5261 100644 --- a/Production/docker-compose.btc-clightning.yml +++ b/Production/docker-compose.btc-clightning.yml @@ -1,7 +1,7 @@ version: "3" services: nginx: - restart: always + restart: unless-stopped image: nginx container_name: nginx ports: @@ -15,7 +15,7 @@ services: links: - btcpayserver nginx-gen: - restart: always + restart: unless-stopped image: jwilder/docker-gen container_name: nginx-gen volumes: @@ -29,7 +29,7 @@ services: links: - nginx letsencrypt-nginx-proxy-companion: - restart: always + restart: unless-stopped image: jrcs/letsencrypt-nginx-proxy-companion container_name: letsencrypt-nginx-proxy-companion volumes: @@ -45,7 +45,7 @@ services: links: - nginx-gen btcpayserver: - restart: always + restart: unless-stopped image: nicolasdorier/btcpayserver:1.0.2.21 expose: - "49392" @@ -73,7 +73,7 @@ services: - "nbxplorer_datadir:/root/.nbxplorer" - "clightning_bitcoin_datadir:/etc/clightning_bitcoin" nbxplorer: - restart: always + restart: unless-stopped image: nicolasdorier/nbxplorer:1.0.2.7 expose: - "32838" @@ -89,12 +89,12 @@ services: links: - bitcoind postgres: - restart: always + restart: unless-stopped image: postgres:9.6.5 volumes: - "postgres_datadir:/var/lib/postgresql/data" bitcoind: - restart: always + restart: unless-stopped container_name: btcpayserver_bitcoind image: nicolasdorier/docker-bitcoin:0.16.0 environment: @@ -111,7 +111,7 @@ services: clightning_bitcoin: image: nicolasdorier/clightning:0.0.0.16 container_name: btcpayserver_clightning_bitcoin - restart: always + restart: unless-stopped environment: LIGHTNINGD_OPT: | bitcoin-datadir=/etc/bitcoin diff --git a/Production/docker-compose.btc-ltc-clightning.yml b/Production/docker-compose.btc-ltc-clightning.yml index cf2662f..9800e4a 100644 --- a/Production/docker-compose.btc-ltc-clightning.yml +++ b/Production/docker-compose.btc-ltc-clightning.yml @@ -1,7 +1,7 @@ version: "3" services: nginx: - restart: always + restart: unless-stopped image: nginx container_name: nginx ports: @@ -15,7 +15,7 @@ services: links: - btcpayserver nginx-gen: - restart: always + restart: unless-stopped image: jwilder/docker-gen container_name: nginx-gen volumes: @@ -29,7 +29,7 @@ services: links: - nginx letsencrypt-nginx-proxy-companion: - restart: always + restart: unless-stopped image: jrcs/letsencrypt-nginx-proxy-companion container_name: letsencrypt-nginx-proxy-companion volumes: @@ -45,7 +45,7 @@ services: links: - nginx-gen btcpayserver: - restart: always + restart: unless-stopped image: nicolasdorier/btcpayserver:1.0.2.21 expose: - "49392" @@ -77,7 +77,7 @@ services: - "clightning_litecoin_datadir:/etc/clightning_litecoin" - "clightning_bitcoin_datadir:/etc/clightning_bitcoin" nbxplorer: - restart: always + restart: unless-stopped image: nicolasdorier/nbxplorer:1.0.2.7 expose: - "32838" @@ -97,12 +97,12 @@ services: - litecoind - bitcoind postgres: - restart: always + restart: unless-stopped image: postgres:9.6.5 volumes: - "postgres_datadir:/var/lib/postgresql/data" litecoind: - restart: always + restart: unless-stopped container_name: btcpayserver_litecoind image: nicolasdorier/docker-litecoin:0.15.1 environment: @@ -119,7 +119,7 @@ services: clightning_litecoin: image: nicolasdorier/clightning:0.0.0.16 container_name: btcpayserver_clightning_litecoin - restart: always + restart: unless-stopped environment: LIGHTNINGD_OPT: | bitcoin-datadir=/etc/litecoin @@ -137,7 +137,7 @@ services: links: - litecoind bitcoind: - restart: always + restart: unless-stopped container_name: btcpayserver_bitcoind image: nicolasdorier/docker-bitcoin:0.16.0 environment: @@ -154,7 +154,7 @@ services: clightning_bitcoin: image: nicolasdorier/clightning:0.0.0.16 container_name: btcpayserver_clightning_bitcoin - restart: always + restart: unless-stopped environment: LIGHTNINGD_OPT: | bitcoin-datadir=/etc/bitcoin diff --git a/Production/docker-compose.btc-ltc.yml b/Production/docker-compose.btc-ltc.yml index 489d46c..3b5086d 100644 --- a/Production/docker-compose.btc-ltc.yml +++ b/Production/docker-compose.btc-ltc.yml @@ -1,7 +1,7 @@ version: "3" services: nginx: - restart: always + restart: unless-stopped image: nginx container_name: nginx ports: @@ -15,7 +15,7 @@ services: links: - btcpayserver nginx-gen: - restart: always + restart: unless-stopped image: jwilder/docker-gen container_name: nginx-gen volumes: @@ -29,7 +29,7 @@ services: links: - nginx letsencrypt-nginx-proxy-companion: - restart: always + restart: unless-stopped image: jrcs/letsencrypt-nginx-proxy-companion container_name: letsencrypt-nginx-proxy-companion volumes: @@ -45,7 +45,7 @@ services: links: - nginx-gen btcpayserver: - restart: always + restart: unless-stopped image: nicolasdorier/btcpayserver:1.0.2.21 expose: - "49392" @@ -71,7 +71,7 @@ services: - "btcpay_datadir:/datadir" - "nbxplorer_datadir:/root/.nbxplorer" nbxplorer: - restart: always + restart: unless-stopped image: nicolasdorier/nbxplorer:1.0.2.7 expose: - "32838" @@ -91,12 +91,12 @@ services: - litecoind - bitcoind postgres: - restart: always + restart: unless-stopped image: postgres:9.6.5 volumes: - "postgres_datadir:/var/lib/postgresql/data" litecoind: - restart: always + restart: unless-stopped container_name: btcpayserver_litecoind image: nicolasdorier/docker-litecoin:0.15.1 environment: @@ -111,7 +111,7 @@ services: volumes: - "litecoin_datadir:/data" bitcoind: - restart: always + restart: unless-stopped container_name: btcpayserver_bitcoind image: nicolasdorier/docker-bitcoin:0.16.0 environment: diff --git a/Production/docker-compose.btc.yml b/Production/docker-compose.btc.yml index 840b4fa..a73f190 100644 --- a/Production/docker-compose.btc.yml +++ b/Production/docker-compose.btc.yml @@ -1,7 +1,7 @@ version: "3" services: nginx: - restart: always + restart: unless-stopped image: nginx container_name: nginx ports: @@ -15,7 +15,7 @@ services: links: - btcpayserver nginx-gen: - restart: always + restart: unless-stopped image: jwilder/docker-gen container_name: nginx-gen volumes: @@ -29,7 +29,7 @@ services: links: - nginx letsencrypt-nginx-proxy-companion: - restart: always + restart: unless-stopped image: jrcs/letsencrypt-nginx-proxy-companion container_name: letsencrypt-nginx-proxy-companion volumes: @@ -45,7 +45,7 @@ services: links: - nginx-gen btcpayserver: - restart: always + restart: unless-stopped image: nicolasdorier/btcpayserver:1.0.2.21 expose: - "49392" @@ -70,7 +70,7 @@ services: - "btcpay_datadir:/datadir" - "nbxplorer_datadir:/root/.nbxplorer" nbxplorer: - restart: always + restart: unless-stopped image: nicolasdorier/nbxplorer:1.0.2.7 expose: - "32838" @@ -86,12 +86,12 @@ services: links: - bitcoind postgres: - restart: always + restart: unless-stopped image: postgres:9.6.5 volumes: - "postgres_datadir:/var/lib/postgresql/data" bitcoind: - restart: always + restart: unless-stopped container_name: btcpayserver_bitcoind image: nicolasdorier/docker-bitcoin:0.16.0 environment: diff --git a/Production/docker-compose.ltc-clightning.yml b/Production/docker-compose.ltc-clightning.yml index cb91b03..c78f6ff 100644 --- a/Production/docker-compose.ltc-clightning.yml +++ b/Production/docker-compose.ltc-clightning.yml @@ -1,7 +1,7 @@ version: "3" services: nginx: - restart: always + restart: unless-stopped image: nginx container_name: nginx ports: @@ -15,7 +15,7 @@ services: links: - btcpayserver nginx-gen: - restart: always + restart: unless-stopped image: jwilder/docker-gen container_name: nginx-gen volumes: @@ -29,7 +29,7 @@ services: links: - nginx letsencrypt-nginx-proxy-companion: - restart: always + restart: unless-stopped image: jrcs/letsencrypt-nginx-proxy-companion container_name: letsencrypt-nginx-proxy-companion volumes: @@ -45,7 +45,7 @@ services: links: - nginx-gen btcpayserver: - restart: always + restart: unless-stopped image: nicolasdorier/btcpayserver:1.0.2.21 expose: - "49392" @@ -73,7 +73,7 @@ services: - "nbxplorer_datadir:/root/.nbxplorer" - "clightning_litecoin_datadir:/etc/clightning_litecoin" nbxplorer: - restart: always + restart: unless-stopped image: nicolasdorier/nbxplorer:1.0.2.7 expose: - "32838" @@ -89,12 +89,12 @@ services: links: - litecoind postgres: - restart: always + restart: unless-stopped image: postgres:9.6.5 volumes: - "postgres_datadir:/var/lib/postgresql/data" litecoind: - restart: always + restart: unless-stopped container_name: btcpayserver_litecoind image: nicolasdorier/docker-litecoin:0.15.1 environment: @@ -111,7 +111,7 @@ services: clightning_litecoin: image: nicolasdorier/clightning:0.0.0.16 container_name: btcpayserver_clightning_litecoin - restart: always + restart: unless-stopped environment: LIGHTNINGD_OPT: | bitcoin-datadir=/etc/litecoin diff --git a/Production/docker-compose.ltc.yml b/Production/docker-compose.ltc.yml index 28f116c..0b98355 100644 --- a/Production/docker-compose.ltc.yml +++ b/Production/docker-compose.ltc.yml @@ -1,7 +1,7 @@ version: "3" services: nginx: - restart: always + restart: unless-stopped image: nginx container_name: nginx ports: @@ -15,7 +15,7 @@ services: links: - btcpayserver nginx-gen: - restart: always + restart: unless-stopped image: jwilder/docker-gen container_name: nginx-gen volumes: @@ -29,7 +29,7 @@ services: links: - nginx letsencrypt-nginx-proxy-companion: - restart: always + restart: unless-stopped image: jrcs/letsencrypt-nginx-proxy-companion container_name: letsencrypt-nginx-proxy-companion volumes: @@ -45,7 +45,7 @@ services: links: - nginx-gen btcpayserver: - restart: always + restart: unless-stopped image: nicolasdorier/btcpayserver:1.0.2.21 expose: - "49392" @@ -70,7 +70,7 @@ services: - "btcpay_datadir:/datadir" - "nbxplorer_datadir:/root/.nbxplorer" nbxplorer: - restart: always + restart: unless-stopped image: nicolasdorier/nbxplorer:1.0.2.7 expose: - "32838" @@ -86,12 +86,12 @@ services: links: - litecoind postgres: - restart: always + restart: unless-stopped image: postgres:9.6.5 volumes: - "postgres_datadir:/var/lib/postgresql/data" litecoind: - restart: always + restart: unless-stopped container_name: btcpayserver_litecoind image: nicolasdorier/docker-litecoin:0.15.1 environment: diff --git a/README.md b/README.md index dd9320d..c0eb0fe 100644 --- a/README.md +++ b/README.md @@ -1,78 +1,101 @@ -# How to use +# Introduction -This repository is hosting different docker-compose which can be used to facilitate deployment of BTCPay Server. +This repository will help you to setup BTCPay and all its dependencies in a simple way: ![Architecture](https://github.com/btcpayserver/btcpayserver-doc/raw/master/img/Architecture.png) -As you can see, it depends on several piece of infrastructure, mainly: +As you can see, BTCPay depends on several piece of infrastructure, mainly: * A lightweight block explorer (NBXplorer), * A database (Postgres, or SQLite), * A full node (Bitcoin Core) -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. +There is more dependencies, if you support more than just Bitcoin. (C-Lightning, LitecoinD etc...) +Setting up the dependencies correctly in a production environment might be time consuming. -The [Production](Production) `docker-compose` files 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: +This repository is meant to setup your environment easily. -[![Deploy to Azure](https://azuredeploy.net/deploybutton.svg)](https://portal.azure.com/#create/Microsoft.Template/uri/https%3A%2F%2Fraw.githubusercontent.com%2Fbtcpayserver%2Fbtcpayserver-azure%2Fmaster%2Fazuredeploy.json) - -The [Production-NoReverseProxy](Production-NoReverseProxy) `docker-compose` files are used for environment which are already behind a reverse proxy. It exposes BTCPayServer directly on port 80. +# How to use this? -# About accessing services inside those docker compose +## For complete noobs -Several scripts are provided to access the internal of your docker-service: +If you have no knowledge of Linux administration or Docker, we advise you to host BTCPay on Microsoft Azure by opening an account then clicking here -* `litecoin-cli.sh` -* `bitcoin-cli.sh` -* `litecoin-lightning-cli.sh` -* `bitcoin-lightning-cli.sh` +[![Deploy to Azure](https://azuredeploy.net/deploybutton.svg)](https://portal.azure.com/#create/Microsoft.Template/uri/https%3A%2F%2Fraw.githubusercontent.com%2Fbtcpayserver%2Fbtcpayserver-azure%2Fmaster%2Fazuredeploy.json) -We also provide powershell `.ps1` scripts if you are on windows. +Follow this video -You can use it easily: +[![BTCPay - One Click Setup](http://img.youtube.com/vi/Bxs95BdEMHY/mqdefault.jpg)](http://www.youtube.com/watch?v=Bxs95BdEMHY "BTCPay - One Click Setup") -``` -./bitcoin-cli.sh getblockcount -``` +This installation is convenient but will cost you around 60 USD per month. +After all your nodes are synched and you confirm things work fine, you can fine tune save additional money by following [this guide](https://github.com/btcpayserver/btcpayserver-doc/blob/master/PennyPinching.md), and drop to 30 or 40 USD per month. -# For docker noobs +## For technical user -If you are a docker noob here is how you would create a HTTPS ready server. +If, for some reason, you don't want or can't use the Azure deployment explained above then you can install BTCPayServer on your own instance. First step is to make sure you have a domain name pointing to your host, and that port `443` and `80` and externally accessible. Let's assume it is `btcpay.example.com`. -Clone the repository: -``` +You also want to support litecoin, bitcoin and clightning and having HTTPS automatically configured by nginx. + +```bash +# Log as root +sudo su - + +# Create a folder for BTCPay +mkdir BTCPayServer +cd BTCPayServer + +# Clone this repository git clone https://github.com/btcpayserver/btcpayserver-docker cd btcpayserver-docker -``` -Create an `.env` file with the parameters documented in [Production](Production): +# Run btcpay-setup.sh with the right parameters +export BTCPAY_HOST="btcpay.example.com" +export NBITCOIN_NETWORK="mainnet" +export BTCPAYGEN_CRYPTO1="btc" +export BTCPAYGEN_CRYPTO2="ltc" +export BTCPAYGEN_REVERSEPROXY="nginx" +export BTCPAYGEN_LIGHTNING="clightning" +. ./btcpay-setup.sh -i -``` -NBITCOIN_NETWORK=mainnet -BTCPAY_HOST=btcpay.example.com -LETSENCRYPT_EMAIL=me@example.com -ACME_CA_URI=https://acme-v01.api.letsencrypt.org/directory ``` -Save, then run it: +`btcpay-setup.sh` will : -``` -docker-compose -f "$(pwd)/Production/docker-compose.btc-ltc.yml" up -d -``` +* Install Docker +* Install Docker-Compose +* Make sure BTCPay starts at reboot via upstart or systemd +* Setup environment variables to use BTCPay utilities +* Add BTCPay utilities in /usr/bin +* Start BTCPay -Wait a little bit, then you can now browse `https://btcpay.example.com/`. +# Tooling + +A wide range of tooling get available on your system when btcpay is installed: + +* `bitcoin-cli.sh` access your bitcoin node instance +* `bitcoin-lightning-cli.sh` access your clighning node instance +* `changedomain.sh` change the domain of your BTCPayServer +* `btcpay-update.sh` update BTCPay to the latest version +* `btcpay-setup.sh` change the settings of your server (run `. ./btcpay-setup.sh` to get more information about additional parameters, run `. ./btcpay-setup.sh -i` to setup again your btcpay server) + +# Under the hood + +## Prebuilt docker-compose + +For your custom need, you will find some working example of `docker-compose` file which will setup everything for you. + +The [Production](Production) `docker-compose` files 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: -# About generate-docker-compose +[![Deploy to Azure](https://azuredeploy.net/deploybutton.svg)](https://portal.azure.com/#create/Microsoft.Template/uri/https%3A%2F%2Fraw.githubusercontent.com%2Fbtcpayserver%2Fbtcpayserver-azure%2Fmaster%2Fazuredeploy.json) -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. +The [Production-NoReverseProxy](Production-NoReverseProxy) `docker-compose` files are used for environment which are already behind a reverse proxy. It exposes BTCPayServer directly on port 80. -# No docker-compose suit my need, what should I do? +## Generated docker-compose 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). @@ -87,9 +110,9 @@ To configure your custom docker-compose, the following environment variables are * `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`: +Then, running [build.sh](build.sh) (or [build.ps1](build.ps1)) will then generate a `docker-compose.generated.yml` in the [Generated](Generated) folder of this repository. +For example, if you want `btc` and `ltc` support with `nginx` and `clightning` inside `Generated/docker-compose.custom.yml`: Note: The first run might take a while, but next run are instantaneous. On Windows: @@ -116,11 +139,145 @@ BTCPAYGEN_SUBNAME="custom" \ ./build.sh ``` -# How to extend with my own crypto? +## What btcpay-setup do + +`btcpay-setup.sh` utility is a tool which: + +1. Make sure docker and docker-compose are installed on your system +2. Generate a docker-compose via `./build.sh` +3. Setup an [Environment File](https://docs.docker.com/compose/env-file/) to configure your docker-compose +4. Setup environment variables so the tools described in [tooling](#tooling) can work. +5. Add symbolic links of those tools in `/usr/bin` +6. Start docker-compose +7. Make sure it restart at reboot via upstart or systemd. + + +Here is an overview of the files generated by `btcpay-setup.sh`. + +`/etc/profile.d/btcpay-env.sh` ensures that your environment variable are correctly setup when you log in, so you can use the tools. +```bash +export BTCPAYGEN_OLD_PREGEN="false" +export BTCPAYGEN_CRYPTO1="btc" +export BTCPAYGEN_CRYPTO2="" +export BTCPAYGEN_CRYPTO3="" +export BTCPAYGEN_CRYPTO4="" +export BTCPAYGEN_CRYPTO5="" +export BTCPAYGEN_CRYPTO6="" +export BTCPAYGEN_CRYPTO7="" +export BTCPAYGEN_CRYPTO8="" +export BTCPAYGEN_CRYPTO9="" +export BTCPAYGEN_LIGHTNING="clightning" +export BTCPAYGEN_REVERSEPROXY="nginx" +export BTCPAY_DOCKER_COMPOSE="/var/lib/waagent/custom-script/download/0/btcpayserver-docker/Production/docker-compose.generated.yml" +export BTCPAY_BASE_DIRECTORY="/var/lib/waagent/custom-script/download/0" +export BTCPAY_ENV_FILE="/var/lib/waagent/custom-script/download/0/.env" +if cat $BTCPAY_ENV_FILE &> /dev/null; then +export BTCPAY_HOST="$(cat $BTCPAY_ENV_FILE | sed -n 's/^BTCPAY_HOST=\(.*\)$/\1/p')" +export LETSENCRYPT_EMAIL="$(cat $BTCPAY_ENV_FILE | sed -n 's/^LETSENCRYPT_EMAIL=\(.*\)$/\1/p')" +export NBITCOIN_NETWORK="$(cat $BTCPAY_ENV_FILE | sed -n 's/^NBITCOIN_NETWORK=\(.*\)$/\1/p')" +export LIGHTNING_ALIAS="$(cat $BTCPAY_ENV_FILE | sed -n 's/^LIGHTNING_ALIAS=\(.*\)$/\1/p')" +export ACME_CA_URI="$(cat $BTCPAY_ENV_FILE | sed -n 's/^ACME_CA_URI=\(.*\)$/\1/p')" +fi +``` + +`/etc/systemd/system/btcpayserver.service` file ensure that you can control btcpay via `systemctl`, and that btcpay server start on reboot: + +```ini +[Unit] +Description=BTCPayServer service +After=docker.service network-online.target +Requires=docker.service network-online.target + +[Service] +Type=oneshot +RemainAfterExit=yes + +ExecStart=/bin/bash -c '. /etc/profile.d/btcpay-env.sh && cd "$(dirname $BTCPAY_ENV_FILE)" && docker-compose -f "$BTCPAY_DOCKER_COMPOSE" up -d' +ExecStop=/bin/bash -c '. /etc/profile.d/btcpay-env.sh && cd "$(dirname $BTCPAY_ENV_FILE)" && docker-compose -f "$BTCPAY_DOCKER_COMPOSE" stop' +ExecReload=/bin/bash -c '. /etc/profile.d/btcpay-env.sh && cd "$(dirname $BTCPAY_ENV_FILE)" && docker-compose -f "$BTCPAY_DOCKER_COMPOSE" restart' + +[Install] +WantedBy=multi-user.target +``` + +`.env` file (`$BTCPAY_ENV_FILE`) are the environment variable passed to the containers managed by your docker-compose: + +```ini +BTCPAY_HOST=btcpay.example.com +ACME_CA_URI=https://acme-v01.api.letsencrypt.org/directory +NBITCOIN_NETWORK=mainnet +LETSENCRYPT_EMAIL=me@example.com +``` + +# How to extend with your 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/src/CryptoDefinition.cs)) -Congratulation! \ No newline at end of file +Now if you want to test, DOT NOT USE `build.sh`, because this utility is a pre-built docker image. +Instead, install [.NET Core 2.1 SDK](https://www.microsoft.com/net/download/windows) then run: + +```bash +BTCPAYGEN_CRYPTO1="xxx" +BTCPAYGEN_SUBNAME="test" +cd docker-compose-generator/src +dotnet run +``` + +This will generate your docker-compose in the `Generated` folder, which you can then try by yourself. +Note that BTCPayServer developers will not spend time testing your image, so make sure it works. + +# For docker noobs + +If you are a docker noob here is how you would create a HTTPS ready server. + +First step is to make sure you have a domain name pointing to your host, and that port `443` and `80` and externally accessible. +Let's assume it is `btcpay.example.com`. + +Clone the repository: +``` +git clone https://github.com/btcpayserver/btcpayserver-docker +cd btcpayserver-docker +``` + +Create an `.env` file with the parameters documented in [Production](Production): + +``` +NBITCOIN_NETWORK=mainnet +BTCPAY_HOST=btcpay.example.com +LETSENCRYPT_EMAIL=me@example.com +ACME_CA_URI=https://acme-v01.api.letsencrypt.org/directory +``` + +Save, then run it: + +``` +docker-compose -f "$(pwd)/Production/docker-compose.btc-ltc.yml" up -d +``` + +Wait a little bit, then you can now browse `https://btcpay.example.com/`. + +# FAQ + +## How can I modify my environment? + +As root, run `. btcpay-setup.sh`, this will show you the environment variable it is expecting. +For example if you support `btc` and `ltc` already, and wants to add `btg`. + +```bash +export BTCPAYGEN_CRYPTO3='btg' +. btcpay-setup.sh -i +``` + +## I deployed before btcpay-setup.sh existed, can I migrate to this new system? + +Yes, the following command will migrate you to this new system: + +```bash +sudo su - +btcpay-update.sh +cd $DOWNLOAD_ROOT/btcpayserver-docker +. ./btcpay-setup.sh -i +``` \ No newline at end of file diff --git a/btcpay-restart.sh b/btcpay-restart.sh new file mode 100755 index 0000000..76e227c --- /dev/null +++ b/btcpay-restart.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +. /etc/profile.d/btcpay-env.sh + +cd "`dirname $BTCPAY_ENV_FILE`" +docker-compose -f $BTCPAY_DOCKER_COMPOSE down +docker-compose -f $BTCPAY_DOCKER_COMPOSE up -d diff --git a/btcpay-setup.sh b/btcpay-setup.sh index 9670a0c..4776c31 100755 --- a/btcpay-setup.sh +++ b/btcpay-setup.sh @@ -10,14 +10,16 @@ if [[ $EUID -ne 0 ]]; then return fi -if [[ ! -d "Production-NoReverseProxy" ]]; then - echo "You must run this script from inside the btcpayserver-docker folder" - return -fi - -if ! git -C . rev-parse; then - echo "You must run this script inside the git repository of btcpayserver-docker" - return +# Verify we are in right folder. If we are not, let's go in the parent folder of the current docker-compose. +if ! git -C . rev-parse &> /dev/null || [ ! -d "Generated" ]; then + if [ ! -z $BTCPAY_DOCKER_COMPOSE ]; then + cd $(dirname $BTCPAY_DOCKER_COMPOSE) + cd .. + fi + if ! git -C . rev-parse || [ ! -d "Generated" ]; then + echo "You must run this script inside the git repository of btcpayserver-docker" + return + fi fi function display_help () { @@ -65,16 +67,80 @@ if [ "$1" != "-i" ]; then return fi +######### Migration: old pregen environment to new environment ############ +if [ ! -z $BTCPAY_DOCKER_COMPOSE ] && [ ! -z $DOWNLOAD_ROOT ] && [ -z $BTCPAYGEN_MIGRATED_PREGEN ]; then + echo "Old pregen docker deployment detected. Migrating..." + rm "$DOWNLOAD_ROOT/btcpay-restart.sh" + rm "$DOWNLOAD_ROOT/btcpay-update.sh" + rm "$DOWNLOAD_ROOT/changedomain.sh" + rm "$DOWNLOAD_ROOT/entrypoint.sh" + DOWNLOAD_ROOT="" + BTCPAYGEN_MIGRATED_PREGEN="true" + # Migration: old deployment store those in BTCPAY_ENV_FILE + BTCPAY_HOST=$(cat $BTCPAY_ENV_FILE | sed -n 's/^BTCPAY_HOST=\(.*\)$/\1/p') + ACME_CA_URI=$(cat $BTCPAY_ENV_FILE | sed -n 's/^ACME_CA_URI=\(.*\)$/\1/p') + NBITCOIN_NETWORK=$(cat $BTCPAY_ENV_FILE | sed -n 's/^NBITCOIN_NETWORK=\(.*\)$/\1/p') + LETSENCRYPT_EMAIL=$(cat $BTCPAY_ENV_FILE | sed -n 's/^LETSENCRYPT_EMAIL=\(.*\)$/\1/p') + LIGHTNING_ALIAS=$(cat $BTCPAY_ENV_FILE | sed -n 's/^LIGHTNING_ALIAS=\(.*\)$/\1/p') + + if [[ $(dirname $BTCPAY_DOCKER_COMPOSE) == *Production ]]; then + BTCPAYGEN_REVERSEPROXY='nginx' + fi + if [[ $(dirname $BTCPAY_DOCKER_COMPOSE) == *Production-NoReverseProxy ]]; then + BTCPAYGEN_REVERSEPROXY='none' + fi + + if [[ $BTCPAY_DOCKER_COMPOSE == *docker-compose.btc.yml ]]; then + BTCPAYGEN_CRYPTO1='btc' + BTCPAYGEN_LIGHTNING='none' + fi + if [[ $BTCPAY_DOCKER_COMPOSE == *docker-compose.btc-clightning.yml ]]; then + BTCPAYGEN_CRYPTO1='btc' + BTCPAYGEN_LIGHTNING='clightning' + fi + if [[ $BTCPAY_DOCKER_COMPOSE == *docker-compose.ltc.yml ]]; then + BTCPAYGEN_CRYPTO1='ltc' + BTCPAYGEN_LIGHTNING='none' + fi + if [[ $BTCPAY_DOCKER_COMPOSE == *docker-compose.ltc-clightning.yml ]]; then + BTCPAYGEN_CRYPTO1='ltc' + BTCPAYGEN_LIGHTNING='clightning' + fi + if [[ $BTCPAY_DOCKER_COMPOSE == *docker-compose.btc-ltc.yml ]]; then + BTCPAYGEN_CRYPTO1='btc' + BTCPAYGEN_CRYPTO2='ltc' + BTCPAYGEN_LIGHTNING='none' + fi + if [[ $BTCPAY_DOCKER_COMPOSE == *docker-compose.btc-ltc-clightning.yml ]]; then + BTCPAYGEN_CRYPTO1='btc' + BTCPAYGEN_CRYPTO2='ltc' + BTCPAYGEN_LIGHTNING='clightning' + fi +fi +######################################################### + : "${LETSENCRYPT_EMAIL:=me@example.com}" +: "${BTCPAYGEN_MIGRATED_PREGEN:=false}" : "${NBITCOIN_NETWORK:=mainnet}" : "${BTCPAYGEN_CRYPTO1:=btc}" : "${BTCPAYGEN_REVERSEPROXY:=nginx}" : "${BTCPAYGEN_LIGHTNING:=none}" : "${ACME_CA_URI:=https://acme-v01.api.letsencrypt.org/directory}" +OLD_BTCPAY_DOCKER_COMPOSE=$BTCPAY_DOCKER_COMPOSE ORIGINAL_DIRECTORY=$(pwd) BTCPAY_BASE_DIRECTORY="$(dirname $(pwd))" -BTCPAY_DOCKER_COMPOSE="$(pwd)/Generated/docker-compose.generated.yml" + +if [ "$BTCPAYGEN_MIGRATED_PREGEN" == "true" ]; then + if [[ $(dirname $BTCPAY_DOCKER_COMPOSE) == *Production ]]; then + BTCPAY_DOCKER_COMPOSE="$(pwd)/Production/docker-compose.generated.yml" + elif [[ $(dirname $BTCPAY_DOCKER_COMPOSE) == *Production-NoReverseProxy ]]; then + BTCPAY_DOCKER_COMPOSE="$(pwd)/Production-NoReverseProxy/docker-compose.generated.yml" + fi +else # new deployments must be in Generated + BTCPAY_DOCKER_COMPOSE="$(pwd)/Generated/docker-compose.generated.yml" +fi + BTCPAY_ENV_FILE="$BTCPAY_BASE_DIRECTORY/.env" echo " @@ -101,6 +167,7 @@ Additional exported variables: BTCPAY_DOCKER_COMPOSE=$BTCPAY_DOCKER_COMPOSE BTCPAY_BASE_DIRECTORY=$BTCPAY_BASE_DIRECTORY BTCPAY_ENV_FILE=$BTCPAY_ENV_FILE +BTCPAYGEN_MIGRATED_PREGEN=$BTCPAYGEN_MIGRATED_PREGEN ---------------------- " @@ -118,17 +185,10 @@ if [ "$NBITCOIN_NETWORK" != "mainnet" ] && [ "$NBITCOIN_NETWORK" != "testnet" ] echo "NBITCOIN_NETWORK should be equal to mainnet, testnet or regtest" fi -export BTCPAY_DOCKER_COMPOSE -export BTCPAY_BASE_DIRECTORY -export BTCPAY_ENV_FILE - # Put the variables in /etc/profile.d when a user log interactively touch "/etc/profile.d/btcpay-env.sh" echo " -export BTCPAY_HOST=\"$BTCPAY_HOST\" -export LETSENCRYPT_EMAIL=\"$LETSENCRYPT_EMAIL\" -export NBITCOIN_NETWORK=\"$NBITCOIN_NETWORK\" -export LIGHTNING_ALIAS=\"$LIGHTNING_ALIAS\" +export BTCPAYGEN_OLD_PREGEN=\"$BTCPAYGEN_MIGRATED_PREGEN\" export BTCPAYGEN_CRYPTO1=\"$BTCPAYGEN_CRYPTO1\" export BTCPAYGEN_CRYPTO2=\"$BTCPAYGEN_CRYPTO2\" export BTCPAYGEN_CRYPTO3=\"$BTCPAYGEN_CRYPTO3\" @@ -139,14 +199,32 @@ export BTCPAYGEN_CRYPTO7=\"$BTCPAYGEN_CRYPTO7\" export BTCPAYGEN_CRYPTO8=\"$BTCPAYGEN_CRYPTO8\" export BTCPAYGEN_CRYPTO9=\"$BTCPAYGEN_CRYPTO9\" export BTCPAYGEN_LIGHTNING=\"$BTCPAYGEN_LIGHTNING\" -export ACME_CA_URI=\"$ACME_CA_URI\" +export BTCPAYGEN_REVERSEPROXY=\"$BTCPAYGEN_REVERSEPROXY\" export BTCPAY_DOCKER_COMPOSE=\"$BTCPAY_DOCKER_COMPOSE\" export BTCPAY_BASE_DIRECTORY=\"$BTCPAY_BASE_DIRECTORY\" -export BTCPAY_ENV_FILE=\"$BTCPAY_ENV_FILE\"" > /etc/profile.d/btcpay-env.sh +export BTCPAY_ENV_FILE=\"$BTCPAY_ENV_FILE\" +if cat \$BTCPAY_ENV_FILE &> /dev/null; then +export BTCPAY_HOST=\"\$(cat \$BTCPAY_ENV_FILE | sed -n 's/^BTCPAY_HOST=\(.*\)$/\1/p')\" +export LETSENCRYPT_EMAIL=\"\$(cat \$BTCPAY_ENV_FILE | sed -n 's/^LETSENCRYPT_EMAIL=\(.*\)$/\1/p')\" +export NBITCOIN_NETWORK=\"\$(cat \$BTCPAY_ENV_FILE | sed -n 's/^NBITCOIN_NETWORK=\(.*\)$/\1/p')\" +export LIGHTNING_ALIAS=\"\$(cat \$BTCPAY_ENV_FILE | sed -n 's/^LIGHTNING_ALIAS=\(.*\)$/\1/p')\" +export ACME_CA_URI=\"\$(cat \$BTCPAY_ENV_FILE | sed -n 's/^ACME_CA_URI=\(.*\)$/\1/p')\" +fi +" > /etc/profile.d/btcpay-env.sh chmod +x /etc/profile.d/btcpay-env.sh + +. /etc/profile.d/btcpay-env.sh + echo -e "BTCPay Server environment variables successfully saved in /etc/profile.d/btcpay-env.sh\n" if ! [ -x "$(command -v docker)" ] || ! [ -x "$(command -v docker-compose)" ]; then + apt-get update 2>error + apt-get install -y \ + curl \ + apt-transport-https \ + ca-certificates \ + software-properties-common \ + 2>error curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add - if [ $(lsb_release -cs) == "bionic" ]; then # Bionic not in the repo yet, see https://linuxconfig.org/how-to-install-docker-on-ubuntu-18-04-bionic-beaver @@ -155,12 +233,6 @@ if ! [ -x "$(command -v docker)" ] || ! [ -x "$(command -v docker-compose)" ]; t add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" fi apt-get update 2>error - apt-get install -y \ - curl \ - apt-transport-https \ - ca-certificates \ - software-properties-common \ - 2>error fi if ! [ -x "$(command -v docker)" ]; then @@ -195,8 +267,12 @@ echo -e "BTCPay Server docker-compose parameters saved in $BTCPAY_ENV_FILE\n" # Generate the docker compose in BTCPAY_DOCKER_COMPOSE . ./build.sh +if [ "$BTCPAYGEN_MIGRATED_PREGEN" == "true" ]; then + cp Generated/docker-compose.generated.yml $BTCPAY_DOCKER_COMPOSE +fi + # Schedule for reboot -if [ -d "/etc/systemd/system" ]; then # Use systemd +if [ -x "$(command -v systemctl)" ]; then # Use systemd if [ -e "/etc/init/start_containers.conf" ]; then echo -e "Uninstalling upstart script /etc/init/start_containers.conf" rm "/etc/init/start_containers.conf" @@ -241,25 +317,32 @@ stop on runlevel [!2345] script . /etc/profile.d/btcpay-env.sh - cd \"`dirname \$BTCPAY_ENV_FILE`\" + cd \"\$(dirname \$BTCPAY_ENV_FILE)\" docker-compose -f \"\$BTCPAY_DOCKER_COMPOSE\" up -d end script" > /etc/init/start_containers.conf echo -e "BTCPay Server upstart configured in /etc/init/start_containers.conf\n" initctl reload-configuration - cd "$(dirname $BTCPAY_ENV_FILE)" - docker-compose -f "$BTCPAY_DOCKER_COMPOSE" up -d echo "BTCPay Server started" fi +cd "$(dirname $BTCPAY_ENV_FILE)" + +if [ $OLD_BTCPAY_DOCKER_COMPOSE != $BTCPAY_DOCKER_COMPOSE ]; then + echo "Closing old docker-compose at $OLD_BTCPAY_DOCKER_COMPOSE..." + docker-compose -f "$OLD_BTCPAY_DOCKER_COMPOSE" down +fi + +docker-compose -f "$BTCPAY_DOCKER_COMPOSE" up -d --remove-orphans cd $ORIGINAL_DIRECTORY for scriptname in *.sh; do + if [ "$scriptname" == "build.sh" -o "$scriptname" == "build-pregen.sh" ] ; then + continue; + fi echo "Adding symlink of $scriptname to /usr/bin" chmod +x $scriptname - if [ -e /usr/bin/$scriptname ]; then - rm /usr/bin/$scriptname - fi - ln -s $scriptname /usr/bin + rm /usr/bin/$scriptname &> /dev/null + ln -s "$(pwd)/$scriptname" /usr/bin done diff --git a/btcpay-update.sh b/btcpay-update.sh new file mode 100755 index 0000000..2791695 --- /dev/null +++ b/btcpay-update.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +set -e + +. /etc/profile.d/btcpay-env.sh + +cd "$BTCPAY_BASE_DIRECTORY/btcpayserver-docker" +git pull --force + +if [[ $BTCPAY_DOCKER_COMPOSE == *docker-compose.generated.yml ]]; then + # Generate the docker compose in BTCPAY_DOCKER_COMPOSE + . ./build.sh + if [ "$BTCPAYGEN_MIGRATED_PREGEN" == "true" ]; then + cp Generated/docker-compose.generated.yml $BTCPAY_DOCKER_COMPOSE + fi +fi + +for scriptname in *.sh; do + if [ "$scriptname" == "build.sh" -o "$scriptname" == "build-pregen.sh" ] ; then + continue; + fi + echo "Adding symlink of $scriptname to /usr/bin" + chmod +x $scriptname + rm /usr/bin/$scriptname &> /dev/null + ln -s "$(pwd)/$scriptname" /usr/bin +done + +cd "`dirname $BTCPAY_ENV_FILE`" +docker-compose -f $BTCPAY_DOCKER_COMPOSE up -d --remove-orphans diff --git a/build-pregen.ps1 b/build-pregen.ps1 index 0fb05d7..0bd66e5 100755 --- a/build-pregen.ps1 +++ b/build-pregen.ps1 @@ -1,4 +1,4 @@ # 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 pull btcpayserver/docker-compose-generator docker run -v "$(Get-Location)\Production:/app/Production" -v "$(Get-Location)\Production-NoReverseProxy:/app/Production-NoReverseProxy" --rm btcpayserver/docker-compose-generator pregen \ No newline at end of file diff --git a/build-pregen.sh b/build-pregen.sh index 434fc80..e61eb95 100755 --- a/build-pregen.sh +++ b/build-pregen.sh @@ -1,5 +1,5 @@ #!/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 pull btcpayserver/docker-compose-generator docker run -v "$(pwd)/Production:/app/Production" -v "$(pwd)/Production-NoReverseProxy:/app/Production-NoReverseProxy" --rm btcpayserver/docker-compose-generator pregen \ No newline at end of file diff --git a/build.ps1 b/build.ps1 index 73683e9..09fad1a 100755 --- a/build.ps1 +++ b/build.ps1 @@ -1,7 +1,8 @@ # 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 pull btcpayserver/docker-compose-generator docker run -v "$(Get-Location)\Generated:/app/Generated" ` + -v "$(Get-Location)\docker-compose-generator\docker-fragments:/app/docker-fragments" ` -e "BTCPAYGEN_CRYPTO1=$BTCPAYGEN_CRYPTO1" ` -e "BTCPAYGEN_CRYPTO2=$BTCPAYGEN_CRYPTO2" ` -e "BTCPAYGEN_CRYPTO3=$BTCPAYGEN_CRYPTO3" ` @@ -14,4 +15,8 @@ docker run -v "$(Get-Location)\Generated:/app/Generated" ` -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 + --rm btcpayserver/docker-compose-generator + +If ($BTCPAYGEN_REVERSEPROXY -eq "nginx") { + Copy-Item ".\Production\nginx.tmpl" -Destination ".\Generated" +} diff --git a/build.sh b/build.sh index 6ab0708..439533b 100755 --- a/build.sh +++ b/build.sh @@ -1,8 +1,9 @@ #!/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 pull btcpayserver/docker-compose-generator docker run -v "$(pwd)/Generated:/app/Generated" \ + -v "$(pwd)/docker-compose-generator/docker-fragments:/app/docker-fragments" \ -e "BTCPAYGEN_CRYPTO1=$BTCPAYGEN_CRYPTO1" \ -e "BTCPAYGEN_CRYPTO2=$BTCPAYGEN_CRYPTO2" \ -e "BTCPAYGEN_CRYPTO3=$BTCPAYGEN_CRYPTO3" \ @@ -15,4 +16,8 @@ docker run -v "$(pwd)/Generated:/app/Generated" \ -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 + --rm btcpayserver/docker-compose-generator + +if [ "$BTCPAYGEN_REVERSEPROXY" == "nginx" ]; then + cp Production/nginx.tmpl Generated/nginx.tmpl +fi diff --git a/changedomain.sh b/changedomain.sh new file mode 100755 index 0000000..3f523d8 --- /dev/null +++ b/changedomain.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +. /etc/profile.d/btcpay-env.sh + +export NEW_HOST="$1" +export OLD_HOST=`cat $BTCPAY_ENV_FILE | sed -n 's/^BTCPAY_HOST=\(.*\)$/\1/p'` +echo "Changing domain from \"$OLD_HOST\" to \"$NEW_HOST\"" + +export BTCPAY_HOST="$NEW_HOST" +export ACME_CA_URI="https://acme-v01.api.letsencrypt.org/directory" + +# Modify environment file +sed -i '/^BTCPAY_HOST/d' $BTCPAY_ENV_FILE +sed -i '/^ACME_CA_URI/d' $BTCPAY_ENV_FILE +echo "BTCPAY_HOST=$BTCPAY_HOST" >> $BTCPAY_ENV_FILE +echo "ACME_CA_URI=$ACME_CA_URI" >> $BTCPAY_ENV_FILE + +cd "`dirname $BTCPAY_ENV_FILE`" +docker-compose -f "$BTCPAY_DOCKER_COMPOSE" up -d \ No newline at end of file diff --git a/docker-compose-generator/.dockerignore b/docker-compose-generator/.dockerignore index 5a76cae..35d8b76 100644 --- a/docker-compose-generator/.dockerignore +++ b/docker-compose-generator/.dockerignore @@ -122,3 +122,4 @@ output .vs **/launchSettings.json +docker-fragments/ \ No newline at end of file diff --git a/docker-compose-generator/Dockerfile b/docker-compose-generator/Dockerfile index c7f4c3d..a5da653 100644 --- a/docker-compose-generator/Dockerfile +++ b/docker-compose-generator/Dockerfile @@ -16,6 +16,5 @@ VOLUME /datadir ENV INSIDE_CONTAINER=1 COPY --from=builder "/app" . -COPY docker-fragments docker-fragments ENTRYPOINT ["dotnet", "docker-compose-generator.dll"] diff --git a/docker-compose-generator/docker-fragments/bgold.yml b/docker-compose-generator/docker-fragments/bgold.yml index 6e13e4e..6c08ee5 100644 --- a/docker-compose-generator/docker-fragments/bgold.yml +++ b/docker-compose-generator/docker-fragments/bgold.yml @@ -2,7 +2,7 @@ version: "3" services: bgoldd: - restart: always + restart: unless-stopped container_name: btcpayserver_bgoldd image: kamigawabul/docker-bitcoingold:0.15.0.2 environment: diff --git a/docker-compose-generator/docker-fragments/bitcoin-clightning.yml b/docker-compose-generator/docker-fragments/bitcoin-clightning.yml index edc4190..01500e4 100644 --- a/docker-compose-generator/docker-fragments/bitcoin-clightning.yml +++ b/docker-compose-generator/docker-fragments/bitcoin-clightning.yml @@ -4,7 +4,7 @@ services: clightning_bitcoin: image: nicolasdorier/clightning:0.0.0.16 container_name: btcpayserver_clightning_bitcoin - restart: always + restart: unless-stopped environment: LIGHTNINGD_OPT: | bitcoin-datadir=/etc/bitcoin diff --git a/docker-compose-generator/docker-fragments/bitcoin.yml b/docker-compose-generator/docker-fragments/bitcoin.yml index 3de26b8..8432d91 100644 --- a/docker-compose-generator/docker-fragments/bitcoin.yml +++ b/docker-compose-generator/docker-fragments/bitcoin.yml @@ -2,7 +2,7 @@ version: "3" services: bitcoind: - restart: always + restart: unless-stopped container_name: btcpayserver_bitcoind image: nicolasdorier/docker-bitcoin:0.16.0 environment: diff --git a/docker-compose-generator/docker-fragments/btcpayserver.yml b/docker-compose-generator/docker-fragments/btcpayserver.yml index 25cd3c8..b82bbeb 100644 --- a/docker-compose-generator/docker-fragments/btcpayserver.yml +++ b/docker-compose-generator/docker-fragments/btcpayserver.yml @@ -3,7 +3,7 @@ version: "3" services: btcpayserver: - restart: always + restart: unless-stopped image: nicolasdorier/btcpayserver:1.0.2.21 expose: - "49392" @@ -33,7 +33,7 @@ services: - "nbxplorer_datadir:/root/.nbxplorer" nbxplorer: - restart: always + restart: unless-stopped image: nicolasdorier/nbxplorer:1.0.2.7 expose: - "32838" @@ -44,7 +44,7 @@ services: - "nbxplorer_datadir:/datadir" postgres: - restart: always + restart: unless-stopped image: postgres:9.6.5 volumes: - "postgres_datadir:/var/lib/postgresql/data" diff --git a/docker-compose-generator/docker-fragments/litecoin-clightning.yml b/docker-compose-generator/docker-fragments/litecoin-clightning.yml index 240e6aa..969863a 100644 --- a/docker-compose-generator/docker-fragments/litecoin-clightning.yml +++ b/docker-compose-generator/docker-fragments/litecoin-clightning.yml @@ -4,7 +4,7 @@ services: clightning_litecoin: image: nicolasdorier/clightning:0.0.0.16 container_name: btcpayserver_clightning_litecoin - restart: always + restart: unless-stopped environment: LIGHTNINGD_OPT: | bitcoin-datadir=/etc/litecoin diff --git a/docker-compose-generator/docker-fragments/litecoin.yml b/docker-compose-generator/docker-fragments/litecoin.yml index 061e0d3..c8b73fe 100644 --- a/docker-compose-generator/docker-fragments/litecoin.yml +++ b/docker-compose-generator/docker-fragments/litecoin.yml @@ -2,7 +2,7 @@ version: "3" services: litecoind: - restart: always + restart: unless-stopped container_name: btcpayserver_litecoind image: nicolasdorier/docker-litecoin:0.15.1 environment: diff --git a/docker-compose-generator/docker-fragments/nginx.yml b/docker-compose-generator/docker-fragments/nginx.yml index 2cd9155..170ec8e 100644 --- a/docker-compose-generator/docker-fragments/nginx.yml +++ b/docker-compose-generator/docker-fragments/nginx.yml @@ -2,7 +2,7 @@ version: "3" services: nginx: - restart: always + restart: unless-stopped image: nginx container_name: nginx ports: @@ -17,7 +17,7 @@ services: - btcpayserver nginx-gen: - restart: always + restart: unless-stopped image: jwilder/docker-gen container_name: nginx-gen volumes: @@ -32,7 +32,7 @@ services: - nginx letsencrypt-nginx-proxy-companion: - restart: always + restart: unless-stopped image: jrcs/letsencrypt-nginx-proxy-companion container_name: letsencrypt-nginx-proxy-companion volumes: diff --git a/docker-compose-generator/src/docker-compose-generator.csproj b/docker-compose-generator/src/docker-compose-generator.csproj index 8d4d196..ba248d8 100644 --- a/docker-compose-generator/src/docker-compose-generator.csproj +++ b/docker-compose-generator/src/docker-compose-generator.csproj @@ -2,14 +2,11 @@ Exe - netcoreapp2.0 + netcoreapp2.1 DockerGenerator - - -