Skip to content

Commit 692230b

Browse files
authored
Merge pull request #692 from danvergara/rewrite-image-build-cmake
Add docker buildx bake and support for cmake
2 parents 3c49f6d + 92f7719 commit 692230b

File tree

5 files changed

+355
-199
lines changed

5 files changed

+355
-199
lines changed

docker-bake.hcl

+238
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,238 @@
1+
group "all" {
2+
targets = [
3+
"bitcoin-28",
4+
"bitcoin-27",
5+
"bitcoin-26",
6+
"v0-21-1",
7+
"v0-20-0",
8+
"v0-19-2",
9+
"v0-17-0",
10+
"v0-16-1",
11+
"bitcoin-unknown-message",
12+
"bitcoin-invalid-blocks",
13+
"bitcoin-50-orphans",
14+
"bitcoin-no-mp-trim",
15+
"bitcoin-disabled-opcodes",
16+
"bitcoin-5k-inv"
17+
]
18+
}
19+
20+
group "maintained" {
21+
targets = [
22+
"bitcoin-28",
23+
"bitcoin-27",
24+
"bitcoin-26"
25+
]
26+
}
27+
28+
group "practice" {
29+
targets = [
30+
"bitcoin-unknown-message",
31+
"bitcoin-invalid-blocks",
32+
"bitcoin-50-orphans",
33+
"bitcoin-no-mp-trim",
34+
"bitcoin-disabled-opcodes",
35+
"bitcoin-5k-inv"
36+
]
37+
}
38+
39+
group "vulnerable" {
40+
targets = [
41+
"v0-21-1",
42+
"v0-20-0",
43+
"v0-19-2",
44+
"v0-17-0",
45+
"v0-16-1",
46+
]
47+
}
48+
49+
target "maintained-base" {
50+
context = "./resources/images/bitcoin"
51+
args = {
52+
REPO = "bitcoin/bitcoin"
53+
BUILD_ARGS = "--disable-tests --without-gui --disable-bench --disable-fuzz-binary --enable-suppress-external-warnings"
54+
}
55+
platforms = ["linux/amd64", "linux/arm64", "linux/arm/v7"]
56+
}
57+
58+
target "cmake-base" {
59+
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"]
81+
tags = ["bitcoindevproject/bitcoin:28.0"]
82+
args = {
83+
COMMIT_SHA = "110183746150428e6385880c79f8c5733b1361ba"
84+
}
85+
}
86+
87+
target "bitcoin-27" {
88+
inherits = ["autogen-base"]
89+
tags = ["bitcoindevproject/bitcoin:27.2"]
90+
args = {
91+
COMMIT_SHA = "bf03c458e994abab9be85486ed8a6d8813313579"
92+
}
93+
}
94+
95+
target "bitcoin-26" {
96+
inherits = ["autogen-base"]
97+
tags = ["bitcoindevproject/bitcoin:26.2"]
98+
args = {
99+
COMMIT_SHA = "7b7041019ba5e7df7bde1416aa6916414a04f3db"
100+
}
101+
}
102+
103+
target "practice-base" {
104+
dockerfile = "./Dockerfile"
105+
context = "./resources/images/bitcoin/insecure"
106+
contexts = {
107+
bitcoin-src = "."
108+
}
109+
args = {
110+
ALPINE_VERSION = "3.20"
111+
BITCOIN_VERSION = "28.1.1"
112+
EXTRA_PACKAGES = "sqlite-dev"
113+
EXTRA_RUNTIME_PACKAGES = ""
114+
REPO = "willcl-ark/bitcoin"
115+
}
116+
platforms = ["linux/amd64", "linux/armhf"]
117+
}
118+
119+
target "bitcoin-unknown-message" {
120+
inherits = ["practice-base"]
121+
tags = ["bitcoindevproject/bitcoin:99.0.0-unknown-message"]
122+
args = {
123+
COMMIT_SHA = "ae999611026e941eca5c0b61f22012c3b3f3d8dc"
124+
}
125+
}
126+
127+
target "bitcoin-invalid-blocks" {
128+
inherits = ["practice-base"]
129+
tags = ["bitcoindevproject/bitcoin:98.0.0-invalid-blocks"]
130+
args = {
131+
COMMIT_SHA = "9713324368e5a966ec330389a533ae8ad7a0ea8f"
132+
}
133+
}
134+
135+
target "bitcoin-50-orphans" {
136+
inherits = ["practice-base"]
137+
tags = ["bitcoindevproject/bitcoin:97.0.0-50-orphans"]
138+
args = {
139+
COMMIT_SHA = "cbcb308eb29621c0db3a105e1a1c1788fb0dab6b"
140+
}
141+
}
142+
143+
target "bitcoin-no-mp-trim" {
144+
inherits = ["practice-base"]
145+
tags = ["bitcoindevproject/bitcoin:96.0.0-no-mp-trim"]
146+
args = {
147+
COMMIT_SHA = "a3a15a9a06dd541d1dafba068c00eedf07e1d5f8"
148+
}
149+
}
150+
151+
target "bitcoin-disabled-opcodes" {
152+
inherits = ["practice-base"]
153+
tags = ["bitcoindevproject/bitcoin:95.0.0-disabled-opcodes"]
154+
args = {
155+
COMMIT_SHA = "5bdb8c52a8612cac9aa928c84a499dd701542b2a"
156+
}
157+
}
158+
159+
target "bitcoin-5k-inv" {
160+
inherits = ["practice-base"]
161+
tags = ["bitcoindevproject/bitcoin:94.0.0-5k-inv"]
162+
args = {
163+
COMMIT_SHA = "e70e610e07eea3aeb0c49ae0bd9f4049ffc1b88c"
164+
}
165+
}
166+
167+
target "CVE-base" {
168+
dockerfile = "./Dockerfile"
169+
context = "./resources/images/bitcoin/insecure"
170+
contexts = {
171+
bitcoin-src = "."
172+
}
173+
platforms = ["linux/amd64", "linux/armhf"]
174+
args = {
175+
REPO = "josibake/bitcoin"
176+
}
177+
}
178+
179+
target "v0-16-1" {
180+
inherits = ["CVE-base"]
181+
tags = ["bitcoindevproject/bitcoin:0.16.1"]
182+
args = {
183+
ALPINE_VERSION = "3.7"
184+
BITCOIN_VERSION = "0.16.1"
185+
COMMIT_SHA = "dc94c00e58c60412a4e1a540abdf0b56093179e8"
186+
EXTRA_PACKAGES = "protobuf-dev libressl-dev"
187+
EXTRA_RUNTIME_PACKAGES = "boost boost-program_options libressl"
188+
PRE_CONFIGURE_COMMANDS = "sed -i '/AC_PREREQ/a\\AR_FLAGS=cr' src/univalue/configure.ac && sed -i '/AX_PROG_CC_FOR_BUILD/a\\AR_FLAGS=cr' src/secp256k1/configure.ac && sed -i 's:sys/fcntl.h:fcntl.h:' src/compat.h"
189+
}
190+
}
191+
192+
target "v0-17-0" {
193+
inherits = ["CVE-base"]
194+
tags = ["bitcoindevproject/bitcoin:0.17.0"]
195+
args = {
196+
ALPINE_VERSION = "3.9"
197+
BITCOIN_VERSION = "0.17.0"
198+
COMMIT_SHA = "f6b2db49a707e7ad433d958aee25ce561c66521a"
199+
EXTRA_PACKAGES = "protobuf-dev libressl-dev"
200+
EXTRA_RUNTIME_PACKAGES = "boost boost-program_options libressl sqlite-dev"
201+
}
202+
}
203+
204+
target "v0-19-2" {
205+
inherits = ["CVE-base"]
206+
tags = ["bitcoindevproject/bitcoin:0.19.2"]
207+
args = {
208+
ALPINE_VERSION = "3.12.12"
209+
BITCOIN_VERSION = "0.19.2"
210+
COMMIT_SHA = "e20f83eb5466a7d68227af14a9d0cf66fb520ffc"
211+
EXTRA_PACKAGES = "sqlite-dev libressl-dev"
212+
EXTRA_RUNTIME_PACKAGES = "boost boost-program_options libressl sqlite-dev"
213+
}
214+
}
215+
216+
target "v0-20-0" {
217+
inherits = ["CVE-base"]
218+
tags = ["bitcoindevproject/bitcoin:0.20.0"]
219+
args = {
220+
ALPINE_VERSION = "3.12.12"
221+
BITCOIN_VERSION = "0.20.0"
222+
COMMIT_SHA = "0bbff8feff0acf1693dfe41184d9a4fd52001d3f"
223+
EXTRA_PACKAGES = "sqlite-dev miniupnpc-dev"
224+
EXTRA_RUNTIME_PACKAGES = "boost-filesystem miniupnpc-dev sqlite-dev"
225+
}
226+
}
227+
228+
target "v0-21-1" {
229+
inherits = ["CVE-base"]
230+
tags = ["bitcoindevproject/bitcoin:0.21.1"]
231+
args = {
232+
ALPINE_VERSION = "3.17"
233+
BITCOIN_VERSION = "0.21.1"
234+
COMMIT_SHA = "e0a22f14c15b4877ef6221f9ee2dfe510092d734"
235+
EXTRA_PACKAGES = "sqlite-dev"
236+
EXTRA_RUNTIME_PACKAGES = "boost-filesystem sqlite-dev"
237+
}
238+
}

