dockerfile: optimize on size and network call

- merge multiple steps to reduce number of layers
- run make clean to reduce layer size
- run cargo clean
- merge multiple ARG into single step
Signed-off-by: Lakshya Singh <lakshay.singh1108@gmail.com>
This commit is contained in:
Lakshya Singh 2023-11-23 21:26:59 +05:30
parent 7e5d66f55d
commit eeaac24d54
No known key found for this signature in database
GPG Key ID: D3239BA6109A2CE7
4 changed files with 49 additions and 45 deletions

View File

@ -53,21 +53,21 @@ ARG BITCOIN_VERSION=23.0
ARG BITCOIN_PREFIX=/opt/bitcoin-${BITCOIN_VERSION}
ARG SHA256SUMS_HASH=aaff81ea001f499e8f6f3221387d7db960d71a3b7a4a2b1aaf2c8060bc94a391
RUN wget https://bitcoincore.org/bin/bitcoin-core-${BITCOIN_VERSION}/SHA256SUMS
RUN wget https://bitcoincore.org/bin/bitcoin-core-${BITCOIN_VERSION}/SHA256SUMS.asc
RUN wget https://bitcoincore.org/bin/bitcoin-core-${BITCOIN_VERSION}/bitcoin-${BITCOIN_VERSION}.tar.gz
RUN gpg --batch --verify SHA256SUMS.asc SHA256SUMS
RUN echo "${SHA256SUMS_HASH} SHA256SUMS" | sha256sum -c -
RUN grep " bitcoin-${BITCOIN_VERSION}.tar.gz\$" SHA256SUMS | sha256sum -c -
RUN tar -xzf *.tar.gz
RUN wget https://bitcoincore.org/bin/bitcoin-core-${BITCOIN_VERSION}/SHA256SUMS && \
wget https://bitcoincore.org/bin/bitcoin-core-${BITCOIN_VERSION}/SHA256SUMS.asc && \
wget https://bitcoincore.org/bin/bitcoin-core-${BITCOIN_VERSION}/bitcoin-${BITCOIN_VERSION}.tar.gz && \
gpg --batch --verify SHA256SUMS.asc SHA256SUMS && \
echo "${SHA256SUMS_HASH} SHA256SUMS" | sha256sum -c - && \
grep " bitcoin-${BITCOIN_VERSION}.tar.gz\$" SHA256SUMS | sha256sum -c - && \
tar -xzf *.tar.gz
WORKDIR /bitcoin-${BITCOIN_VERSION}
RUN sed -i '/AC_PREREQ/a\AR_FLAGS=cr' src/univalue/configure.ac
RUN sed -i '/AX_PROG_CC_FOR_BUILD/a\AR_FLAGS=cr' src/secp256k1/configure.ac
RUN sed -i s:sys/fcntl.h:fcntl.h: src/compat.h
RUN ./autogen.sh
RUN ./configure LDFLAGS=-L`ls -d /opt/db*`/lib/ CPPFLAGS=-I`ls -d /opt/db*`/include/ \
RUN 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 && \
./autogen.sh && \
./configure LDFLAGS=-L`ls -d /opt/db*`/lib/ CPPFLAGS=-I`ls -d /opt/db*`/include/ \
--prefix=${BITCOIN_PREFIX} \
--mandir=/usr/share/man \
--disable-tests \
@ -78,13 +78,15 @@ RUN ./configure LDFLAGS=-L`ls -d /opt/db*`/lib/ CPPFLAGS=-I`ls -d /opt/db*`/incl
--with-libs \
--with-sqlite=yes \
--with-daemon
RUN make -j $(nproc)
RUN make install
RUN strip ${BITCOIN_PREFIX}/bin/bitcoin-cli
RUN strip ${BITCOIN_PREFIX}/bin/bitcoin-tx
RUN strip ${BITCOIN_PREFIX}/bin/bitcoind
RUN strip ${BITCOIN_PREFIX}/lib/libbitcoinconsensus.a
RUN strip ${BITCOIN_PREFIX}/lib/libbitcoinconsensus.so.0.0.0
RUN make -j $(nproc) && \
make install && \
strip ${BITCOIN_PREFIX}/bin/bitcoin-cli \
${BITCOIN_PREFIX}/bin/bitcoin-tx \
${BITCOIN_PREFIX}/bin/bitcoind \
${BITCOIN_PREFIX}/lib/libbitcoinconsensus.a \
${BITCOIN_PREFIX}/lib/libbitcoinconsensus.so.0.0.0 && \
make clean
# Runtime binaries and setup stage
FROM --platform=${TARGETPLATFORM:-${BUILDPLATFORM:-linux/amd64}} alpine:3.18 as runner
@ -95,8 +97,8 @@ ARG GID=101
LABEL maintainer.0="Lakshya Singh (@king-11)" \
maintainer.1="Dev Random (@devrandom01)"
RUN addgroup bitcoin --gid ${GID} --system
RUN adduser --uid ${UID} --system bitcoin --ingroup bitcoin
RUN addgroup bitcoin --gid ${GID} --system && \
adduser --uid ${UID} --system bitcoin --ingroup bitcoin
RUN sed -i 's/http\:\/\/dl-cdn.alpinelinux.org/https\:\/\/alpine.global.ssl.fastly.net/g' /etc/apk/repositories
RUN apk --no-cache add \
boost-filesystem \

