Skip to content

Commit

Permalink
Merge pull request #25 from willcl-ark/nightly-debian
Browse files Browse the repository at this point in the history
  • Loading branch information
willcl-ark authored Oct 9, 2024
2 parents 6a687b8 + 601f94d commit 148bac4
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 55 deletions.
20 changes: 10 additions & 10 deletions .github/workflows/master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,18 @@ on:
push:
paths:
- 'master/Dockerfile'
- 'master/alpine/Dockerfile'

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
include:
- type: ""
suffix: ""
- type: "-alpine"
suffix: "/alpine"
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -33,7 +41,7 @@ jobs:
echo "docker_platforms=${PLATFORMS}" | tee -a $GITHUB_OUTPUT
echo "docker_username=bitcoin" | tee -a $GITHUB_OUTPUT
echo "push=${PUSH}" | tee -a $GITHUB_OUTPUT
echo "tags=${REPO}:${BRANCH}" | tee -a $GITHUB_OUTPUT
echo "tags=${REPO}:nightly${{ matrix.type }}" | tee -a $GITHUB_OUTPUT
- name: Login into Docker Hub
uses: docker/login-action@v3
Expand All @@ -55,18 +63,10 @@ jobs:
echo "Push: ${{ steps.prepare.outputs.push }}"
echo "Tags: ${{ steps.prepare.outputs.tags }}"
echo docker buildx build --platform ${{ steps.prepare.outputs.docker_platforms }} \
--output "type=image,push=true" \
--progress=plain \
--build-arg "BUILD_DATE=${{ steps.prepare.outputs.build_date }}" \
--build-arg "VCS_REF=${GITHUB_SHA::8}" \
$(printf "%s" "${TAGS[@]/#/ --tag }" ) \
master/
docker buildx build --platform ${{ steps.prepare.outputs.docker_platforms }} \
--output "type=image,push=${{ steps.prepare.outputs.push }}" \
--progress=plain \
--build-arg "BUILD_DATE=${{ steps.prepare.outputs.build_date }}" \
--build-arg "VCS_REF=${GITHUB_SHA::8}" \
$(printf "%s" "${TAGS[@]/#/ --tag }" ) \
master/
master${{ matrix.suffix }}
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ These images are built with support for the following platforms:

| Image | Platforms |
|------------------------------------|----------------------------------------|
| `bitcoin/bitcoin:latest` | linux/amd64, linux/arm64, linux/arm/v7 |
| `bitcoin/bitcoin:alpine` | linux/amd64 |
| `bitcoin/bitcoin:<version>` | linux/amd64, linux/arm64, linux/arm/v7 |
| `bitcoin/bitcoin:<version>-alpine` | linux/amd64 |
| `bitcoin/bitcoin:master` | linux/amd64 |
| `bitcoin/bitcoin:nightly` | linux/amd64, linux/arm64 |
| `bitcoin/bitcoin:nightly-alpine` | linux/amd64, linux/arm64 |

