multi-stage build

This commit is contained in:
Kieran 2023-05-08 13:40:18 +01:00
parent 26746e11fc
commit d9608da68a
Signed by: Kieran
GPG Key ID: DE71CEB3925BE941

View File

@ -1,5 +1,4 @@
FROM debian:bullseye-slim
FROM debian:bullseye-slim as base
ARG UID=101
ARG GID=101
@ -7,23 +6,23 @@ LABEL maintainer.0="João Fonseca (@joaopaulofonseca)" \
maintainer.1="Pedro Branco (@pedrobranco)" \
maintainer.2="Rui Marinho (@ruimarinho)"
RUN groupadd --gid ${GID} bitcoin \
&& useradd --create-home --no-log-init -u ${UID} -g ${GID} bitcoin \
&& apt-get update -y \
&& apt-get install -y curl gnupg gosu \
&& apt-get install -y git autoconf automake build-essential libboost-filesystem-dev libboost-system-dev libboost-thread-dev libevent-dev libsqlite3-dev libtool pkg-config libzmq3-dev --no-install-recommends \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
ARG TARGETPLATFORM
ENV BITCOIN_VERSION=24.0.1
ENV BITCOIN_DATA=/home/bitcoin/.bitcoin
ENV PATH=/opt/bitcoin-${BITCOIN_VERSION}/bin:$PATH
RUN groupadd --gid ${GID} bitcoin \
&& useradd --create-home --no-log-init -u ${UID} -g ${GID} bitcoin
FROM base as builder
RUN apt-get update -y \
&& apt-get install -y curl gnupg git ca-certificates autoconf automake build-essential \
libboost-filesystem-dev libboost-system-dev libboost-thread-dev libevent-dev \
libsqlite3-dev libtool pkg-config libzmq3-dev --no-install-recommends \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
RUN set -ex \
&& if [ "${TARGETPLATFORM}" = "linux/amd64" ]; then export TARGETPLATFORM=x86_64-linux-gnu; fi \
&& if [ "${TARGETPLATFORM}" = "linux/arm64" ]; then export TARGETPLATFORM=aarch64-linux-gnu; fi \
&& if [ "${TARGETPLATFORM}" = "linux/arm/v7" ]; then export TARGETPLATFORM=arm-linux-gnueabihf; fi \
&& for key in \
152812300785C96444D3334D17565732E08E5E41 \
0AD83877C1F0CD1EE9BD660AD7CC770B81FD22A8 \
@ -57,6 +56,7 @@ RUN set -ex \
RUN cd /build/bitcoin-${BITCOIN_VERSION} && \
./autogen.sh && \
./configure \
--prefix=/opt/bitcoin-${BITCOIN_VERSION} \
--disable-wallet \
--disable-bench \
--disable-gui-tests \
@ -74,14 +74,16 @@ RUN cd /build/bitcoin-${BITCOIN_VERSION} && \
make -j$(nproc) && \
make install
FROM base as runner
RUN apt-get update -y \
&& apt-get install -y gosu libevent-2.1-7 libevent-pthreads-2.1-7 libzmq5 \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
COPY --from=builder /opt/bitcoin-${BITCOIN_VERSION} /opt/bitcoin-${BITCOIN_VERSION}
COPY docker-entrypoint.sh /entrypoint.sh
VOLUME ["/home/bitcoin/.bitcoin"]
EXPOSE 8332 8333 18332 18333 18443 18444 38333 38332
ENTRYPOINT ["/entrypoint.sh"]
RUN bitcoind -version | grep "Bitcoin Core version v${BITCOIN_VERSION}"
CMD ["bitcoind"]