From 6f25921336d7b378737338a1b07a5b3ea59a55ce Mon Sep 17 00:00:00 2001 From: "Andreas M. Antonopoulos" Date: Thu, 18 Jun 2020 14:35:47 -0400 Subject: [PATCH] Docker (wait-for-bitcoind) and docker-compose fixes Sequencing of containers now works. --- code/docker/c-lightning/Dockerfile | 5 +++++ .../docker/c-lightning/c-lightning-entrypoint.sh | 3 +++ code/docker/c-lightning/wait-for-bitcoind.sh | 16 ++++++++++++++++ code/docker/eclair/Dockerfile | 7 +++++++ code/docker/eclair/eclair-entrypoint.sh | 4 ++++ code/docker/eclair/wait-for-bitcoind.sh | 16 ++++++++++++++++ code/docker/lnbook-app/docker-compose.yml | 16 ---------------- code/docker/lnd/Dockerfile | 6 +++++- code/docker/lnd/lnd-entrypoint.sh | 2 ++ code/docker/lnd/wait-for-bitcoind.sh | 16 ++++++++++++++++ 10 files changed, 74 insertions(+), 17 deletions(-) create mode 100644 code/docker/c-lightning/wait-for-bitcoind.sh create mode 100644 code/docker/eclair/wait-for-bitcoind.sh create mode 100644 code/docker/lnd/wait-for-bitcoind.sh diff --git a/code/docker/c-lightning/Dockerfile b/code/docker/c-lightning/Dockerfile index 757ae41..595d53e 100644 --- a/code/docker/c-lightning/Dockerfile +++ b/code/docker/c-lightning/Dockerfile @@ -24,6 +24,11 @@ ADD fund-c-lightning.sh /usr/local/bin RUN chmod +x /usr/local/bin/fund-c-lightning.sh ADD logtail.sh /usr/local/bin RUN chmod +x /usr/local/bin/logtail.sh +ADD wait-for-bitcoind.sh /usr/local/bin +RUN chmod +x /usr/local/bin/wait-for-bitcoind.sh EXPOSE 9735 9835 ENTRYPOINT ["/usr/local/bin/c-lightning-entrypoint.sh"] + +# Show logs from beginning and keep following +CMD ["/usr/local/bin/logtail.sh"] diff --git a/code/docker/c-lightning/c-lightning-entrypoint.sh b/code/docker/c-lightning/c-lightning-entrypoint.sh index 8153e0a..0bcd4a6 100644 --- a/code/docker/c-lightning/c-lightning-entrypoint.sh +++ b/code/docker/c-lightning/c-lightning-entrypoint.sh @@ -1,6 +1,9 @@ #!/bin/bash set -Eeuo pipefail +source /usr/local/bin/wait-for-bitcoind.sh + +echo Starting c-lightning... lightningd --lightning-dir=/lightningd --daemon until lightning-cli --lightning-dir=/lightningd --network regtest getinfo > /dev/null 2>&1 diff --git a/code/docker/c-lightning/wait-for-bitcoind.sh b/code/docker/c-lightning/wait-for-bitcoind.sh new file mode 100644 index 0000000..bda3a80 --- /dev/null +++ b/code/docker/c-lightning/wait-for-bitcoind.sh @@ -0,0 +1,16 @@ +#!/bin/bash +set -Eeuo pipefail + +echo Waiting for bitcoind to start... +until bitcoin-cli -rpcconnect=bitcoind -rpcport=18443 -rpcuser=regtest -rpcpassword=regtest getblockchaininfo > /dev/null 2>&1 +do + echo -n "." + sleep 1 +done + +echo Waiting for bitcoind to mine blocks... +until bitcoin-cli -rpcconnect=bitcoind -rpcport=18443 -rpcuser=regtest -rpcpassword=regtest getbalance | jq -e ". > 0" > /dev/null 2>&1 +do + echo -n "." + sleep 1 +done diff --git a/code/docker/eclair/Dockerfile b/code/docker/eclair/Dockerfile index 50b32ae..0518f20 100644 --- a/code/docker/eclair/Dockerfile +++ b/code/docker/eclair/Dockerfile @@ -6,6 +6,8 @@ RUN apt update && apt install -yqq \ RUN apt update && apt install -yqq \ openjdk-11-jdk unzip +COPY --from=lnbook/bitcoind /usr/local/ /usr/local/ + # Install eclair ENV ECLAIR_VER 0.4 ENV ECLAIR_COMMIT 69c538e @@ -25,6 +27,11 @@ ADD eclair-entrypoint.sh /usr/local/bin RUN chmod +x /usr/local/bin/eclair-entrypoint.sh ADD logtail.sh /usr/local/bin RUN chmod +x /usr/local/bin/logtail.sh +ADD wait-for-bitcoind.sh /usr/local/bin +RUN chmod +x /usr/local/bin/wait-for-bitcoind.sh EXPOSE 9735 ENTRYPOINT ["/usr/local/bin/eclair-entrypoint.sh"] + +# Show logs from beginning and keep following +CMD ["/usr/local/bin/logtail.sh"] diff --git a/code/docker/eclair/eclair-entrypoint.sh b/code/docker/eclair/eclair-entrypoint.sh index efb4382..d6110d8 100644 --- a/code/docker/eclair/eclair-entrypoint.sh +++ b/code/docker/eclair/eclair-entrypoint.sh @@ -1,6 +1,8 @@ #!/bin/bash set -Eeuo pipefail +source /usr/local/bin/wait-for-bitcoind.sh + echo Starting eclair... cd /usr/src/eclair-node-${ECLAIR_VER}-${ECLAIR_COMMIT}/ /bin/bash bin/eclair-node.sh -Declair.datadir="/eclair" & @@ -13,6 +15,8 @@ done echo Eclair node started +sleep 2 + # Executing CMD echo "$@" exec "$@" diff --git a/code/docker/eclair/wait-for-bitcoind.sh b/code/docker/eclair/wait-for-bitcoind.sh new file mode 100644 index 0000000..bda3a80 --- /dev/null +++ b/code/docker/eclair/wait-for-bitcoind.sh @@ -0,0 +1,16 @@ +#!/bin/bash +set -Eeuo pipefail + +echo Waiting for bitcoind to start... +until bitcoin-cli -rpcconnect=bitcoind -rpcport=18443 -rpcuser=regtest -rpcpassword=regtest getblockchaininfo > /dev/null 2>&1 +do + echo -n "." + sleep 1 +done + +echo Waiting for bitcoind to mine blocks... +until bitcoin-cli -rpcconnect=bitcoind -rpcport=18443 -rpcuser=regtest -rpcpassword=regtest getbalance | jq -e ". > 0" > /dev/null 2>&1 +do + echo -n "." + sleep 1 +done diff --git a/code/docker/lnbook-app/docker-compose.yml b/code/docker/lnbook-app/docker-compose.yml index 572ffc6..160678e 100644 --- a/code/docker/lnbook-app/docker-compose.yml +++ b/code/docker/lnbook-app/docker-compose.yml @@ -14,19 +14,12 @@ services: - "18443" - "12005" - "12006" - healthcheck: - test: bitcoin-cli -datadir=/bitcoind getblockchaininfo - interval: 2s - timeout: 5s - retries: 30 Alice: container_name: Alice build: context: ../lnd image: lnbook/lnd:latest - depends_on: - - bitcoind networks: - lnnet expose: @@ -37,9 +30,6 @@ services: build: context: ../c-lightning image: lnbook/c-lightning:latest - depends_on: - - bitcoind - - Alice networks: - lnnet expose: @@ -50,9 +40,6 @@ services: build: context: ../eclair image: lnbook/eclair:latest - depends_on: - - bitcoind - - Bob networks: - lnnet expose: @@ -63,9 +50,6 @@ services: build: context: ../lnd image: lnbook/lnd:latest - depends_on: - - bitcoind - - Wei networks: - lnnet expose: diff --git a/code/docker/lnd/Dockerfile b/code/docker/lnd/Dockerfile index 2850d37..325420a 100644 --- a/code/docker/lnd/Dockerfile +++ b/code/docker/lnd/Dockerfile @@ -14,6 +14,8 @@ RUN apt update && apt install -yqq \ curl gosu jq bash-completion COPY --from=lnd-base /go /go +COPY --from=lnbook/bitcoind /usr/local/ /usr/local/ + RUN cp /go/src/github.com/lightningnetwork/lnd/contrib/lncli.bash-completion \ /usr/share/bash-completion/completions/lncli @@ -29,6 +31,8 @@ ADD lnd-entrypoint.sh /usr/local/bin RUN chmod +x /usr/local/bin/lnd-entrypoint.sh ADD logtail.sh /usr/local/bin RUN chmod +x /usr/local/bin/logtail.sh +ADD wait-for-bitcoind.sh /usr/local/bin +RUN chmod +x /usr/local/bin/wait-for-bitcoind.sh # LND RPC EXPOSE 10009/tcp @@ -39,5 +43,5 @@ EXPOSE 9735/tcp WORKDIR /lnd ENTRYPOINT ["/usr/local/bin/lnd-entrypoint.sh"] -# Show lnd logs from beginning and keep following +# Show logs from beginning and keep following CMD ["/usr/local/bin/logtail.sh"] diff --git a/code/docker/lnd/lnd-entrypoint.sh b/code/docker/lnd/lnd-entrypoint.sh index 3ec9b1a..732d15b 100644 --- a/code/docker/lnd/lnd-entrypoint.sh +++ b/code/docker/lnd/lnd-entrypoint.sh @@ -1,6 +1,8 @@ #!/bin/bash set -Eeuo pipefail +source /usr/local/bin/wait-for-bitcoind.sh + echo Starting lnd... lnd --lnddir=/lnd --noseedbackup > /dev/null & diff --git a/code/docker/lnd/wait-for-bitcoind.sh b/code/docker/lnd/wait-for-bitcoind.sh new file mode 100644 index 0000000..bda3a80 --- /dev/null +++ b/code/docker/lnd/wait-for-bitcoind.sh @@ -0,0 +1,16 @@ +#!/bin/bash +set -Eeuo pipefail + +echo Waiting for bitcoind to start... +until bitcoin-cli -rpcconnect=bitcoind -rpcport=18443 -rpcuser=regtest -rpcpassword=regtest getblockchaininfo > /dev/null 2>&1 +do + echo -n "." + sleep 1 +done + +echo Waiting for bitcoind to mine blocks... +until bitcoin-cli -rpcconnect=bitcoind -rpcport=18443 -rpcuser=regtest -rpcpassword=regtest getbalance | jq -e ". > 0" > /dev/null 2>&1 +do + echo -n "." + sleep 1 +done