The Debian-based (non-alpine) images use pre-built binaries pulled from bitcoincore.org or bitcoin.org (or both) as availability dictates. These binaries are built using the Bitcoin Core [reproducible build](https://github.com/bitcoin/bitcoin/blob/master/contrib/guix/README.md) system, and signatures attesting to them can be found in the [guix.sigs](https://github.com/bitcoin-core/guix.sigs) repo. Signatures are checked in the build process for these docker images using the [verify_binaries.py](https://github.com/bitcoin/bitcoin/tree/master/contrib/verify-binaries) script from the bitcoin/bitcoin git repository.

Expand All @@ -34,25 +37,26 @@ The nightly master image is currently alpine-based, source-built, and targeted a
> [IMPORTANT]
> The Alpine Linux distribution, whilst being a resource efficient Linux distribution with security in mind, is not officially supported by the Bitcoin Core team — use at your own risk.
#### Latest version
#### Latest released version

These tags refer to the latest major version, and the latest minor and patch of this version where applicable.

- `bitcoin/bitcoin:latest`: Release binaries directly from bitcoincore.org. Caution when specifying this tag in production as blindly upgrading Bitcoin Core major versions can introduce new behaviours.
- `bitcoin/bitcoin:alpine`: Source-built binaries using the Alpine Linux distribution.

#### Specific version
#### Specific released version

These tags refer to a specific version of Bitcoin Core.

- `bitcoin/bitcoin:<version>`: Release binaries of a specific release directly from bitcoincore.org (e.g. `27.1` or `26`).
- `bitcoin/bitcoin:<version>-alpine`: Source-built binaries of a specific release of Bitcoin Core (e.g. `27.1` or `26`) using the Alpine Linux distribution.

#### Nightly master
#### Nightly master build

This tag refers to a nightly build of https://github.com/bitcoin/bitcoin master branch using Alpine Linux.

- `bitcoin/bitcoin:master`: Source-built binaries on Alpine Linux, compiled nightly using master branch pulled from https://github.com/bitcoin/bitcoin.
- `bitcoin/bitcoin:nightly`: Source-built binaries on Debian Linux, compiled nightly using master branch pulled from https://github.com/bitcoin/bitcoin.
- `bitcoin/bitcoin:nightly-alpine`: Source-built binaries on Alpine Linux, compiled nightly using master branch pulled from https://github.com/bitcoin/bitcoin.

## Usage

Expand Down
63 changes: 25 additions & 38 deletions master/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,59 +1,46 @@
# Build stage for Bitcoin Core
FROM alpine:3.20 AS build

RUN apk --no-cache add \
boost-dev \
build-base \
chrpath \
cmake \
file \
gnupg \
git \
libevent-dev \
libressl \
libtool \
linux-headers \
sqlite-dev \
zeromq-dev
FROM debian:bookworm-slim AS build

LABEL maintainer.0="Will Clark (@willcl-ark)"

RUN apt-get update -y \
&& apt-get install -y build-essential git ca-certificates cmake pkg-config python3 libevent-dev libboost-dev libsqlite3-dev libzmq3-dev systemtap-sdt-dev --no-install-recommends \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

ENV BITCOIN_PREFIX=/opt/bitcoin
WORKDIR /src
RUN git clone -b "master" --single-branch --depth 1 "https://github.com/bitcoin/bitcoin.git"
WORKDIR /src/bitcoin

RUN cmake -B build -DBUILD_TESTS=OFF -DBUILD_UTIL=OFF -DBUILD_TX=ON -DCMAKE_BUILD_TYPE=MinSizeRel -DWITH_CCACHE=OFF -DCMAKE_INSTALL_PREFIX:PATH="${BITCOIN_PREFIX}" && \
cmake --build build -j$(nproc) && \
strip build/src/bitcoin-cli build/src/bitcoin-tx build/src/bitcoind && \
cmake --install build
RUN set -ex \
&& cmake -B build -DBUILD_TESTS=OFF -DBUILD_UTIL=OFF -DBUILD_TX=ON -DCMAKE_BUILD_TYPE=MinSizeRel -DWITH_CCACHE=OFF -DCMAKE_INSTALL_PREFIX:PATH="${BITCOIN_PREFIX}" \
&& cmake --build build -j$(nproc) \
&& strip build/src/bitcoin-cli build/src/bitcoin-tx build/src/bitcoind \
&& cmake --install build

# Copy build artefacts
FROM alpine:3.20
# Second stage
FROM debian:bookworm-slim

ARG UID=100
ARG UID=101
ARG GID=101

LABEL maintainer.0="Will Clark (@willcl-ark)"
ENV BITCOIN_DATA=/home/bitcoin/.bitcoin

RUN addgroup --gid ${GID} --system bitcoin && \
adduser --uid ${UID} --system bitcoin --ingroup bitcoin
RUN apk --no-cache add \
bash \
libevent \
libzmq \
shadow \
sqlite-libs \
su-exec
RUN groupadd --gid ${GID} bitcoin \
&& useradd --create-home --no-log-init -u ${UID} -g ${GID} bitcoin \
&& apt-get update -y \
&& apt-get install -y libevent-dev libboost-dev libsqlite3-dev libzmq3-dev systemtap-sdt-dev --no-install-recommends \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

ENV BITCOIN_DATA=/home/bitcoin/.bitcoin
COPY --from=build /opt/bitcoin /opt
ENV PATH=/opt/bin:$PATH

COPY --from=build /opt/bitcoin /opt
COPY docker-entrypoint.sh /entrypoint.sh

VOLUME ["/home/bitcoin/.bitcoin"]

EXPOSE 8332 8333 18332 18333 18443 18444 38333 38332

ENTRYPOINT ["/entrypoint.sh"]

RUN bitcoind -version | grep "Bitcoin Core version"
CMD ["bitcoind"]
59 changes: 59 additions & 0 deletions master/alpine/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Build stage for Bitcoin Core
FROM alpine:3.20 AS build

RUN apk --no-cache add \
boost-dev \
build-base \
chrpath \
cmake \
file \
gnupg \
git \
libevent-dev \
libressl \
libtool \
linux-headers \
sqlite-dev \
zeromq-dev

ENV BITCOIN_PREFIX=/opt/bitcoin
WORKDIR /src
RUN git clone -b "master" --single-branch --depth 1 "https://github.com/bitcoin/bitcoin.git"
WORKDIR /src/bitcoin

RUN cmake -B build -DBUILD_TESTS=OFF -DBUILD_UTIL=OFF -DBUILD_TX=ON -DCMAKE_BUILD_TYPE=MinSizeRel -DWITH_CCACHE=OFF -DCMAKE_INSTALL_PREFIX:PATH="${BITCOIN_PREFIX}" && \
cmake --build build -j$(nproc) && \
strip build/src/bitcoin-cli build/src/bitcoin-tx build/src/bitcoind && \
cmake --install build

# Copy build artefacts
FROM alpine:3.20

ARG UID=100
ARG GID=101

LABEL maintainer.0="Will Clark (@willcl-ark)"

RUN addgroup --gid ${GID} --system bitcoin && \
adduser --uid ${UID} --system bitcoin --ingroup bitcoin
RUN apk --no-cache add \
bash \
libevent \
libzmq \
shadow \
sqlite-libs \
su-exec

ENV BITCOIN_DATA=/home/bitcoin/.bitcoin
ENV PATH=/opt/bin:$PATH

COPY --from=build /opt/bitcoin /opt
COPY docker-entrypoint.sh /entrypoint.sh

VOLUME ["/home/bitcoin/.bitcoin"]

EXPOSE 8332 8333 18332 18333 18443 18444 38333 38332

ENTRYPOINT ["/entrypoint.sh"]

CMD ["bitcoind"]
39 changes: 39 additions & 0 deletions master/alpine/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/sh
set -e

if [ -n "${UID+x}" ] && [ "${UID}" != "0" ]; then
usermod -u "$UID" bitcoin
fi

if [ -n "${GID+x}" ] && [ "${GID}" != "0" ]; then
groupmod -g "$GID" bitcoin
fi

echo "$0: assuming uid:gid for bitcoin:bitcoin of $(id -u bitcoin):$(id -g bitcoin)"

if [ "$(echo "$1" | cut -c1)" = "-" ]; then
echo "$0: assuming arguments for bitcoind"

set -- bitcoind "$@"
fi

if [ "$(echo "$1" | cut -c1)" = "-" ] || [ "$1" = "bitcoind" ]; then
mkdir -p "$BITCOIN_DATA"
chmod 700 "$BITCOIN_DATA"
# Fix permissions for home dir.
chown -R bitcoin:bitcoin "$(getent passwd bitcoin | cut -d: -f6)"
# Fix permissions for bitcoin data dir.
chown -R bitcoin:bitcoin "$BITCOIN_DATA"

echo "$0: setting data directory to $BITCOIN_DATA"

set -- "$@" -datadir="$BITCOIN_DATA"
fi

if [ "$1" = "bitcoind" ] || [ "$1" = "bitcoin-cli" ] || [ "$1" = "bitcoin-tx" ]; then
echo
exec su-exec bitcoin "$@"
fi

echo
exec "$@"
4 changes: 2 additions & 2 deletions master/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash
set -e

if [ -n "${UID+x}" ] && [ "${UID}" != "0" ]; then
Expand Down Expand Up @@ -32,7 +32,7 @@ fi

if [ "$1" = "bitcoind" ] || [ "$1" = "bitcoin-cli" ] || [ "$1" = "bitcoin-tx" ]; then
echo
exec su-exec bitcoin "$@"
exec gosu bitcoin "$@"
fi

echo
Expand Down

0 comments on commit 148bac4

Please sign in to comment.