docs/developer-notes.md

+31
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,34 @@ python3 -m build
7272
# Upload to Pypi
7373
python3 -m twine upload dist/*
7474
```
75+
76+
## Building docker images
77+
78+
The Bitcoin Core docker images used by warnet are specified in the *docker-bake.hcl* file.
79+
This uses the (experimental) `bake` build functionality of docker buildx.
80+
We use [HCL language](https://github.com/hashicorp/hcl) in the declaration file itself.
81+
See the `bake` [documentation](https://docs.docker.com/build/bake/) for more information on specifications, and how to e.g. override arguments.
82+
83+
In order to build (or "bake") a certain image, find the image's target (name) in the *docker-bake.hcl* file, and then run `docker buildx bake <target>`.
84+
85+
```bash
86+
# build the dummy image that will crash on 5k invs
87+
docker buildx bake bitcoin-5k-inv
88+
89+
# build the same image, but set platform to only linux/amd64
90+
docker buildx bake bitcoin-5k-inv --set bitcoin-5k-inv.platform=linux/amd64
91+
```
92+
93+
To load the single-platform build result to `docker images`, run:
94+
95+
```bash
96+
docker buildx bake --load bitcoin-5k-inv
97+
```
98+
99+
Push the build result to a registry by running:
100+
101+
```bash
102+
docker buildx bake --push bitcoin-5k-inv
103+
```
104+
105+
It will automatically push the build result to registry.
+80
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"]

resources/images/bitcoin/insecure/Dockerfile

+6-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,12 @@ RUN mkdir -p ${BERKELEYDB_PREFIX}
4848

4949
WORKDIR /${BERKELEYDB_VERSION}/build_unix
5050

51-
RUN ../dist/configure --enable-cxx --disable-shared --with-pic --prefix=${BERKELEYDB_PREFIX}
51+
ARG TARGETPLATFORM
52+
RUN if [ "$TARGETPLATFORM" = "linux/arm64" ]; then \
53+
../dist/configure --enable-cxx --disable-shared --with-pic --prefix=${BERKELEYDB_PREFIX} --build=aarch64-unknown-linux-gnu; \
54+
else \
55+
../dist/configure --enable-cxx --disable-shared --with-pic --prefix=${BERKELEYDB_PREFIX}; \
56+
fi
5257
RUN make -j$(nproc)
5358
RUN make install
5459
RUN rm -rf ${BERKELEYDB_PREFIX}/docs

0 commit comments

Comments
 (0)