View File

@ -27,17 +27,18 @@ RUN apk update && \
zlib-dev \
zlib-static
ARG CORE_LIGHTNING_GIT_HASH=bd9494c65be09e6f8ecb3bc49b50a859467a65fe
ARG CORE_LIGHTNING_REPO=https://github.com/lightning-signer/c-lightning.git
ARG CORE_LIGHTNING_GIT_HASH=bd9494c65be09e6f8ecb3bc49b50a859467a65fe \
CORE_LIGHTNING_REPO=https://github.com/lightning-signer/c-lightning.git
RUN git clone --recursive $CORE_LIGHTNING_REPO core-lightning
RUN cd core-lightning && \
git checkout $CORE_LIGHTNING_GIT_HASH && \
./configure --enable-static --prefix=/usr && \
make -j $(nproc) && \
make -j $(nproc) install
make -j $(nproc) install && \
make clean
ARG PLUGINS_GIT_HASH=ce078bb74e10b5dea779fcd9fbe77e1d3e72db7a
ARG PLUGINS_REPO=https://github.com/lightningd/plugins.git
ARG PLUGINS_GIT_HASH=ce078bb74e10b5dea779fcd9fbe77e1d3e72db7a \
PLUGINS_REPO=https://github.com/lightningd/plugins.git
RUN git clone $PLUGINS_REPO
RUN cd plugins && \
git checkout $PLUGINS_GIT_HASH
@ -59,15 +60,16 @@ RUN apk update && \
pkgconf \
sqlite-dev
ARG CLBOSS_GIT_HASH=9c050d61f01ffff4b7b5d295f708569dd71b55d3
ARG CLBOSS_REPO=https://github.com/ZmnSCPxj/clboss.git
ARG CLBOSS_GIT_HASH=9c050d61f01ffff4b7b5d295f708569dd71b55d3 \
CLBOSS_REPO=https://github.com/ZmnSCPxj/clboss.git
RUN git clone --recurse-submodules $CLBOSS_REPO clboss
RUN cd clboss && \
git checkout $CLBOSS_GIT_HASH && \
autoreconf -i && \
./configure --prefix=/usr && \
make -j $(nproc) && \
make install
make -j $(nproc) install && \
make clean
FROM --platform=${TARGETPLATFORM:-${BUILDPLATFORM:-linux/amd64}} alpine:3.18 as vls_builder
@ -83,12 +85,13 @@ RUN apk update && \
protobuf-dev \
rust
ARG VLS_GIT_HASH=af02dac8b855c361d74234387d288a9591fad1d5
ARG VLS_REPO=https://gitlab.com/lightning-signer/validating-lightning-signer.git
ARG VLS_GIT_HASH=af02dac8b855c361d74234387d288a9591fad1d5 \
VLS_REPO=https://gitlab.com/lightning-signer/validating-lightning-signer.git
RUN git clone $VLS_REPO vls
RUN cd vls && \
git checkout $VLS_GIT_HASH && \
cargo build --bin remote_hsmd_socket --release
cargo install --path ./vls-proxy --bin remote_hsmd_socket --profile release --root /usr/local/ && \
cargo clean
# final stage with runtime dependencies and pkgs
FROM --platform=${TARGETPLATFORM:-${BUILDPLATFORM:-linux/amd64}} alpine:3.18 as runner
@ -109,8 +112,8 @@ RUN apk update && \
curl-dev \
sqlite-dev
ARG LIGHTNINGD_UID=101
ARG LIGHTNINGD_USER=lightning
ARG LIGHTNINGD_UID=101 \
LIGHTNINGD_USER=lightning
ARG LIGHTNINGD_HOME=/home/${LIGHTNINGD_USER}
ENV LIGHTNINGD_DATA=${LIGHTNINGD_HOME}/.lightning \
LIGHTNINGD_RPC_PORT=9835 \
@ -119,15 +122,13 @@ ENV LIGHTNINGD_DATA=${LIGHTNINGD_HOME}/.lightning \
RUN mkdir -p /usr/local/src/plugins
COPY --from=builder /usr/bin/lightningd /usr/bin/
COPY --from=builder /usr/bin/lightning-cli /usr/bin/
COPY --from=builder /usr/bin/lightning-hsmtool /usr/bin/
COPY --from=builder /usr/bin/lightningd /usr/bin/lightning-cli /usr/bin/lightning-hsmtool /usr/bin/
COPY --from=builder /usr/libexec/c-lightning /usr/libexec/c-lightning
COPY --from=builder /usr/share/man/man8 /usr/share/man/man8
COPY --from=builder /usr/share/doc/c-lightning /usr/share/doc/c-lightning
COPY --from=clboss_builder /usr/bin/clboss /usr/bin/clboss
COPY --from=builder /build/plugins/summary /usr/local/src/plugins/summary
COPY --from=vls_builder /build/vls/target/release/remote_hsmd_socket /usr/libexec/c-lightning/remote_hsmd_socket
COPY --from=vls_builder /usr/local/bin/remote_hsmd_socket /usr/libexec/c-lightning/remote_hsmd_socket
RUN addgroup -S lightning && adduser -S lightning -G lightning && \
mkdir -p ${LIGHTNINGD_DATA} && \

