From 2b21335448811be221a68224cd3663aee6ebff95 Mon Sep 17 00:00:00 2001 From: Max Edwards Date: Wed, 22 Nov 2023 11:42:15 +0000 Subject: [PATCH 1/2] added docker image build script for k8s --- scripts/build-bitcoin-images-k8s.sh | 54 +++++++++++++++++++ src/templates/Dockerfile_k8 | 84 +++++++++++++++++++++++++++++ src/templates/isroutable.patch | 13 +++++ 3 files changed, 151 insertions(+) create mode 100755 scripts/build-bitcoin-images-k8s.sh create mode 100644 src/templates/Dockerfile_k8 create mode 100644 src/templates/isroutable.patch diff --git a/scripts/build-bitcoin-images-k8s.sh b/scripts/build-bitcoin-images-k8s.sh new file mode 100755 index 000000000..d078d228b --- /dev/null +++ b/scripts/build-bitcoin-images-k8s.sh @@ -0,0 +1,54 @@ +#!/usr/bin/env bash + +# Create a new builder to enable building multi-platform images +docker buildx create --use + +# Image and Registry info +DOCKER_REGISTRY="bitcoindevproject/k8s-bitcoin-core" +REPO="bitcoin/bitcoin" +BUILD_ARGS="--disable-tests --with-incompatible-bdb --without-gui --disable-bench --disable-fuzz-binary --enable-suppress-external-warnings --without-miniupnpc --without-natpmp" +echo "DOCKER_REGISTRY=${DOCKER_REGISTRY}" +echo "REPO=${REPO}" + +# Tags and their supported architectures +declare -A VERSION_ARCH_MAP=( + ["23.2"]="amd64 arm64 armhf" + ["24.2"]="amd64 arm64 armhf" + ["25.1"]="amd64 arm64 armhf" +) + +if [[ -d "src/templates" ]]; then + cd src/templates || exit 1 +else + echo "Directory src/templates does not exist. Please run this script from the project root." + exit 1 +fi + +# Loop through each tag and its architectures to build and push +for VERSION in "${!VERSION_ARCH_MAP[@]}"; do + IFS=' ' read -ra ARCHS <<< "${VERSION_ARCH_MAP[${VERSION}]}" + IMAGES_LIST=() # Array to store images for manifest + for DOCKER_ARCH in "${ARCHS[@]}"; do + echo "BRANCH=v${VERSION}" + echo "DOCKER_ARCH=${DOCKER_ARCH}" + + IMAGE_TAG="${VERSION}-${DOCKER_ARCH}" + IMAGE_FULL_NAME="${DOCKER_REGISTRY}:${IMAGE_TAG}" + echo "IMAGE_FULL_NAME=${IMAGE_FULL_NAME}" + + # Use Buildx to build the image for the specified architecture + docker buildx build --platform linux/"${DOCKER_ARCH}" \ + --provenance=false \ + --build-arg REPO="${REPO}" \ + --build-arg BRANCH="v${VERSION}" \ + --build-arg BUILD_ARGS="${BUILD_ARGS}" \ + --tag "${IMAGE_FULL_NAME}" \ + . --push + + IMAGES_LIST+=("${IMAGE_FULL_NAME}") + done + + # Create the manifest list for each version under the same repository + MANIFEST_TAG="${DOCKER_REGISTRY}:${VERSION}" + docker buildx imagetools create --tag "${MANIFEST_TAG}" "${IMAGES_LIST[@]}" +done \ No newline at end of file diff --git a/src/templates/Dockerfile_k8 b/src/templates/Dockerfile_k8 new file mode 100644 index 000000000..9cec8a613 --- /dev/null +++ b/src/templates/Dockerfile_k8 @@ -0,0 +1,84 @@ +FROM debian:bookworm-slim as builder +ENV DEBIAN_FRONTEND=noninteractive + +ARG ARCH +ARG REPO +ARG BRANCH +ARG BUILD_ARGS + +# Install dependencies +RUN apt-get update && apt-get install -y --no-install-recommends \ + ca-certificates \ + wget \ + git \ + automake \ + autotools-dev \ + build-essential \ + libtool \ + libboost-dev \ + libevent-dev \ + libdb5.3++-dev \ + libminiupnpc-dev \ + libnatpmp-dev \ + libzmq3-dev \ + libqrencode-dev \ + libsqlite3-dev \ + pkg-config \ + && rm -rf /var/lib/apt/lists/* # Clean up to reduce image size + +# Copy the patch into the container +COPY isroutable.patch /tmp/ + +# Clone, patch, and build +RUN set -ex \ + && mkdir build \ + && cd build \ + && git clone --depth 1 --branch "${BRANCH}" "https://github.com/${REPO}" \ + && cd bitcoin \ + && git apply /tmp/isroutable.patch \ + && ./autogen.sh \ + && ./configure ${BUILD_ARGS} \ + && make -j$(nproc) \ + && make install + +# Shrink image size with a second stage +FROM debian:bookworm-slim + +ARG UID=3338 +ARG GID=3338 +ARG REPO +ARG TOR=0 +ARG WARNET=0 +ARG BITCOIN_ARGS +# env var overrides +ENV UID=$UID +ENV GID=$GID +ENV BITCOIN_DATA=/home/bitcoin/.bitcoin +ENV BITCOIN_ARGS=$BITCOIN_ARGS +ENV TOR=$TOR +ENV WARNET=$WARNET + +RUN set -ex \ + && groupadd --gid ${GID} bitcoin \ + && useradd --create-home --no-log-init -u ${UID} -g ${GID} bitcoin \ + && apt-get update \ + && apt-get install -y --no-install-recommends \ + dnsutils \ + gosu \ + iproute2 \ + tor \ + $(if [ -n "${REPO}" ]; then echo "libboost-dev libevent-dev libdb5.3++-dev libminiupnpc-dev libnatpmp-dev libzmq3-dev libqrencode-dev libsqlite3-dev"; fi) \ + && apt-get clean \ + && rm -rf /var/cache/apt/* /var/lib/apt/lists/* + +COPY --from=builder /usr/local/bin/bitcoind /usr/local/bin/bitcoin-cli /usr/local/bin/ +COPY entrypoint.sh /entrypoint.sh +# Warnet torrc using test network +COPY torrc /etc/tor/warnet-torr + +VOLUME ["/home/bitcoin/.bitcoin"] +EXPOSE 8332 8333 18332 18333 18443 18444 38333 38332 + +ENTRYPOINT ["/entrypoint.sh"] +RUN bitcoind -version | grep -E "Bitcoin Core( Daemon)? version ${BRANCH}" +CMD ["bitcoind"] \ No newline at end of file diff --git a/src/templates/isroutable.patch b/src/templates/isroutable.patch new file mode 100644 index 000000000..05245780c --- /dev/null +++ b/src/templates/isroutable.patch @@ -0,0 +1,13 @@ +diff --git a/src/netaddress.cpp b/src/netaddress.cpp +index 7530334db1..b66cfe5c2f 100644 +--- a/src/netaddress.cpp ++++ b/src/netaddress.cpp +@@ -462,7 +462,7 @@ bool CNetAddr::IsValid() const + */ + bool CNetAddr::IsRoutable() const + { +- return IsValid() && !(IsRFC1918() || IsRFC2544() || IsRFC3927() || IsRFC4862() || IsRFC6598() || IsRFC5737() || IsRFC4193() || IsRFC4843() || IsRFC7343() || IsLocal() || IsInternal()); ++ return IsValid() && !(IsLocal() || IsInternal()); + } + + /** \ No newline at end of file From c191dee22ef1e57168956b1809456989dc8743a9 Mon Sep 17 00:00:00 2001 From: willcl-ark Date: Mon, 22 Jan 2024 13:58:07 +0000 Subject: [PATCH 2/2] Various fixups * remove erroneous whitespace * Reference correct dockerfile * Add Bitcoin Core v26.0 --- scripts/build-bitcoin-images-k8s.sh | 4 +++- src/templates/Dockerfile_k8 | 2 +- src/templates/isroutable.patch | 5 +++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/scripts/build-bitcoin-images-k8s.sh b/scripts/build-bitcoin-images-k8s.sh index d078d228b..ff5f294b5 100755 --- a/scripts/build-bitcoin-images-k8s.sh +++ b/scripts/build-bitcoin-images-k8s.sh @@ -15,6 +15,7 @@ declare -A VERSION_ARCH_MAP=( ["23.2"]="amd64 arm64 armhf" ["24.2"]="amd64 arm64 armhf" ["25.1"]="amd64 arm64 armhf" + ["26.0"]="amd64 arm64 armhf" ) if [[ -d "src/templates" ]]; then @@ -43,6 +44,7 @@ for VERSION in "${!VERSION_ARCH_MAP[@]}"; do --build-arg BRANCH="v${VERSION}" \ --build-arg BUILD_ARGS="${BUILD_ARGS}" \ --tag "${IMAGE_FULL_NAME}" \ + --file Dockerfile_k8 \ . --push IMAGES_LIST+=("${IMAGE_FULL_NAME}") @@ -51,4 +53,4 @@ for VERSION in "${!VERSION_ARCH_MAP[@]}"; do # Create the manifest list for each version under the same repository MANIFEST_TAG="${DOCKER_REGISTRY}:${VERSION}" docker buildx imagetools create --tag "${MANIFEST_TAG}" "${IMAGES_LIST[@]}" -done \ No newline at end of file +done diff --git a/src/templates/Dockerfile_k8 b/src/templates/Dockerfile_k8 index 9cec8a613..fdc921853 100644 --- a/src/templates/Dockerfile_k8 +++ b/src/templates/Dockerfile_k8 @@ -81,4 +81,4 @@ EXPOSE 8332 8333 18332 18333 18443 18444 38333 38332 ENTRYPOINT ["/entrypoint.sh"] RUN bitcoind -version | grep -E "Bitcoin Core( Daemon)? version ${BRANCH}" -CMD ["bitcoind"] \ No newline at end of file +CMD ["bitcoind"] diff --git a/src/templates/isroutable.patch b/src/templates/isroutable.patch index 05245780c..96b36eb27 100644 --- a/src/templates/isroutable.patch +++ b/src/templates/isroutable.patch @@ -9,5 +9,6 @@ index 7530334db1..b66cfe5c2f 100644 - return IsValid() && !(IsRFC1918() || IsRFC2544() || IsRFC3927() || IsRFC4862() || IsRFC6598() || IsRFC5737() || IsRFC4193() || IsRFC4843() || IsRFC7343() || IsLocal() || IsInternal()); + return IsValid() && !(IsLocal() || IsInternal()); } - - /** \ No newline at end of file + + /** +