From 25a3f35113a57558453ff08e78854e1891894df9 Mon Sep 17 00:00:00 2001 From: "Andreas M. Antonopoulos" Date: Mon, 15 Jun 2020 10:40:11 -0400 Subject: [PATCH] Docker bitcoind fixes and cleanup --- code/docker/bitcoind-regtest/Dockerfile | 16 +++++++++++----- code/docker/bitcoind-regtest/bashrc | 2 ++ .../bitcoind-start.sh => bitcoind-entrypoint.sh} | 12 +++++++++++- .../bitcoind-regtest/{bitcoind => }/mine.sh | 4 ++++ 4 files changed, 28 insertions(+), 6 deletions(-) rename code/docker/bitcoind-regtest/{bitcoind/bitcoind-start.sh => bitcoind-entrypoint.sh} (68%) rename code/docker/bitcoind-regtest/{bitcoind => }/mine.sh (87%) diff --git a/code/docker/bitcoind-regtest/Dockerfile b/code/docker/bitcoind-regtest/Dockerfile index 3a14fde..41259bd 100644 --- a/code/docker/bitcoind-regtest/Dockerfile +++ b/code/docker/bitcoind-regtest/Dockerfile @@ -19,12 +19,16 @@ ADD $GH_URL/contrib/bitcoin-cli.bash-completion $BC/bitcoin-cli ADD $GH_URL/contrib/bitcoind.bash-completion $BC/bitcoind ADD $GH_URL/contrib/bitcoin-tx.bash-completion $BC/bitcoin-tx -ADD bashrc /root/.bashrc - FROM bitcoind-base AS bitcoind-regtest ADD bitcoind /bitcoind -RUN ln -s /bitcoind /root/.bitcoin +RUN ln -s /bitcoind /root/. + +ADD bashrc /root/.bashrc +ADD bitcoind-entrypoint.sh /usr/local/bin +RUN chmod +x /usr/local/bin/bitcoind-entrypoint.sh +ADD mine.sh /usr/local/bin +RUN chmod +x /usr/local/bin/mine.sh # bitcoind P2P EXPOSE 18444/tcp @@ -36,5 +40,7 @@ EXPOSE 12005/tcp EXPOSE 12006/tcp WORKDIR /bitcoind -CMD /bin/bash /bitcoind/bitcoind-start.sh \ - && /bin/bash /bitcoind/mine.sh +ENTRYPOINT ["/usr/local/bin/bitcoind-entrypoint.sh"] + +# Mine new block every 10 seconds +CMD ["/usr/local/bin/mine.sh"] diff --git a/code/docker/bitcoind-regtest/bashrc b/code/docker/bitcoind-regtest/bashrc index 7062b7c..5f4b902 100644 --- a/code/docker/bitcoind-regtest/bashrc +++ b/code/docker/bitcoind-regtest/bashrc @@ -1,3 +1,5 @@ # Use bash-completion, if available +alias bitcoin-cli="bitcoin-cli -datadir=/bitcoind" + [[ $PS1 && -f /usr/share/bash-completion/bash_completion ]] && \ . /usr/share/bash-completion/bash_completion diff --git a/code/docker/bitcoind-regtest/bitcoind/bitcoind-start.sh b/code/docker/bitcoind-regtest/bitcoind-entrypoint.sh similarity index 68% rename from code/docker/bitcoind-regtest/bitcoind/bitcoind-start.sh rename to code/docker/bitcoind-regtest/bitcoind-entrypoint.sh index e0e5a8b..b6574f0 100644 --- a/code/docker/bitcoind-regtest/bitcoind/bitcoind-start.sh +++ b/code/docker/bitcoind-regtest/bitcoind-entrypoint.sh @@ -1,7 +1,13 @@ #!/bin/bash +set -Eeuo pipefail +echo Starting bitcoind... bitcoind -datadir=/bitcoind -daemon -sleep 5 +until bitcoin-cli -datadir=/bitcoind getblockchaininfo > /dev/null 2>&1 +do + sleep 1 +done +echo bitcoind started export address=`cat /bitcoind/keys/demo_address.txt` export privkey=`cat /bitcoind/keys/demo_privkey.txt` echo "================================================" @@ -10,3 +16,7 @@ echo "Bitcoin address: " ${address} echo "Private key: " ${privkey} echo "================================================" bitcoin-cli -datadir=/bitcoind importprivkey $privkey + +# Executing CMD +echo "$@" +exec "$@" diff --git a/code/docker/bitcoind-regtest/bitcoind/mine.sh b/code/docker/bitcoind-regtest/mine.sh similarity index 87% rename from code/docker/bitcoind-regtest/bitcoind/mine.sh rename to code/docker/bitcoind-regtest/mine.sh index 42fdffd..5e08f57 100755 --- a/code/docker/bitcoind-regtest/bitcoind/mine.sh +++ b/code/docker/bitcoind-regtest/mine.sh @@ -1,4 +1,5 @@ #!/bin/bash +set -Eeuo pipefail export address=`cat /bitcoind/keys/demo_address.txt` export privkey=`cat /bitcoind/keys/demo_privkey.txt` @@ -14,3 +15,6 @@ while sleep 10; do \ bitcoin-cli -datadir=/bitcoind generatetoaddress 1 $address; \ echo "Balance:" `bitcoin-cli -datadir=/bitcoind getbalance`; \ done + +# If loop is interrupted, stop bitcoind +bitcoin-cli -datadir=/bitcoind stop