Dockerfile for Knots 26.1

This commit is contained in:
Léo Haf 2024-03-27 22:05:25 +01:00
parent 267fa2f491
commit ffe60e5884
Signed by: Retropex
GPG Key ID: 0E37EBAB8574F005

227
26.1/Dockerfile Normal file
View File

@ -0,0 +1,227 @@
# This Dockerfile builds Bitcoin Knots and packages it into a minimal `final` image
# VERSION of Bitcoin Knots to be build
# NOTE: Unlike our other images this one is NOT prefixed with `v`,
# as many things (like download URLs) use this form instead.
ARG VERSION=26.1.knots20240325
# CPU architecture to build binaries for
ARG ARCH
# Define default versions so that they don't have to be repeated throughout the file
ARG VER_ALPINE=3.18
# $USER name, and data $DIR to be used in the `final` image
ARG USER=bitcoind
ARG DIR=/data
# Choose where to get bitcoind sources from, options: release, git
# NOTE: Only `SOURCE=git` can be used for RC releases
ARG SOURCE=release
# Choose where to get BerkeleyDB from, options: prebuilt, compile
# NOTE: When compiled here total execution time exceeds allowed CI limits, so pre-built one is used by default
ARG BDB_SOURCE=prebuilt
#
## `preparer-base` installs dependencies needed by both ways of fetching the source,
# as well as imports GPG keys needed to verify authenticity of the source.
#
FROM alpine:${VER_ALPINE} AS preparer-base
RUN apk add --no-cache gnupg
# Guix Builder Keys: https://github.com/bitcoin-core/guix.sigs/tree/main/builder-keys
# curl -s "https://api.github.com/repos/bitcoin-core/guix.sigs/contents/builder-keys" | jq -r '.[].download_url'
ENV KEYS 1A3E761F19D2CC7785C5502EA291A2C45D0C504A CACC7CBB26B3D2EE8FC2F2BC0E37EBAB8574F005 71A3B16735405025D447E8F274810B012346C9A6 \
9EDAFF80E080659604F4A76B2EBB056FD847F8A7
RUN gpg --keyserver keyserver.ubuntu.com --recv-keys $KEYS
#
## Option #1: [default] Fetch bitcoind source from release tarballs
#
FROM preparer-base AS preparer-release
ARG VERSION
# Download sigs
ADD https://bitcoinknots.org/files/26.x/$VERSION/SHA256SUMS.asc ./
# Download checksums
ADD https://bitcoinknots.org/files/26.x/$VERSION/SHA256SUMS ./
# Download source code
ADD https://bitcoinknots.org/files/26.x/$VERSION/bitcoin-26.1.knots20240325.tar.gz ./bitcoin-$VERSION.tar.gz
# Verify that hashes are signed with the previously imported key
RUN gpg --verify SHA256SUMS.asc SHA256SUMS
# Extract
RUN tar -xzf "bitcoin-$VERSION.tar.gz" && \
rm -f "bitcoin-$VERSION.tar.gz"
#
## Option #2: Fetch bitcoind source from GitHub
#
FROM preparer-base AS preparer-git
ARG VERSION
RUN apk add --no-cache git
# Fetch the source code at a specific TAG
RUN git clone -b "v$VERSION" --depth=1 https://github.com/bitcoinknots/bitcoin.git "/bitcoin-$VERSION/"
# Verify tag, and copy source code to predetermined location on success
RUN cd "/bitcoin-$VERSION/" && \
git verify-tag "v$VERSION"
#
## Alias to go around `COPY` not accepting ARGs in value passed to `--from=`
#
FROM preparer-${SOURCE} AS preparer
#
## `berkeleydb-prebuilt` downloads a pre-built BerkeleyDB to make sure
# the overall build time of this Dockerfile fits within CI limits.
#
FROM lncm/berkeleydb:v4.8.30.NC${ARCH:+-${ARCH}} AS berkeleydb-prebuilt
#
## `berkeleydb-compile` builds BerkeleyDB from source using script provided in bitcoind repo.
#
FROM alpine:${VER_ALPINE} AS berkeleydb-compile
# TODO: implement ^^
RUN echo "Not implemented" && exit 1
FROM berkeleydb-${BDB_SOURCE} AS berkeleydb
#
## `builder` builds Bitcoin Knots regardless on how the source, and BDB code were obtained.
#
# NOTE: this stage is emulated using QEMU
# NOTE: `${ARCH:+${ARCH}/}` - if ARCH is set, append `/` to it, leave it empty otherwise
FROM ${ARCH:+${ARCH}/}alpine:${VER_ALPINE} AS builder
ARG VERSION
ARG SOURCE
RUN apk add --no-cache \
autoconf \
automake \
boost-dev \
sqlite-dev \
build-base \
chrpath \
file \
libevent-dev \
libressl \
libtool \
linux-headers \
zeromq-dev
# Fetch pre-built berkeleydb
COPY --from=berkeleydb /opt/ /opt/
# Change to the extracted directory
WORKDIR /bitcoin-$VERSION/
# Copy bitcoin source (downloaded & verified in previous stages)
COPY --from=preparer /bitcoin-$VERSION/ ./
ENV BITCOIN_PREFIX /opt/bitcoin-$VERSION
RUN ./autogen.sh
# TODO: Try to optimize on passed params
RUN ./configure LDFLAGS=-L/opt/db4/lib/ CPPFLAGS=-I/opt/db4/include/ \
CXXFLAGS="-O2" \
--prefix="$BITCOIN_PREFIX" \
--disable-man \
--disable-shared \
--disable-ccache \
--disable-tests \
--enable-static \
--enable-reduce-exports \
--without-gui \
--without-libs \
--with-utils \
--with-sqlite=yes \
--with-daemon
RUN make -j$(( $(nproc) + 1 ))
RUN make install
# List installed binaries pre-strip & strip them
RUN ls -lh "$BITCOIN_PREFIX/bin/"
RUN strip -v "$BITCOIN_PREFIX/bin/bitcoin"*
# List installed binaries post-strip & print their checksums
RUN ls -lh "$BITCOIN_PREFIX/bin/"
RUN sha256sum "$BITCOIN_PREFIX/bin/bitcoin"*
#
## `final` aggregates build results from previous stages into a necessary minimum
# ready to be used, and published to Docker Hub.
#
# NOTE: this stage is emulated using QEMU
# NOTE: `${ARCH:+${ARCH}/}` - if ARCH is set, append `/` to it, leave it empty otherwise
FROM ${ARCH:+${ARCH}/}alpine:${VER_ALPINE} AS final
ARG VERSION
ARG USER
ARG DIR
LABEL org.opencontainers.image.source=https://github.com/bitcoinknots/bitcoin
LABEL org.opencontainers.image.description="Knots v25.1 for umbrel"
LABEL org.opencontainers.image.licenses=MIT
RUN apk add --no-cache \
libevent \
libsodium \
libstdc++ \
libzmq \
sqlite-libs
COPY --from=builder /opt/bitcoin-$VERSION/bin/bitcoin* /usr/local/bin/
# NOTE: Default GID == UID == 1000
RUN adduser --disabled-password \
--home "$DIR/" \
--gecos "" \
"$USER"
USER $USER
# Prevents `VOLUME $DIR/.bitcoind/` being created as owned by `root`
RUN mkdir -p "$DIR/.bitcoin/"
# Expose volume containing all `bitcoind` data
VOLUME $DIR/.bitcoin/
# REST interface
EXPOSE 8080
# P2P network (mainnet, testnet & regnet respectively)
EXPOSE 8333 18333 18444
# RPC interface (mainnet, testnet & regnet respectively)
EXPOSE 8332 18332 18443
# ZMQ ports (for transactions & blocks respectively)
EXPOSE 28332 28333
ENTRYPOINT ["bitcoind"]
CMD ["-zmqpubrawblock=tcp://0.0.0.0:28332", "-zmqpubrawtx=tcp://0.0.0.0:28333"]