View File

@ -6,16 +6,16 @@ WORKDIR /build
RUN apk update && \
apk add \
git \
rust
RUN apk add cargo
rust \
cargo
ARG TXOO_GIT_HASH=528fa92e5def1b6cc19127f2242137bf6f13550d
ARG TXOO_REPO=https://gitlab.com/lightning-signer/txoo.git
RUN git clone --recurse-submodules $TXOO_REPO
RUN cd txoo && \
git checkout $TXOO_GIT_HASH && \
cargo build --release -p txood
cargo install --path ./txood --bin txood --profile release --root /usr/local/ && \
cargo clean
# txoo runner
FROM --platform=${TARGETPLATFORM:-${BUILDPLATFORM:-linux/amd64}} alpine:3.18 as runner
@ -32,7 +32,7 @@ RUN apk update && \
libev-dev \
curl-dev
COPY --from=builder /build/txoo/target/release/txood /usr/bin/txood
COPY --from=builder /usr/local/bin/txood /usr/bin/txood
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh

View File

@ -16,7 +16,8 @@ ARG GIT_HASH=af02dac8b855c361d74234387d288a9591fad1d5
RUN git clone https://gitlab.com/lightning-signer/validating-lightning-signer.git vls
RUN cd vls && \
git checkout $GIT_HASH && \
cargo build --bin vlsd2 --release
cargo install --path ./vls-proxy --bin vlsd2 --profile release --root /usr/local/ && \
cargo clean
FROM --platform=${TARGETPLATFORM:-${BUILDPLATFORM:-linux/amd64}} alpine:3.18 as runner
@ -36,7 +37,7 @@ RUN apk update && \
protobuf \
bind-tools
COPY --from=builder /build/vls/target/release/vlsd2 /usr/local/bin/vlsd2
COPY --from=builder /usr/local/bin/vlsd2 /usr/local/bin/vlsd2
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh