From 78befef79a667665bdc24b4dc60e81af93b38af3 Mon Sep 17 00:00:00 2001 From: kenshin-samourai Date: Thu, 13 Jun 2019 22:40:39 +0200 Subject: [PATCH] add config option exposing the rpc api and zmq notifucations to external apps --- doc/DOCKER_advanced_setups.md | 38 +++++++++++++++++++ doc/DOCKER_setup.md | 1 + docker/my-dojo/conf/docker-bitcoind.conf.tpl | 22 ++++++++++- docker/my-dojo/dojo.sh | 36 +++++++++++++----- .../overrides/bitcoind.rpc.expose.yaml | 8 ++++ 5 files changed, 94 insertions(+), 11 deletions(-) create mode 100644 doc/DOCKER_advanced_setups.md create mode 100644 docker/my-dojo/overrides/bitcoind.rpc.expose.yaml diff --git a/doc/DOCKER_advanced_setups.md b/doc/DOCKER_advanced_setups.md new file mode 100644 index 0000000..9b3828e --- /dev/null +++ b/doc/DOCKER_advanced_setups.md @@ -0,0 +1,38 @@ +# MyDojo - Advanced Setups + +## Expose bitcoind RPC API ans ZMQ notifications to external apps ## + +By default, access to the RPC API of your bitcoind is restricted to Docker containers hosted on the "dojonet" network. + +The following steps allow to expose the RPC API ans ZMQ notifications to applications running on your local machine but outside of Docker. + +``` +# +# If your Docker runs on macos or windows, +# retrieve the local IP address of the VM +# hosting your Docker containers +# + +# Stop your Dojo +./dojo.sh stop + +# Edit the bitcoin config file +nano ./conf/docker-bitcoind.conf + +# +# Set the value of BITCOIND_RPC_EXTERNAL to "on" +# +# If your Docker runs on macos or windows, +# set the value of BITCOIND_RPC_EXTERNAL_IP to the IP address of the VM +# +# Save and exit nano +# + +# Start your Dojo +./dojo.sh start +``` + +With this setting, external applications running on your local machine but outside of Docker should be able to access the following ports: +* 9501: bitcoind zmqpubrawtx notifications +* 9502: bitcoind zmqpubhashblock notifications +* 28256: bitcoind RPC API diff --git a/doc/DOCKER_setup.md b/doc/DOCKER_setup.md index 5ccf884..a67e123 100644 --- a/doc/DOCKER_setup.md +++ b/doc/DOCKER_setup.md @@ -79,6 +79,7 @@ This procedure allows to install a new Dojo from scratch. * BITCOIND_RPC_PASSWORD = password protecting the access to the RPC API of your full node. * If your machine has a lot of RAM, it's recommended that you increase the value of BITCOIND_DB_CACHE for a faster Initial Block Download. * By default, Dojo creates a new onion address for your full node at each startup. Set the value of BITCOIND_EPHEMERAL_HS to 'off' to keep a static address (not recommended). + * This file also provides a few expert settings for advanced setups (e.g.: expose bitcoind RPC API to external apps). See this [doc](./DOCKER_advanced_setups.md) for more details. * Edit docker-mysql.conf.tpl and provide a new value for the following parameters: * MYSQL_ROOT_PASSWORD = password protecting the root account of MySQL, diff --git a/docker/my-dojo/conf/docker-bitcoind.conf.tpl b/docker/my-dojo/conf/docker-bitcoind.conf.tpl index 0202c87..3809a9a 100644 --- a/docker/my-dojo/conf/docker-bitcoind.conf.tpl +++ b/docker/my-dojo/conf/docker-bitcoind.conf.tpl @@ -31,7 +31,27 @@ BITCOIND_MEMPOOL_EXPIRY=72 # Type: numeric BITCOIND_MIN_RELAY_TX_FEE=0.00001 + +# +# EXPERT SETTINGS +# + # Generate a new onion address for bitcoind when Dojo is launched # Activation of this option is recommended for improved privacy. # Values: on | off -BITCOIND_EPHEMERAL_HS=on \ No newline at end of file +BITCOIND_EPHEMERAL_HS=on + +# Expose the RPC API to external apps +# Warning: Do not expose your RPC API to internet! +# See BITCOIND_RPC_EXTERNAL_IP +# Value: on | off +BITCOIND_RPC_EXTERNAL=off + +# IP address used to expose the RPC API to external apps +# This parameter is inactive if BITCOIND_RPC_EXTERNAL isn't set to 'on' +# Warning: Do not expose your RPC API to internet! +# Recommended value: +# linux: 127.0.0.1 +# macos or windows: IP address of the VM running the docker host +# Type: string +BITCOIND_RPC_EXTERNAL_IP=127.0.0.1 \ No newline at end of file diff --git a/docker/my-dojo/dojo.sh b/docker/my-dojo/dojo.sh index a49fe1a..deb98bc 100755 --- a/docker/my-dojo/dojo.sh +++ b/docker/my-dojo/dojo.sh @@ -2,18 +2,34 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )" -if [ -f "$DIR/conf/docker-bitcoind.conf" ]; then - source "$DIR/conf/docker-bitcoind.conf" -fi +# Source a file +source_file() { + if [ -f $1 ]; then + source $1 + fi +} + +source_file "$DIR/conf/docker-bitcoind.conf" +source_file "$DIR/.env" + + +# Docker up +docker_up() { + source_file "$DIR/conf/docker-bitcoind.conf" + + overrides="" -if [ -f "$DIR/.env" ]; then - source "$DIR/.env" -fi + if [ "$BITCOIND_RPC_EXTERNAL" == "on" ]; then + overrides="-f $DIR/overrides/bitcoind.rpc.expose.yaml" + export BITCOIND_RPC_EXTERNAL_IP + fi + eval "docker-compose -f $DIR/docker-compose.yaml $overrides up $1 -d" +} # Start start() { - docker-compose up --remove-orphans -d + docker_up --remove-orphans } # Stop @@ -52,7 +68,7 @@ restart() { sleep 15s docker-compose down - docker-compose up -d + docker_up } # Install @@ -70,7 +86,7 @@ install() { if [ $launchInstall -eq 0 ]; then init_config_files - docker-compose up -d --remove-orphans + docker_up --remove-orphans docker-compose logs --tail=0 --follow fi } @@ -106,7 +122,7 @@ upgrade() { update_config_files cleanup docker-compose build --no-cache - docker-compose up -d --remove-orphans + docker_up --remove-orphans update_dojo_db docker-compose logs --tail=0 --follow fi diff --git a/docker/my-dojo/overrides/bitcoind.rpc.expose.yaml b/docker/my-dojo/overrides/bitcoind.rpc.expose.yaml new file mode 100644 index 0000000..3f059a3 --- /dev/null +++ b/docker/my-dojo/overrides/bitcoind.rpc.expose.yaml @@ -0,0 +1,8 @@ +version: "3.2" + +services: + bitcoind: + ports: + - "${BITCOIND_RPC_EXTERNAL_IP}:28256:28256" + - "${BITCOIND_RPC_EXTERNAL_IP}:9501:9501" + - "${BITCOIND_RPC_EXTERNAL_IP}:9502:9502"