This repository has been archived by the owner on Oct 2, 2023. It is now read-only.
generated from runcitadel/docker-template
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
146 lines (109 loc) · 4.04 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# This Dockerfile builds Bitcoin Core and packages it into a minimal `final` image
# Define default versions so that they don't have to be repeated throughout the file
ARG VER_ALPINE=3.15
# $USER name, and data $DIR to be used in the `final` image
ARG USER=bitcoind
ARG DIR=/data
# Choose where to get bitcoind sources from, options: release, git
# NOTE: Only `SOURCE=git` can be used for RC releases
ARG SOURCE=release
# Choose where to get BerkeleyDB from, options: prebuilt, compile
# NOTE: When compiled here total execution time exceeds allowed CI limits, so pre-built one is used by default
ARG BDB_SOURCE=prebuilt
FROM alpine:${VER_ALPINE} AS preparer
RUN apk add --no-cache git
# Fetch the source code at a specific TAG
RUN git clone -b "backport/22/perf/faster-getblock" --depth=1 https://github.com/AaronDewes/bitcoin.git "/bitcoin/"
FROM ghcr.io/runcitadel/berkeleydb:main AS berkeleydb
#
## `builder` builds Bitcoin Core regardless on how the source, and BDB code were obtained.
#
# NOTE: this stage is emulated using QEMU
# NOTE: `${ARCH:+${ARCH}/}` - if ARCH is set, append `/` to it, leave it empty otherwise
FROM ${ARCH:+${ARCH}/}alpine:${VER_ALPINE} AS builder
# Use APK repos over HTTPS. See: https://github.com/gliderlabs/docker-alpine/issues/184
RUN sed -i 's|http://dl-cdn.alpinelinux.org|https://alpine.global.ssl.fastly.net|g' /etc/apk/repositories
RUN apk add --no-cache \
autoconf \
automake \
boost-dev \
sqlite-dev \
build-base \
chrpath \
file \
libevent-dev \
libressl \
libtool \
linux-headers \
zeromq-dev
# Fetch pre-built berkeleydb
COPY --from=berkeleydb /opt/ /opt/
# Change to the extracted directory
WORKDIR /bitcoin/
# Copy bitcoin source (downloaded & verified in previous stages)
COPY --from=preparer /bitcoin/ ./
ENV BITCOIN_PREFIX /opt/bitcoin
RUN ./autogen.sh
# TODO: Try to optimize on passed params
RUN ./configure LDFLAGS=-L/opt/db4/lib/ CPPFLAGS=-I/opt/db4/include/ \
CXXFLAGS="-O2" \
--prefix="$BITCOIN_PREFIX" \
--disable-man \
--disable-shared \
--disable-ccache \
--disable-tests \
--enable-static \
--enable-reduce-exports \
--without-gui \
--without-libs \
--with-utils \
--with-sqlite=yes \
--with-daemon
RUN make -j$(( $(nproc) + 1 )) check
RUN make install
# List installed binaries pre-strip & strip them
RUN ls -lh "$BITCOIN_PREFIX/bin/"
RUN strip -v "$BITCOIN_PREFIX/bin/bitcoin"*
# List installed binaries post-strip & print their checksums
RUN ls -lh "$BITCOIN_PREFIX/bin/"
RUN sha256sum "$BITCOIN_PREFIX/bin/bitcoin"*
#
## `final` aggregates build results from previous stages into a necessary minimum
# ready to be used, and published to Docker Hub.
#
# NOTE: this stage is emulated using QEMU
# NOTE: `${ARCH:+${ARCH}/}` - if ARCH is set, append `/` to it, leave it empty otherwise
FROM ${ARCH:+${ARCH}/}alpine:${VER_ALPINE} AS final
ARG USER
ARG DIR
# Use APK repos over HTTPS. See: https://github.com/gliderlabs/docker-alpine/issues/184
RUN sed -i 's|http://dl-cdn.alpinelinux.org|https://alpine.global.ssl.fastly.net|g' /etc/apk/repositories
RUN apk add --no-cache \
boost-filesystem \
boost-thread \
libevent \
libsodium \
libstdc++ \
libzmq \
sqlite-libs
COPY --from=builder /opt/bitcoin/bin/bitcoin* /usr/local/bin/
# NOTE: Default GID == UID == 1000
RUN adduser --disabled-password \
--home "$DIR/" \
--gecos "" \
"$USER"
USER $USER
# Prevents `VOLUME $DIR/.bitcoind/` being created as owned by `root`
RUN mkdir -p "$DIR/.bitcoin/"
# Expose volume containing all `bitcoind` data
VOLUME $DIR/.bitcoin/
# REST interface
EXPOSE 8080
# P2P network (mainnet, testnet & regnet respectively)
EXPOSE 8333 18333 18444
# RPC interface (mainnet, testnet & regnet respectively)
EXPOSE 8332 18332 18443
# ZMQ ports (for transactions & blocks respectively)
EXPOSE 28332 28333
ENTRYPOINT ["bitcoind"]
CMD ["-zmqpubrawblock=tcp://0.0.0.0:28332", "-zmqpubrawtx=tcp://0.0.0.0:28333"]