Skip to content

Commit 8fad138

Browse files
committed
Improve build system
1 parent 6ebb189 commit 8fad138

File tree

2 files changed

+55
-83
lines changed

2 files changed

+55
-83
lines changed

.github/workflows/ci.yml

+14-60
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
name: Docker CI
2-
on: push
2+
on:
3+
push:
4+
branches:
5+
- master
36
env:
47
DOCKER_BUILDKIT: 1
58
LATEST_TAG: 24.0.1
69
jobs:
710
build:
8-
name: Build
11+
name: Build and push to Docker Hub
912
runs-on: ubuntu-18.04
1013
strategy:
1114
fail-fast: false
1215
matrix:
13-
arch:
14-
- amd64
15-
- arm64v8
16-
- arm32v7
1716
version:
1817
- "24.0.1"
1918
- "23.1"
@@ -42,59 +41,14 @@ jobs:
4241
- "0.13.0"
4342
steps:
4443
- uses: actions/checkout@v1
45-
- name: Register Docker QEMU
46-
if: matrix.arch != 'amd64'
47-
run: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
48-
- name: Build bitcoind
49-
run: docker build --build-arg ARCH=${{matrix.arch}} --build-arg VERSION=${{matrix.version}} -t bitcoind:v${{matrix.version}}-${{matrix.arch}} .
50-
- name: Log image data
51-
run: docker images bitcoind
52-
- name: Log OS details
53-
run: docker run --entrypoint sh bitcoind:v${{matrix.version}}-${{matrix.arch}} '-c' 'uname -a && . /etc/os-release && echo $PRETTY_NAME'
54-
- name: Check bitcoind -version
55-
run: (docker run bitcoind:v${{matrix.version}}-${{matrix.arch}} -version | tee /dev/stderr | grep -q ${{matrix.version}}) 2>&1
56-
- name: Save image tarballs
57-
run: mkdir -p images && docker save bitcoind:v${{matrix.version}}-${{matrix.arch}} | gzip > "images/bitcoind-v${{matrix.version}}-${{matrix.arch}}.tgz"
58-
- name: Print sha256sum of built image
59-
run: sha256sum images/*
60-
- name: Upload image tarballs
61-
uses: actions/[email protected]
62-
with:
63-
name: images
64-
path: images/
65-
publish:
66-
name: Publish
67-
if: github.ref == 'refs/heads/master'
68-
runs-on: ubuntu-18.04
69-
needs: build
70-
steps:
71-
- name: Download image tarballs
72-
uses: actions/[email protected]
73-
with:
74-
name: images
75-
- name: Print sha256sum of all images
76-
run: sha256sum images/*
77-
- name: Load image tarballs
78-
run: for image in images/*; do docker load -i $image; done
79-
- name: Set image namespace
80-
run: docker images bitcoind --format "{{.Tag}}" | while read -r tag; do docker tag "bitcoind:${tag}" "lukechilds/bitcoind:${tag}"; done
81-
- name: Log image data
82-
run: docker images lukechilds/bitcoind
44+
8345
- name: Login to Docker Hub
84-
run: echo "${{secrets.DOCKER_TOKEN}}" | docker login -u=lukechilds --password-stdin
85-
- name: Create and push multi-arch manifests
86-
env:
87-
DOCKER_CLI_EXPERIMENTAL: enabled # To enable manifests
46+
run: echo "${{ secrets.DOCKER_TOKEN }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin
47+
48+
- name: Run Docker buildx
8849
run: |
89-
versions=$(docker images lukechilds/bitcoind --format "{{.Tag}}" | grep amd64 | cut -d- -f1)
90-
for version in $versions; do
91-
tags=$(docker images lukechilds/bitcoind --format "{{.Tag}}" | grep $version- | sed 's/^/lukechilds\/bitcoind\:&/')
92-
if [[ "${version}" = "v${LATEST_TAG}" ]]; then
93-
docker manifest create lukechilds/bitcoind:latest $tags
94-
docker manifest push lukechilds/bitcoind:latest
95-
fi
96-
docker manifest create "lukechilds/bitcoind:${version}" $tags
97-
docker manifest push "lukechilds/bitcoind:${version}"
98-
docker manifest inspect "lukechilds/bitcoind:${version}"
99-
echo
100-
done
50+
docker buildx build \
51+
--platform linux/amd64,linux/arm64,linux/arm/v7 \
52+
--build-arg VERSION=${{matrix.version}} \
53+
--tag ${{ secrets.DOCKER_USERNAME }}/bitcoind:v$VERSION \
54+
--push .

Dockerfile

+41-23
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
ARG ARCH="amd64"
21
ARG VERSION="0.19.1"
32

43
ARG LEGACY_BITCOIN_CORE_RELEASE_KEY="01EA5486DE18A882D4C2684590C8019E36C2E964"
@@ -12,34 +11,53 @@ ARG PIETER_WUILLE="133EAC179436F14A5CF1B794860FEB804E669320"
1211
ARG SJORS_PROVOOST="ED9BDF7AD6A55E232E84524257FF9BDBCC301009"
1312
ARG KEYS="${LEGACY_BITCOIN_CORE_RELEASE_KEY} ${ANDREW_CHOW} ${JON_ATACK} ${JONAS_SCHNELLI} ${MATT_CORALLO} ${LUKE_DASHJR} ${PETER_TODD} ${PIETER_WUILLE} ${SJORS_PROVOOST}"
1413

15-
FROM $ARCH/debian:stable-slim
14+
# Build stage
15+
FROM --platform=$BUILDPLATFORM debian:stable-slim as builder
1616
LABEL maintainer="Luke Childs <[email protected]>"
1717

18+
ARG TARGETARCH
19+
1820
ARG ARCH
1921
ARG VERSION
2022
ARG KEYS
2123

22-
RUN cd /tmp && \
23-
if [ "${ARCH}" = "amd64" ]; then TARBALL_ARCH=x86_64-linux-gnu; fi && \
24-
if [ "${ARCH}" = "arm64v8" ]; then TARBALL_ARCH=aarch64-linux-gnu; fi && \
25-
if [ "${ARCH}" = "arm32v7" ]; then TARBALL_ARCH=arm-linux-gnueabihf; fi && \
26-
TARBALL="bitcoin-${VERSION}-${TARBALL_ARCH}.tar.gz" && \
27-
apt-get update && \
28-
apt-get install -y wget gpg && \
29-
wget https://bitcoincore.org/bin/bitcoin-core-${VERSION}/${TARBALL} && \
30-
# This file only exists after v22
31-
wget https://bitcoincore.org/bin/bitcoin-core-${VERSION}/SHA256SUMS || true && \
32-
wget https://bitcoincore.org/bin/bitcoin-core-${VERSION}/SHA256SUMS.asc && \
33-
gpg --keyserver keyserver.ubuntu.com --recv-keys $KEYS && \
34-
gpg --verify SHA256SUMS.asc 2>&1 >/dev/null | grep "^gpg: Good signature from" || { echo "No valid signature"; exit 1; } && \
35-
if [ -f SHA256SUMS ]; then CHECKSUM_FILE="SHA256SUMS"; else CHECKSUM_FILE="SHA256SUMS.asc"; fi && \
36-
grep $TARBALL $CHECKSUM_FILE | sha256sum -c && \
37-
# sha256sum -c --ignore-missing "${CHECKSUM_FILE}" \
38-
tar -zxvf $TARBALL --strip-components=1 && \
39-
mv bin/bitcoind /usr/local/bin/ && \
40-
mv bin/bitcoin-cli /usr/local/bin/ && \
41-
apt-get purge -y wget gpg && \
42-
apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
24+
WORKDIR /build
25+
26+
RUN echo "Installing build deps"
27+
RUN apt-get update
28+
RUN apt-get install -y wget pgp
29+
30+
RUN echo "Deriving tarball name from \$TARGETARCH"
31+
RUN [ "${TARGETARCH}" = "amd64" ] && echo "bitcoin-${VERSION}-x86_64-linux-gnu.tar.gz" > /tarball-name || true
32+
RUN [ "${TARGETARCH}" = "arm64" ] && echo "bitcoin-${VERSION}-aarch64-linux-gnu.tar.gz" > /tarball-name || true
33+
RUN [ "${TARGETARCH}" = "arm" ] && echo "bitcoin-${VERSION}-arm-linux-gnueabihf.tar.gz" > /tarball-name || true
34+
RUN echo "Tarball name: $(cat /tarball-name)"
35+
36+
RUN echo "Downloading release assets"
37+
RUN wget https://bitcoincore.org/bin/bitcoin-core-${VERSION}/$(cat /tarball-name)
38+
RUN wget https://bitcoincore.org/bin/bitcoin-core-${VERSION}/SHA256SUMS.asc
39+
# This file only exists after v22 so allow it to fail
40+
RUN wget https://bitcoincore.org/bin/bitcoin-core-${VERSION}/SHA256SUMS || true
41+
RUN echo "Downloaded release assets:" && ls
42+
43+
RUN echo "Verifying PGP signatures"
44+
RUN gpg --keyserver keyserver.ubuntu.com --recv-keys $KEYS
45+
RUN gpg --verify SHA256SUMS.asc 2>&1 >/dev/null | grep "^gpg: Good signature from" || { echo "No valid signature"; exit 1; }
46+
RUN echo "PGP signature verification passed"
47+
48+
RUN echo "Verifying checksums"
49+
RUN [ -f SHA256SUMS ] && cp SHA256SUMS /sha256sums || cp SHA256SUMS.asc /sha256sums
50+
RUN grep $(cat /tarball-name) /sha256sums | sha256sum -c
51+
RUN echo "Chucksums verified ok"
52+
53+
RUN echo "Extracting release assets"
54+
RUN tar -zxvf $(cat /tarball-name) --strip-components=1
55+
56+
# Final image
57+
FROM debian:stable-slim
58+
59+
COPY --from=builder /build/bin/bitcoind /bin
60+
COPY --from=builder /build/bin/bitcoin-cli /bin
4361

4462
ENV HOME /data
4563
VOLUME /data/.bitcoin

0 commit comments

Comments
 (0)