diff --git a/.github/workflows/build.yml b/.github/workflows/ci.yml similarity index 58% rename from .github/workflows/build.yml rename to .github/workflows/ci.yml index 2f3e2fd..f8846f1 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/ci.yml @@ -65,4 +65,41 @@ jobs: with: subject-name: ${{ env.IMAGE_BASE }} subject-digest: ${{ steps.build.outputs.digest }} - push-to-registry: true \ No newline at end of file + push-to-registry: true + test: + runs-on: ubuntu-latest + needs: build + timeout-minutes: 45 + env: + CONTAINER_NAME: testnet4 + steps: + - run: | + docker pull ${{ needs.build.outputs.IMAGE }} + docker tag ${{ needs.build.outputs.IMAGE }} bitcoin-core-docker + - uses: actions/checkout@v4 + - run: ./examples/${CONTAINER_NAME}.sh + - name: Wait for healthy + run: | + while docker exec -i ${CONTAINER_NAME} /opt/wallet-health.sh; do + if ! docker ps | grep ${CONTAINER_NAME}; then + echo "Container stopped?" + exit 1 + fi + echo "waiting for ${CONTAINER_NAME} health" + echo "Last log: $(docker logs -n1 ${CONTAINER_NAME})" + sleep 15 + done + - name: Restart container + run: | + docker restart ${CONTAINER_NAME} + - name: Wait for healthy after restart + run: | + while docker exec -i ${CONTAINER_NAME} /opt/wallet-health.sh; do + if ! docker ps | grep ${CONTAINER_NAME}; then + echo "Container stopped?" + exit 1 + fi + echo "waiting for ${CONTAINER_NAME} health" + echo "Last log: $(docker logs -n1 ${CONTAINER_NAME})" + sleep 15 + done \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 87d58d5..f29287b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,6 +22,6 @@ VOLUME ["/root/.bitcoin"] RUN bitcoind -version | grep "Bitcoin Core version v${BITCOIN_VERSION}" -COPY wallet.sh /opt/wallet.sh +COPY wallet.sh wallet-health.sh /opt/ CMD ["bitcoind"] \ No newline at end of file diff --git a/examples/testnet4.sh b/examples/testnet4.sh index ad97bd6..e73733b 100755 --- a/examples/testnet4.sh +++ b/examples/testnet4.sh @@ -6,5 +6,5 @@ docker run -d \ -e RPC_USER=default \ -e RPC_PASSWORD=default \ -e WALLET_NAME=default \ - -e WALLET_ADDRESS=110yMxB69Fp5kYQtdA7lpQWZWCMna2dtjl \ + -e WALLET_ADDRESS=tb1qfm8a8pxer0kmfa4xlk34e44xpr8g46ae0v04dw \ bitcoin-core-docker /opt/wallet.sh \ No newline at end of file diff --git a/wallet-health.sh b/wallet-health.sh new file mode 100644 index 0000000..4ac668c --- /dev/null +++ b/wallet-health.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +set -eo pipefail + +# this script checks if a wallet exists and is not scanning + +echo "Getting wallet info" +wallet_info=$(bitcoin-cli -rpcwallet=$1 getwalletinfo) + +if [[ $(echo "$wallet_info" | jq -r '.scanning') == "true" ]]; then + echo "Error: Wallet is currently scanning" >&2 + exit 1 +fi diff --git a/wallet.sh b/wallet.sh index 4f35150..34fdecb 100755 --- a/wallet.sh +++ b/wallet.sh @@ -124,7 +124,7 @@ load_wallet() { sleep 5 bitcoin-cli loadwallet ${WALLET_NAME} || echo "wallet already loaded" sleep 5 - bitcoin-cli importaddress "${WALLET_ADDRESS}" "${WALLET_NAME}" true || echo "address already exists" + bitcoin-cli -rpcwallet "${WALLET_NAME}" importaddress "${WALLET_ADDRESS}" "${WALLET_NAME}" true || echo "importaddress failed" } snapshot_restore() {