Skip to content

Commit 18ddaa2

Browse files
authored
build: Use heredoc for Dockerfile commands
1 parent c73284a commit 18ddaa2

1 file changed

Lines changed: 70 additions & 26 deletions

File tree

Dockerfile

Lines changed: 70 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,25 @@ ARG DEBCONF_NOWARNINGS="yes"
99
ARG DEBIAN_FRONTEND="noninteractive"
1010
ARG DEBCONF_NONINTERACTIVE_SEEN="true"
1111

12-
RUN groupadd --gid ${GID} bitcoin \
13-
&& useradd --create-home --no-log-init -u ${UID} -g ${GID} bitcoin \
14-
&& apt-get update -y \
15-
&& apt-get --no-install-recommends -y install jq curl gnupg gosu iputils-ping ca-certificates \
16-
&& apt-get clean \
17-
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
12+
RUN <<EOF
13+
set -eu
14+
15+
# Create bitcoin user
16+
groupadd --gid ${GID} bitcoin
17+
useradd --create-home --no-log-init -u ${UID} -g ${GID} bitcoin
18+
19+
apt-get update -y
20+
apt-get --no-install-recommends -y install \
21+
jq \
22+
curl \
23+
gnupg \
24+
gosu \
25+
iputils-ping \
26+
ca-certificates
27+
28+
apt-get clean
29+
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
30+
EOF
1831

1932
ARG TARGETPLATFORM
2033

@@ -26,26 +39,57 @@ ENV BITCOIN_DATA=/home/bitcoin/.bitcoin
2639
ENV PATH=/opt/bitcoin-${BITCOIN_BASE}/bin:$PATH
2740

2841
SHELL ["/bin/bash", "-c"]
29-
RUN set -eux \
30-
&& if [ -n "${BITCOIN_RC}" ]; then export SUBDIR=/test.; else export SUBDIR=; fi \
31-
&& export URL="https://bitcoincore.org/bin/bitcoin-core-${BITCOIN_VERSION}${SUBDIR}${BITCOIN_RC}" \
32-
&& if [ "${TARGETPLATFORM}" = "linux/amd64" ]; then export TARGETPLATFORM=x86_64-linux-gnu; fi \
33-
&& if [ "${TARGETPLATFORM}" = "linux/arm64" ]; then export TARGETPLATFORM=aarch64-linux-gnu; fi \
34-
&& if [ "${TARGETPLATFORM}" = "linux/arm/v7" ]; then export TARGETPLATFORM=arm-linux-gnueabihf; fi \
35-
&& SIGNERS=($(curl -sS "https://api.github.com/repos/bitcoin-core/guix.sigs/contents/${BITCOIN_BASE}" | jq -r '.[] | select(.type=="dir") | .name' | tr "\n" " ")) \
36-
&& for name in "${SIGNERS[@]}"; do \
37-
curl -sSL "https://raw.githubusercontent.com/bitcoin-core/guix.sigs/main/builder-keys/${name}.gpg" | gpg --import - ; \
38-
done \
39-
&& curl -SLO "${URL}/bitcoin-${BITCOIN_BASE}-${TARGETPLATFORM}.tar.gz" \
40-
&& curl -SLO "${URL}/SHA256SUMS" \
41-
&& curl -SLO "${URL}/SHA256SUMS.asc" \
42-
&& gpg --verify SHA256SUMS.asc SHA256SUMS \
43-
&& grep " bitcoin-${BITCOIN_BASE}-${TARGETPLATFORM}.tar.gz" SHA256SUMS | sha256sum -c - \
44-
&& tar -xzf ./*.tar.gz -C /opt \
45-
&& rm ./*.tar.gz ./*.asc \
46-
&& rm -rf "/opt/bitcoin-${BITCOIN_BASE}/bin/bitcoin-qt" \
47-
&& rm -rf "/opt/bitcoin-${BITCOIN_BASE}/bin/test_bitcoin"
48-
42+
43+
RUN <<EOF
44+
set -eux
45+
46+
# Determine Bitcoin Core release URL
47+
if [ -n "${BITCOIN_RC}" ]; then
48+
export SUBDIR=/test.
49+
else
50+
export SUBDIR=
51+
fi
52+
53+
export URL="https://bitcoincore.org/bin/bitcoin-core-${BITCOIN_VERSION}${SUBDIR}${BITCOIN_RC}"
54+
55+
# Map Docker platform to Bitcoin Core archive platform
56+
if [ "${TARGETPLATFORM}" = "linux/amd64" ]; then
57+
export TARGETPLATFORM=x86_64-linux-gnu
58+
fi
59+
60+
if [ "${TARGETPLATFORM}" = "linux/arm64" ]; then
61+
export TARGETPLATFORM=aarch64-linux-gnu
62+
fi
63+
64+
if [ "${TARGETPLATFORM}" = "linux/arm/v7" ]; then
65+
export TARGETPLATFORM=arm-linux-gnueabihf
66+
fi
67+
68+
# Import Bitcoin Core Guix signer keys
69+
SIGNERS=($(curl -sS "https://api.github.com/repos/bitcoin-core/guix.sigs/contents/${BITCOIN_BASE}" | jq -r '.[] | select(.type=="dir") | .name' | tr "\n" " "))
70+
71+
for name in "${SIGNERS[@]}"; do
72+
curl -sSL "https://raw.githubusercontent.com/bitcoin-core/guix.sigs/main/builder-keys/${name}.gpg" | gpg --import -
73+
done
74+
75+
# Download Bitcoin Core release files
76+
curl -SLO "${URL}/bitcoin-${BITCOIN_BASE}-${TARGETPLATFORM}.tar.gz"
77+
curl -SLO "${URL}/SHA256SUMS"
78+
curl -SLO "${URL}/SHA256SUMS.asc"
79+
80+
# Verify Bitcoin Core release
81+
gpg --verify SHA256SUMS.asc SHA256SUMS
82+
grep " bitcoin-${BITCOIN_BASE}-${TARGETPLATFORM}.tar.gz" SHA256SUMS | sha256sum -c -
83+
84+
# Install Bitcoin Core
85+
tar -xzf ./*.tar.gz -C /opt
86+
87+
# Cleanup
88+
rm ./*.tar.gz ./*.asc
89+
rm -rf "/opt/bitcoin-${BITCOIN_BASE}/bin/bitcoin-qt"
90+
rm -rf "/opt/bitcoin-${BITCOIN_BASE}/bin/test_bitcoin"
91+
EOF
92+
4993
COPY --chmod=755 entrypoint.sh /entrypoint.sh
5094

5195
VOLUME ["/home/bitcoin/.bitcoin"]

0 commit comments

Comments
 (0)