Skip to content

Commit fadf038

Browse files
committed
image build: use cmake with docker buildx bake
1 parent 79da159 commit fadf038

File tree

2 files changed

+106
-6
lines changed

2 files changed

+106
-6
lines changed

docker-bake.hcl

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,33 +47,53 @@ group "vulnerable" {
4747
}
4848

4949
target "maintained-base" {
50-
dockerfile = "./Dockerfile"
5150
context = "./resources/images/bitcoin"
5251
args = {
53-
REPO = "bitcoin"
54-
BUILD_ARGS = "--disable-tests --without-gui --disable-bench --disable-fuzz-binary --enable-suppress-external-warnings "
52+
REPO = "bitcoin/bitcoin"
53+
BUILD_ARGS = "--disable-tests --without-gui --disable-bench --disable-fuzz-binary --enable-suppress-external-warnings"
5554
}
5655
platforms = ["linux/amd64", "linux/arm64", "linux/arm/v7"]
5756
}
5857

59-
target "bitcoin-28" {
58+
target "cmake-base" {
6059
inherits = ["maintained-base"]
60+
dockerfile = "./Dockerfile.dev"
61+
args = {
62+
BUILD_ARGS = "-DBUILD_TESTS=OFF -DBUILD_GUI=OFF -DBUILD_BENCH=OFF -DBUILD_FUZZ_BINARY=OFF -DWITH_ZMQ=ON"
63+
}
64+
}
65+
66+
target "autogen-base" {
67+
inherits = ["maintained-base"]
68+
dockerfile = "./Dockerfile"
69+
}
70+
71+
target "bitcoin-master" {
72+
inherits = ["cmake-base"]
73+
tags = ["bitcoindevproject/bitcoin:28.1"]
74+
args = {
75+
COMMIT_SHA = "bd0ee07310c3dcdd08633c69eac330e2e567b235"
76+
}
77+
}
78+
79+
target "bitcoin-28" {
80+
inherits = ["autogen-base"]
6181
tags = ["bitcoindevproject/bitcoin:28.0"]
6282
args = {
6383
COMMIT_SHA = "110183746150428e6385880c79f8c5733b1361ba"
6484
}
6585
}
6686

6787
target "bitcoin-27" {
68-
inherits = ["maintained-base"]
88+
inherits = ["autogen-base"]
6989
tags = ["bitcoindevproject/bitcoin:27.2"]
7090
args = {
7191
COMMIT_SHA = "bf03c458e994abab9be85486ed8a6d8813313579"
7292
}
7393
}
7494

7595
target "bitcoin-26" {
76-
inherits = ["maintained-base"]
96+
inherits = ["autogen-base"]
7797
tags = ["bitcoindevproject/bitcoin:26.2"]
7898
args = {
7999
COMMIT_SHA = "7b7041019ba5e7df7bde1416aa6916414a04f3db"
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Setup deps stage
2+
FROM alpine AS deps
3+
ARG REPO
4+
ARG COMMIT_SHA
5+
ARG BUILD_ARGS
6+
7+
RUN --mount=type=cache,target=/var/cache/apk \
8+
sed -i 's/http\:\/\/dl-cdn.alpinelinux.org/https\:\/\/alpine.global.ssl.fastly.net/g' /etc/apk/repositories \
9+
&& apk --no-cache add \
10+
cmake \
11+
python3 \
12+
boost-dev \
13+
build-base \
14+
chrpath \
15+
file \
16+
gnupg \
17+
git \
18+
libevent-dev \
19+
libressl \
20+
libtool \
21+
linux-headers \
22+
sqlite-dev \
23+
zeromq-dev
24+
25+
COPY isroutable.patch /tmp/
26+
COPY addrman.patch /tmp/
27+
28+
29+
# Clone and patch and build stage
30+
FROM deps AS build
31+
ENV BITCOIN_PREFIX=/opt/bitcoin
32+
WORKDIR /build
33+
34+
RUN set -ex \
35+
&& cd /build \
36+
&& git clone --depth 1 "https://github.com/${REPO}" \
37+
&& cd bitcoin \
38+
&& git fetch --depth 1 origin "$COMMIT_SHA" \
39+
&& git checkout "$COMMIT_SHA" \
40+
&& git apply /tmp/isroutable.patch \
41+
&& git apply /tmp/addrman.patch \
42+
&& sed -i s:sys/fcntl.h:fcntl.h: src/compat/compat.h \
43+
&& cmake -B build \
44+
-DCMAKE_INSTALL_PREFIX=${BITCOIN_PREFIX} \
45+
${BUILD_ARGS} \
46+
&& cmake --build build -j$(nproc) \
47+
&& cmake --install build \
48+
&& strip ${BITCOIN_PREFIX}/bin/bitcoin-cli \
49+
&& strip ${BITCOIN_PREFIX}/bin/bitcoind \
50+
&& rm -f ${BITCOIN_PREFIX}/lib/libbitcoinconsensus.a \
51+
&& rm -f ${BITCOIN_PREFIX}/lib/libbitcoinconsensus.so.0.0.0
52+
53+
# Final clean stage
54+
FROM alpine
55+
ARG UID=100
56+
ARG GID=101
57+
ENV BITCOIN_DATA=/root/.bitcoin
58+
ENV BITCOIN_PREFIX=/opt/bitcoin
59+
ENV PATH=${BITCOIN_PREFIX}/bin:$PATH
60+
LABEL maintainer.0="bitcoindevproject"
61+
62+
RUN addgroup bitcoin --gid ${GID} --system \
63+
&& adduser --uid ${UID} --system bitcoin --ingroup bitcoin
64+
RUN --mount=type=cache,target=/var/cache/apk sed -i 's/http\:\/\/dl-cdn.alpinelinux.org/https\:\/\/alpine.global.ssl.fastly.net/g' /etc/apk/repositories \
65+
&& apk --no-cache add \
66+
bash \
67+
libevent \
68+
libzmq \
69+
shadow \
70+
sqlite-dev \
71+
su-exec
72+
73+
COPY --from=build /opt/bitcoin /usr/local
74+
COPY entrypoint.sh /
75+
76+
VOLUME ["/home/bitcoin/.bitcoin"]
77+
EXPOSE 8332 8333 18332 18333 18443 18444 38333 38332
78+
79+
ENTRYPOINT ["/entrypoint.sh"]
80+
CMD ["bitcoind"]

0 commit comments

Comments
 (0)