Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions scripts/build-bitcoin-images-k8s.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/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"
["26.0"]="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}" \
--file Dockerfile_k8 \
. --push
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was not specifying --file Dockerfile_k8s so (for me) it was using the default Dockerfile.

This could be why @josibake observed networking not working? (perhaps patch not applied?)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could have been. I might have built and pushed the images and then renamed the Dockerfile but forgot to update it here. I might be misremembering but I thought I saw bitcoind compiling.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should re-push the images though as there is doubt.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

were the images re-pushed? if not no worries, was going to do it now as part of testing this PR

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not re-push anything


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
84 changes: 84 additions & 0 deletions src/templates/Dockerfile_k8
Original file line number Diff line number Diff line change
@@ -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"]
14 changes: 14 additions & 0 deletions src/templates/isroutable.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
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());
}

/**