|
| 1 | +# Base stage |
| 2 | +# ---------- |
| 3 | +# |
| 4 | +# We use the alpine version to get the |
| 5 | +# correct version of glibc / gcc for building older bitcoin |
| 6 | +# core versions. |
| 7 | + |
| 8 | +# Default is set here to quiet a warning from Docker, but the caller must |
| 9 | +# be sure to ALWAYS set this correct per the version of bitcoin core they are |
| 10 | +# trying to build |
| 11 | +ARG ALPINE_VERSION=3.7 |
| 12 | +FROM alpine:${ALPINE_VERSION} AS base |
| 13 | + |
| 14 | +# Setup deps stage |
| 15 | +# ---------------- |
| 16 | +# |
| 17 | +# this installs the common dependencies for all of the old versions |
| 18 | +# and then version specific dependencies are passed via the |
| 19 | +# EXTRA_PACKAGES ARG |
| 20 | +FROM base AS deps |
| 21 | +ARG EXTRA_PACKAGES="" |
| 22 | +RUN --mount=type=cache,target=/var/cache/apk \ |
| 23 | + sed -i 's/http\:\/\/dl-cdn.alpinelinux.org/https\:\/\/alpine.global.ssl.fastly.net/g' /etc/apk/repositories \ |
| 24 | + && apk --no-cache add \ |
| 25 | + autoconf \ |
| 26 | + automake \ |
| 27 | + boost-dev \ |
| 28 | + build-base \ |
| 29 | + ccache \ |
| 30 | + chrpath \ |
| 31 | + file \ |
| 32 | + gnupg \ |
| 33 | + git \ |
| 34 | + libevent-dev \ |
| 35 | + libressl \ |
| 36 | + libtool \ |
| 37 | + linux-headers \ |
| 38 | + zeromq-dev \ |
| 39 | + ${EXTRA_PACKAGES} |
| 40 | + |
| 41 | +ENV BERKELEYDB_VERSION=db-4.8.30.NC |
| 42 | +ENV BERKELEYDB_PREFIX=/opt/${BERKELEYDB_VERSION} |
| 43 | + |
| 44 | +RUN wget https://download.oracle.com/berkeley-db/${BERKELEYDB_VERSION}.tar.gz |
| 45 | +RUN tar -xzf *.tar.gz |
| 46 | +RUN sed s/__atomic_compare_exchange/__atomic_compare_exchange_db/g -i ${BERKELEYDB_VERSION}/dbinc/atomic.h |
| 47 | +RUN mkdir -p ${BERKELEYDB_PREFIX} |
| 48 | + |
| 49 | +WORKDIR /${BERKELEYDB_VERSION}/build_unix |
| 50 | + |
| 51 | +RUN ../dist/configure --enable-cxx --disable-shared --with-pic --prefix=${BERKELEYDB_PREFIX} |
| 52 | +RUN make -j$(nproc) |
| 53 | +RUN make install |
| 54 | +RUN rm -rf ${BERKELEYDB_PREFIX}/docs |
| 55 | + |
| 56 | +# Build stage |
| 57 | +# ----------- |
| 58 | +# |
| 59 | +# We can build from a git repo using the REPO and COMMIT_SHA args |
| 60 | +# or from a local directory using FROM_SRC=true and specifying the local |
| 61 | +# source directory. Build args are set using a default but can be changed |
| 62 | +# on an imnage by image basis, if needed |
| 63 | +# |
| 64 | +# PRE_CONFIGURE_COMMANDS is used for version specific fixes needed before |
| 65 | +# running ./autogen.sh && ./configure |
| 66 | +# |
| 67 | +# EXTRA_BUILD_ARGS is used for version specific build flags |
| 68 | +FROM deps AS build |
| 69 | +ARG FROM_SRC="false" |
| 70 | +ARG REPO="" |
| 71 | +ARG COMMIT_SHA="" |
| 72 | +ARG BUILD_ARGS="--disable-tests --without-gui --disable-bench --disable-fuzz-binary --enable-suppress-external-warnings" |
| 73 | +ARG EXTRA_BUILD_ARGS="" |
| 74 | +ARG PRE_CONFIGURE_COMMANDS="" |
| 75 | + |
| 76 | +COPY --from=deps /opt /opt |
| 77 | +ENV BITCOIN_PREFIX=/opt/bitcoin |
| 78 | +WORKDIR /build |
| 79 | + |
| 80 | +# Even if not being used, --build-context bitcoin-src must be specified else |
| 81 | +# this line will error. If building from a remote repo, use something like |
| 82 | +# --build-context bitcoin-src="." |
| 83 | +COPY --from=bitcoin-src . /tmp/bitcoin-source |
| 84 | +RUN if [ "$FROM_SRC" = "true" ]; then \ |
| 85 | + # run with --progress=plain to see these log outputs |
| 86 | + echo "Using local files from /tmp/bitcoin-source"; \ |
| 87 | + if [ -d "/tmp/bitcoin-source" ] && [ "$(ls -A /tmp/bitcoin-source)" ]; then \ |
| 88 | + cp -R /tmp/bitcoin-source /build/bitcoin; \ |
| 89 | + else \ |
| 90 | + echo "Error: Local source directory is empty or does not exist" && exit 1; \ |
| 91 | + fi \ |
| 92 | + else \ |
| 93 | + echo "Cloning from git repository"; \ |
| 94 | + git clone --depth 1 "https://github.com/${REPO}" /build/bitcoin \ |
| 95 | + && cd /build/bitcoin \ |
| 96 | + && git fetch --depth 1 origin "$COMMIT_SHA" \ |
| 97 | + && git checkout "$COMMIT_SHA"; \ |
| 98 | + fi; |
| 99 | + |
| 100 | +# This is not our local ccache, but ccache in the docker cache |
| 101 | +# this does speed up builds substantially when building from source or building |
| 102 | +# multiple versions sequentially |
| 103 | +ENV CCACHE_DIR=/ccache |
| 104 | +RUN --mount=type=cache,target=/ccache \ |
| 105 | + set -ex \ |
| 106 | + && cd /build/bitcoin \ |
| 107 | + && if [ -n "$PRE_CONFIGURE_COMMANDS" ]; then \ |
| 108 | + eval ${PRE_CONFIGURE_COMMANDS}; \ |
| 109 | + fi \ |
| 110 | + && ./autogen.sh \ |
| 111 | + && ./configure \ |
| 112 | + LDFLAGS=-L`ls -d /opt/db*`/lib/ \ |
| 113 | + CPPFLAGS="-g0 -I`ls -d /opt/db*`/include/ --param ggc-min-expand=1 --param ggc-min-heapsize=32768" \ |
| 114 | + --prefix=${BITCOIN_PREFIX} \ |
| 115 | + ${BUILD_ARGS} \ |
| 116 | + ${EXTRA_BUILD_ARGS} \ |
| 117 | + --with-daemon \ |
| 118 | + && make -j$(nproc) \ |
| 119 | + && make install \ |
| 120 | + && strip ${BITCOIN_PREFIX}/bin/bitcoin-cli \ |
| 121 | + && strip ${BITCOIN_PREFIX}/bin/bitcoind \ |
| 122 | + && rm -f ${BITCOIN_PREFIX}/lib/libbitcoinconsensus.a \ |
| 123 | + && rm -f ${BITCOIN_PREFIX}/lib/libbitcoinconsensus.so.0.0.0 \ |
| 124 | + && rm -f ${BITCOIN_PREFIX}/bin/bitcoin-tx \ |
| 125 | + && rm -f ${BITCOIN_PREFIX}/bin/bitcoin-wallet |
| 126 | + |
| 127 | +# verify ccache is working, specify --progress=plain to see output in build logs |
| 128 | +RUN ccache -s |
| 129 | + |
| 130 | +# Final clean stage |
| 131 | +# ----------------- |
| 132 | +# |
| 133 | +# EXTRA_RUNTIME_PACKAGES is used for version specific runtime deps |
| 134 | +FROM alpine:${ALPINE_VERSION} |
| 135 | +ARG EXTRA_RUNTIME_PACKAGES="" |
| 136 | +ARG UID=100 |
| 137 | +ARG GID=101 |
| 138 | +ARG BITCOIN_VERSION |
| 139 | +ENV BITCOIN_DATA=/root/.bitcoin |
| 140 | +ENV BITCOIN_PREFIX=/opt/bitcoin |
| 141 | +ENV PATH=${BITCOIN_PREFIX}/bin:$PATH |
| 142 | +ENV BITCOIN_VERSION=${BITCOIN_VERSION} |
| 143 | +LABEL maintainer.0="bitcoindevproject" |
| 144 | + |
| 145 | +RUN addgroup -g ${GID} -S bitcoin |
| 146 | +RUN adduser -u ${UID} -S bitcoin -G bitcoin |
| 147 | +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 \ |
| 148 | + && apk --no-cache add \ |
| 149 | + bash \ |
| 150 | + boost-filesystem \ |
| 151 | + boost-system \ |
| 152 | + boost-thread \ |
| 153 | + libevent \ |
| 154 | + libzmq \ |
| 155 | + shadow \ |
| 156 | + sqlite-dev \ |
| 157 | + su-exec \ |
| 158 | + ${EXTRA_RUNTIME_PACKAGES} |
| 159 | + |
| 160 | +COPY --from=build /opt/bitcoin /usr/local |
| 161 | +COPY entrypoint.sh /entrypoint.sh |
| 162 | + |
| 163 | +VOLUME ["/home/bitcoin/.bitcoin"] |
| 164 | +EXPOSE 8332 8333 18332 18333 18443 18444 38333 38332 |
| 165 | + |
| 166 | +ENTRYPOINT ["/entrypoint.sh"] |
| 167 | +CMD ["bitcoind"] |
| 168 | + |
0 commit comments