Skip to content

Commit 96ddf6b

Browse files
author
b-l-u-e
committed
fix: auto-detect CMake vs autotools for warnet image build
Signed-off-by: b-l-u-e <8102260+blue@users.noreply.github.com>
1 parent 8436221 commit 96ddf6b

6 files changed

Lines changed: 84 additions & 274 deletions

File tree

.github/workflows/imagebuild.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ jobs:
6666
--build-arg COMMIT_SHA=v$tag \
6767
--build-arg BUILD_ARGS='-DBUILD_TESTS=OFF -DBUILD_GUI=OFF -DBUILD_BENCH=OFF -DBUILD_UTIL=ON -DBUILD_FUZZ_BINARY=OFF -DWITH_ZMQ=ON' \
6868
-t bitcoindevproject/bitcoin:$tag \
69-
--file resources/images/bitcoin/Dockerfile.dev \
69+
--file resources/images/bitcoin/Dockerfile.cmake \
7070
resources/images/bitcoin/ \
7171
--push
7272
done

docker-bake.hcl

Lines changed: 0 additions & 230 deletions
This file was deleted.

docs/developer-notes.md

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -75,31 +75,5 @@ python3 -m twine upload dist/*
7575

7676
## Building docker images
7777

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.
78+
See [docs for `warnet image build` command](./warnet.md#warnet-image-build)
8279

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.

resources/images/bitcoin/Dockerfile renamed to resources/images/bitcoin/Dockerfile.autotools

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Setup deps stage
2-
FROM alpine AS deps
2+
FROM alpine:3.20 AS deps
33
ARG REPO
44
ARG COMMIT_SHA
55
ARG BUILD_ARGS
@@ -31,19 +31,41 @@ FROM deps AS build
3131
ENV BITCOIN_PREFIX=/opt/bitcoin
3232
WORKDIR /build
3333

34+
# Assume $COMMIT_SHA is a git commit but if that fails, then
35+
# assume it is a release tag that can be checked out
3436
RUN set -ex \
3537
&& 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" \
38+
&& git init \
39+
&& git remote add origin "https://github.com/${REPO}" \
40+
41+
# Try commit/branch first
42+
&& if git fetch --depth 1 origin "$COMMIT_SHA:refs/temp/ref" 2>/dev/null; then \
43+
REF=refs/temp/ref; \
44+
else \
45+
46+
# Fallback: fetch tag explicitly into local refs
47+
git fetch --depth 1 origin "refs/tags/$COMMIT_SHA:refs/tags/$COMMIT_SHA"; \
48+
REF="refs/tags/$COMMIT_SHA"; \
49+
fi \
50+
51+
# Resolve tag -> commit if needed
52+
&& resolved=$(git rev-parse --verify "$REF^{commit}") \
53+
&& git checkout "$resolved" \
54+
55+
# Build
4056
&& git apply /tmp/isroutable.patch \
4157
&& git apply /tmp/addrman.patch \
4258
&& sed -i s:sys/fcntl.h:fcntl.h: src/compat/compat.h \
4359
&& ./autogen.sh \
60+
&& DB_PREFIX="$(ls -d /opt/db-* 2>/dev/null | head -n1 || true)" \
61+
&& if [ -n "$DB_PREFIX" ] && [ -d "$DB_PREFIX/lib" ]; then \
62+
export LDFLAGS="-L${DB_PREFIX}/lib"; \
63+
export CPPFLAGS="-g0 -I${DB_PREFIX}/include --param ggc-min-expand=1 --param ggc-min-heapsize=32768"; \
64+
else \
65+
export LDFLAGS=""; \
66+
export CPPFLAGS="-g0 --param ggc-min-expand=1 --param ggc-min-heapsize=32768"; \
67+
fi \
4468
&& ./configure \
45-
LDFLAGS=-L`ls -d /opt/db*`/lib/ \
46-
CPPFLAGS="-g0 -I`ls -d /opt/db*`/include/ --param ggc-min-expand=1 --param ggc-min-heapsize=32768" \
4769
--prefix=${BITCOIN_PREFIX} \
4870
${BUILD_ARGS} \
4971
&& make -j$(nproc) \
@@ -56,8 +78,7 @@ RUN set -ex \
5678
&& rm ${BITCOIN_PREFIX}/bin/bitcoin-wallet \
5779
&& rm ${BITCOIN_PREFIX}/bin/bitcoin-util
5880

59-
# Final clean stage
60-
FROM alpine
81+
FROM alpine:3.20
6182
ARG UID=100
6283
ARG GID=101
6384
ENV BITCOIN_DATA=/root/.bitcoin
@@ -84,4 +105,3 @@ EXPOSE 8332 8333 18332 18333 18443 18444 38333 38332
84105

85106
ENTRYPOINT ["/entrypoint.sh"]
86107
CMD ["bitcoind"]
87-
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ RUN set -ex \
5353
&& resolved=$(git rev-parse --verify "$REF^{commit}") \
5454
&& git checkout "$resolved" \
5555

56+
# Build
5657
&& git apply /tmp/isroutable.patch \
5758
&& git apply /tmp/addrman.patch \
5859
&& sed -i s:sys/fcntl.h:fcntl.h: src/compat/compat.h \
@@ -66,7 +67,6 @@ RUN set -ex \
6667
&& rm -f ${BITCOIN_PREFIX}/lib/libbitcoinconsensus.a \
6768
&& rm -f ${BITCOIN_PREFIX}/lib/libbitcoinconsensus.so.0.0.0
6869

69-
# Final clean stage
7070
FROM alpine:3.20
7171
ARG UID=100
7272
ARG GID=101

0 commit comments

Comments
 (0)