From 078f7e973be730ee1a5f564953e9a77a75c3d5bf Mon Sep 17 00:00:00 2001 From: wario_is_here Date: Thu, 12 Dec 2024 14:14:06 +0100 Subject: [PATCH 1/2] update to bitcoincore 28.0 --- Bitcoin/28.0/docker-entrypoint.sh | 81 ++++++++++++++++++++++++++++ Bitcoin/28.0/linuxamd64.Dockerfile | 46 ++++++++++++++++ Bitcoin/28.0/linuxarm32v7.Dockerfile | 51 ++++++++++++++++++ Bitcoin/28.0/linuxarm63v8.Dockerfile | 51 ++++++++++++++++++ 4 files changed, 229 insertions(+) create mode 100644 Bitcoin/28.0/docker-entrypoint.sh create mode 100644 Bitcoin/28.0/linuxamd64.Dockerfile create mode 100644 Bitcoin/28.0/linuxarm32v7.Dockerfile create mode 100644 Bitcoin/28.0/linuxarm63v8.Dockerfile diff --git a/Bitcoin/28.0/docker-entrypoint.sh b/Bitcoin/28.0/docker-entrypoint.sh new file mode 100644 index 0000000..5768c20 --- /dev/null +++ b/Bitcoin/28.0/docker-entrypoint.sh @@ -0,0 +1,81 @@ +#!/bin/bash +set -e + +if [[ "$1" == "bitcoin-cli" || "$1" == "bitcoin-tx" || "$1" == "bitcoind" || "$1" == "test_bitcoin" ]]; then + mkdir -p "$BITCOIN_DATA" + + CONFIG_PREFIX="" + if [[ "${BITCOIN_NETWORK}" == "regtest" ]]; then + CONFIG_PREFIX=$'regtest=1\n[regtest]' + elif [[ "${BITCOIN_NETWORK}" == "testnet" ]]; then + CONFIG_PREFIX=$'testnet=1\n[test]' + elif [[ "${BITCOIN_NETWORK}" == "mainnet" ]]; then + CONFIG_PREFIX=$'mainnet=1\n[main]' + elif [[ "${BITCOIN_NETWORK}" == "signet" ]]; then + CONFIG_PREFIX=$'signet=1\n[signet]' + else + BITCOIN_NETWORK="mainnet" + CONFIG_PREFIX=$'mainnet=1\n[main]' + fi + + if [[ "$BITCOIN_WALLETDIR" ]] && [[ "$BITCOIN_NETWORK" ]]; then + NL=$'\n' + WALLETDIR="$BITCOIN_WALLETDIR/${BITCOIN_NETWORK}" + WALLETFILE="${WALLETDIR}/wallet.dat" + mkdir -p "$WALLETDIR" + chown -R bitcoin:bitcoin "$WALLETDIR" + CONFIG_PREFIX="${CONFIG_PREFIX}${NL}walletdir=${WALLETDIR}${NL}" + : "${CREATE_WALLET:=true}" + if ! [[ -f "${WALLETFILE}" ]] && [[ "${CREATE_WALLET}" != "false" ]]; then + echo "The wallet does not exists, creating it at ${WALLETDIR}..." + gosu bitcoin bitcoin-wallet "-datadir=${WALLETDIR}" "-legacy" "-wallet=" create + fi + fi + + cat <<-EOF > "$BITCOIN_DATA/bitcoin.conf" + ${CONFIG_PREFIX} + printtoconsole=1 + rpcallowip=::/0 + ${BITCOIN_EXTRA_ARGS} + EOF + chown bitcoin:bitcoin "$BITCOIN_DATA/bitcoin.conf" + + if [[ "${BITCOIN_TORCONTROL}" ]]; then + # Because bitcoind only accept torcontrol= host as an ip only, we resolve it here and add to config + TOR_CONTROL_HOST=$(echo ${BITCOIN_TORCONTROL} | cut -d ':' -f 1) + TOR_CONTROL_PORT=$(echo ${BITCOIN_TORCONTROL} | cut -d ':' -f 2) + if [[ "$TOR_CONTROL_HOST" ]] && [[ "$TOR_CONTROL_PORT" ]]; then + TOR_IP=$(getent hosts $TOR_CONTROL_HOST | cut -d ' ' -f 1) + echo "torcontrol=$TOR_IP:$TOR_CONTROL_PORT" >> "$BITCOIN_DATA/bitcoin.conf" + echo "Added "torcontrol=$TOR_IP:$TOR_CONTROL_PORT" to $BITCOIN_DATA/bitcoin.conf" + else + echo "Invalid BITCOIN_TORCONTROL" + fi + fi + + # ensure correct ownership and linking of data directory + # we do not update group ownership here, in case users want to mount + # a host directory and still retain access to it + chown -R bitcoin "$BITCOIN_DATA" + ln -sfn "$BITCOIN_DATA" /home/bitcoin/.bitcoin + chown -h bitcoin:bitcoin /home/bitcoin/.bitcoin + rm -f /home/bitcoin/.bitcoin/settings.json + + # peers_dat is routinely corrupted, preventing bitcoind to start, see https://github.com/bitcoin/bitcoin/issues/26599 + # This should be fixed in 24.1, but doesn't hurt to keep it + peers_dat="/home/bitcoin/.bitcoin/peers.dat" + peers_dat_corrupted="/home/bitcoin/.bitcoin/peers_corrupted.dat" + if [[ -f "${peers_dat}" ]]; then + actual_hash=$(head -c -32 "${peers_dat}" | sha256sum | cut -c1-64 | xxd -r -p | sha256sum | cut -c1-64) + expected_hash=$(tail -c 32 "${peers_dat}" | xxd -ps -c 32) + if [[ "${actual_hash}" != "${expected_hash}" ]]; then + echo "${peers_dat} is corrupted, moving it to ${peers_dat_corrupted}" + rm -f "${peers_dat_corrupted}" + mv "${peers_dat}" "${peers_dat_corrupted}" + fi + fi + + exec gosu bitcoin "$@" +else + exec "$@" +fi diff --git a/Bitcoin/28.0/linuxamd64.Dockerfile b/Bitcoin/28.0/linuxamd64.Dockerfile new file mode 100644 index 0000000..bd14560 --- /dev/null +++ b/Bitcoin/28.0/linuxamd64.Dockerfile @@ -0,0 +1,46 @@ +FROM debian:bookworm-slim as builder + +RUN set -ex \ + && apt-get update \ + && apt-get install -qq --no-install-recommends ca-certificates dirmngr gosu wget + +ENV BITCOIN_VERSION 28.0 +ENV BITCOIN_URL https://bitcoincore.org/bin/bitcoin-core-${BITCOIN_VERSION}/bitcoin-${BITCOIN_VERSION}-x86_64-linux-gnu.tar.gz +ENV BITCOIN_SHA256 7fe294b02b25b51acb8e8e0a0eb5af6bbafa7cd0c5b0e5fcbb61263104a82fbc + +# install bitcoin binaries +RUN set -ex \ + && cd /tmp \ + && wget -qO bitcoin.tar.gz "$BITCOIN_URL" \ + && echo "$BITCOIN_SHA256 bitcoin.tar.gz" | sha256sum -c - \ + && mkdir bin \ + && tar -xzvf bitcoin.tar.gz -C /tmp/bin --strip-components=2 "bitcoin-$BITCOIN_VERSION/bin/bitcoin-cli" "bitcoin-$BITCOIN_VERSION/bin/bitcoind" "bitcoin-$BITCOIN_VERSION/bin/bitcoin-wallet" \ + && cd bin \ + && wget -qO gosu "https://github.com/tianon/gosu/releases/download/1.17/gosu-amd64" \ + && echo "bbc4136d03ab138b1ad66fa4fc051bafc6cc7ffae632b069a53657279a450de3 gosu" | sha256sum -c - + +FROM debian:bookworm-slim +COPY --from=builder "/tmp/bin" /usr/local/bin + +ARG BITCOIN_USER_ID=999 +ARG BITCOIN_GROUP_ID=999 + +RUN apt-get update && \ + apt-get install -qq --no-install-recommends xxd && \ + rm -rf /var/lib/apt/lists/* +RUN chmod +x /usr/local/bin/gosu && groupadd -r -g $BITCOIN_GROUP_ID bitcoin && useradd -r -m -u $BITCOIN_USER_ID -g bitcoin bitcoin + +# create data directory +ENV BITCOIN_DATA /data +RUN mkdir "$BITCOIN_DATA" \ + && chown -R bitcoin:bitcoin "$BITCOIN_DATA" \ + && ln -sfn "$BITCOIN_DATA" /home/bitcoin/.bitcoin \ + && chown -h bitcoin:bitcoin /home/bitcoin/.bitcoin + +VOLUME /data + +COPY docker-entrypoint.sh /entrypoint.sh +ENTRYPOINT ["/entrypoint.sh"] + +EXPOSE 8332 8333 18332 18333 18443 18444 +CMD ["bitcoind"] diff --git a/Bitcoin/28.0/linuxarm32v7.Dockerfile b/Bitcoin/28.0/linuxarm32v7.Dockerfile new file mode 100644 index 0000000..59bd1a6 --- /dev/null +++ b/Bitcoin/28.0/linuxarm32v7.Dockerfile @@ -0,0 +1,51 @@ +# Use manifest image which support all architecture +FROM debian:bookworm-slim as builder + +RUN set -ex \ + && apt-get update \ + && apt-get install -qq --no-install-recommends ca-certificates dirmngr gosu wget +RUN apt-get install -qq --no-install-recommends qemu-user-static binfmt-support + +ENV BITCOIN_VERSION 28.0 +ENV BITCOIN_URL https://bitcoincore.org/bin/bitcoin-core-${BITCOIN_VERSION}/bitcoin-${BITCOIN_VERSION}-arm-linux-gnueabihf.tar.gz +ENV BITCOIN_SHA256 e004b7910bedd6dd18b6c52b4eef398d55971da666487a82cd48708d2879727e + +# install bitcoin binaries +RUN set -ex \ + && cd /tmp \ + && wget -qO bitcoin.tar.gz "$BITCOIN_URL" \ + && echo "$BITCOIN_SHA256 bitcoin.tar.gz" | sha256sum -c - \ + && mkdir bin \ + && tar -xzvf bitcoin.tar.gz -C /tmp/bin --strip-components=2 "bitcoin-$BITCOIN_VERSION/bin/bitcoin-cli" "bitcoin-$BITCOIN_VERSION/bin/bitcoind" "bitcoin-$BITCOIN_VERSION/bin/bitcoin-wallet" \ + && cd bin \ + && wget -qO gosu "https://github.com/tianon/gosu/releases/download/1.17/gosu-armhf" \ + && echo "e5866286277ff2a2159fb9196fea13e0a59d3f1091ea46ddb985160b94b6841b gosu" | sha256sum -c - + +# Making sure the builder build an arm image despite being x64 +FROM arm32v7/debian:bookworm-slim + +COPY --from=builder "/tmp/bin" /usr/local/bin +COPY --from=builder /usr/bin/qemu-arm-static /usr/bin/qemu-arm-static + +ARG BITCOIN_USER_ID=999 +ARG BITCOIN_GROUP_ID=999 + +RUN apt-get update && \ + apt-get install -qq --no-install-recommends xxd && \ + rm -rf /var/lib/apt/lists/* +RUN chmod +x /usr/local/bin/gosu && groupadd -r -g $BITCOIN_GROUP_ID bitcoin && useradd -r -m -u $BITCOIN_USER_ID -g bitcoin bitcoin + +# create data directory +ENV BITCOIN_DATA /data +RUN mkdir "$BITCOIN_DATA" \ + && chown -R bitcoin:bitcoin "$BITCOIN_DATA" \ + && ln -sfn "$BITCOIN_DATA" /home/bitcoin/.bitcoin \ + && chown -h bitcoin:bitcoin /home/bitcoin/.bitcoin + +VOLUME /data + +COPY docker-entrypoint.sh /entrypoint.sh +ENTRYPOINT ["/entrypoint.sh"] + +EXPOSE 8332 8333 18332 18333 18443 18444 +CMD ["bitcoind"] diff --git a/Bitcoin/28.0/linuxarm63v8.Dockerfile b/Bitcoin/28.0/linuxarm63v8.Dockerfile new file mode 100644 index 0000000..2745bb1 --- /dev/null +++ b/Bitcoin/28.0/linuxarm63v8.Dockerfile @@ -0,0 +1,51 @@ +# Use manifest image which support all architecture +FROM debian:bookworm-slim as builder + +RUN set -ex \ + && apt-get update \ + && apt-get install -qq --no-install-recommends ca-certificates dirmngr gosu wget +RUN apt-get install -qq --no-install-recommends qemu-user-static binfmt-support + +ENV BITCOIN_VERSION 28.0 +ENV BITCOIN_URL https://bitcoincore.org/bin/bitcoin-core-${BITCOIN_VERSION}/bitcoin-${BITCOIN_VERSION}-aarch64-linux-gnu.tar.gz +ENV BITCOIN_SHA256 7fa582d99a25c354d23e371a5848bd9e6a79702870f9cbbf1292b86e647d0f4e + +# install bitcoin binaries +RUN set -ex \ + && cd /tmp \ + && wget -qO bitcoin.tar.gz "$BITCOIN_URL" \ + && echo "$BITCOIN_SHA256 bitcoin.tar.gz" | sha256sum -c - \ + && mkdir bin \ + && tar -xzvf bitcoin.tar.gz -C /tmp/bin --strip-components=2 "bitcoin-$BITCOIN_VERSION/bin/bitcoin-cli" "bitcoin-$BITCOIN_VERSION/bin/bitcoind" "bitcoin-$BITCOIN_VERSION/bin/bitcoin-wallet" \ + && cd bin \ + && wget -qO gosu "https://github.com/tianon/gosu/releases/download/1.17/gosu-arm64" \ + && echo "c3805a85d17f4454c23d7059bcb97e1ec1af272b90126e79ed002342de08389b gosu" | sha256sum -c - + +# Making sure the builder build an arm image despite being x64 +FROM arm64v8/debian:bookworm-slim + +COPY --from=builder "/tmp/bin" /usr/local/bin +COPY --from=builder /usr/bin/qemu-aarch64-static /usr/bin/qemu-aarch64-static + +ARG BITCOIN_USER_ID=999 +ARG BITCOIN_GROUP_ID=999 + +RUN apt-get update && \ + apt-get install -qq --no-install-recommends xxd && \ + rm -rf /var/lib/apt/lists/* +RUN chmod +x /usr/local/bin/gosu && groupadd -r -g $BITCOIN_GROUP_ID bitcoin && useradd -r -m -u $BITCOIN_USER_ID -g bitcoin bitcoin + +# create data directory +ENV BITCOIN_DATA /data +RUN mkdir "$BITCOIN_DATA" \ + && chown -R bitcoin:bitcoin "$BITCOIN_DATA" \ + && ln -sfn "$BITCOIN_DATA" /home/bitcoin/.bitcoin \ + && chown -h bitcoin:bitcoin /home/bitcoin/.bitcoin + +VOLUME /data + +COPY docker-entrypoint.sh /entrypoint.sh +ENTRYPOINT ["/entrypoint.sh"] + +EXPOSE 8332 8333 18332 18333 18443 18444 +CMD ["bitcoind"] From 87a045a8dcb2409755f0aaa6c203288927d29bc0 Mon Sep 17 00:00:00 2001 From: wario_is_here <117512622+warioishere@users.noreply.github.com> Date: Sat, 14 Dec 2024 09:39:24 +0100 Subject: [PATCH 2/2] cleanup code for corrupted peers.dat not anymore need as solved in https://github.com/bitcoin/bitcoin/pull/26909 --- Bitcoin/28.0/docker-entrypoint.sh | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/Bitcoin/28.0/docker-entrypoint.sh b/Bitcoin/28.0/docker-entrypoint.sh index 5768c20..321138e 100644 --- a/Bitcoin/28.0/docker-entrypoint.sh +++ b/Bitcoin/28.0/docker-entrypoint.sh @@ -53,28 +53,6 @@ if [[ "$1" == "bitcoin-cli" || "$1" == "bitcoin-tx" || "$1" == "bitcoind" || "$1 fi fi - # ensure correct ownership and linking of data directory - # we do not update group ownership here, in case users want to mount - # a host directory and still retain access to it - chown -R bitcoin "$BITCOIN_DATA" - ln -sfn "$BITCOIN_DATA" /home/bitcoin/.bitcoin - chown -h bitcoin:bitcoin /home/bitcoin/.bitcoin - rm -f /home/bitcoin/.bitcoin/settings.json - - # peers_dat is routinely corrupted, preventing bitcoind to start, see https://github.com/bitcoin/bitcoin/issues/26599 - # This should be fixed in 24.1, but doesn't hurt to keep it - peers_dat="/home/bitcoin/.bitcoin/peers.dat" - peers_dat_corrupted="/home/bitcoin/.bitcoin/peers_corrupted.dat" - if [[ -f "${peers_dat}" ]]; then - actual_hash=$(head -c -32 "${peers_dat}" | sha256sum | cut -c1-64 | xxd -r -p | sha256sum | cut -c1-64) - expected_hash=$(tail -c 32 "${peers_dat}" | xxd -ps -c 32) - if [[ "${actual_hash}" != "${expected_hash}" ]]; then - echo "${peers_dat} is corrupted, moving it to ${peers_dat_corrupted}" - rm -f "${peers_dat_corrupted}" - mv "${peers_dat}" "${peers_dat_corrupted}" - fi - fi - exec gosu bitcoin "$@" else exec "$@"