2024-04-13 04:57:49 +02:00
|
|
|
# This Dockerfile is used by buildx to build ARM64, AMD64, and ARM32 Docker images from an AMD64 host.
|
|
|
|
# To speed up the build process, we are cross-compiling rather than relying on QEMU.
|
|
|
|
# There are four main stages:
|
|
|
|
# * downloader: Downloads specific binaries needed for c-lightning for each architecture.
|
|
|
|
# * builder: Cross-compiles for each architecture.
|
|
|
|
# * builder-python: Builds Python dependencies for cln-rest with QEMU.
|
|
|
|
# * final: Creates the runtime image.
|
|
|
|
|
|
|
|
ARG BASE_DISTRO="debian:bullseye-slim"
|
|
|
|
|
|
|
|
FROM --platform=$BUILDPLATFORM ${BASE_DISTRO} as base-downloader
|
|
|
|
RUN set -ex \
|
|
|
|
&& apt-get update \
|
|
|
|
&& apt-get install -qq --no-install-recommends ca-certificates dirmngr wget qemu-user-static binfmt-support
|
|
|
|
|
|
|
|
FROM base-downloader as base-downloader-linux-amd64
|
|
|
|
ENV TARBALL_ARCH_FINAL=x86_64-linux-gnu
|
|
|
|
|
|
|
|
FROM base-downloader as base-downloader-linux-arm64
|
|
|
|
ENV TARBALL_ARCH_FINAL=aarch64-linux-gnu
|
|
|
|
|
|
|
|
FROM base-downloader as base-downloader-linux-arm
|
|
|
|
ENV TARBALL_ARCH_FINAL=arm-linux-gnueabihf
|
|
|
|
|
|
|
|
FROM base-downloader-${TARGETOS}-${TARGETARCH} as downloader
|
2019-08-29 14:57:44 +02:00
|
|
|
|
|
|
|
RUN set -ex \
|
|
|
|
&& apt-get update \
|
|
|
|
&& apt-get install -qq --no-install-recommends ca-certificates dirmngr wget
|
2018-06-21 17:42:52 +02:00
|
|
|
|
|
|
|
WORKDIR /opt
|
|
|
|
|
2019-08-29 14:57:44 +02:00
|
|
|
|
2024-04-13 04:57:49 +02:00
|
|
|
ENV BITCOIN_VERSION=22.0
|
2023-09-20 03:39:23 +02:00
|
|
|
ENV BITCOIN_TARBALL bitcoin-${BITCOIN_VERSION}-${TARBALL_ARCH_FINAL}.tar.gz
|
2018-08-20 10:38:22 +02:00
|
|
|
ENV BITCOIN_URL https://bitcoincore.org/bin/bitcoin-core-$BITCOIN_VERSION/$BITCOIN_TARBALL
|
2021-11-04 19:06:44 +01:00
|
|
|
ENV BITCOIN_ASC_URL https://bitcoincore.org/bin/bitcoin-core-$BITCOIN_VERSION/SHA256SUMS
|
2018-06-21 17:42:52 +02:00
|
|
|
|
|
|
|
RUN mkdir /opt/bitcoin && cd /opt/bitcoin \
|
2018-08-20 10:38:22 +02:00
|
|
|
&& wget -qO $BITCOIN_TARBALL "$BITCOIN_URL" \
|
2021-11-04 19:06:44 +01:00
|
|
|
&& wget -qO bitcoin "$BITCOIN_ASC_URL" \
|
|
|
|
&& grep $BITCOIN_TARBALL bitcoin | tee SHA256SUMS \
|
|
|
|
&& sha256sum -c SHA256SUMS \
|
2018-06-21 17:42:52 +02:00
|
|
|
&& BD=bitcoin-$BITCOIN_VERSION/bin \
|
2023-09-06 10:31:38 +02:00
|
|
|
&& tar -xzvf $BITCOIN_TARBALL $BD/ --strip-components=1 \
|
2018-08-20 10:38:22 +02:00
|
|
|
&& rm $BITCOIN_TARBALL
|
2018-06-21 17:42:52 +02:00
|
|
|
|
2018-10-30 20:53:11 +01:00
|
|
|
ENV LITECOIN_VERSION 0.16.3
|
2023-09-20 03:39:23 +02:00
|
|
|
ENV LITECOIN_URL https://download.litecoin.org/litecoin-${LITECOIN_VERSION}/linux/litecoin-${LITECOIN_VERSION}-${TARBALL_ARCH_FINAL}.tar.gz
|
2018-06-21 17:42:52 +02:00
|
|
|
|
|
|
|
# install litecoin binaries
|
|
|
|
RUN mkdir /opt/litecoin && cd /opt/litecoin \
|
|
|
|
&& wget -qO litecoin.tar.gz "$LITECOIN_URL" \
|
2023-09-20 03:39:23 +02:00
|
|
|
&& tar -xzvf litecoin.tar.gz litecoin-$LITECOIN_VERSION/bin/litecoin-cli --strip-components=1 --exclude=*-qt \
|
2018-06-21 17:42:52 +02:00
|
|
|
&& rm litecoin.tar.gz
|
|
|
|
|
2024-04-13 04:57:49 +02:00
|
|
|
FROM --platform=linux/amd64 ${BASE_DISTRO} as base-builder
|
2022-01-26 19:11:29 +01:00
|
|
|
RUN apt-get update -qq && \
|
|
|
|
apt-get install -qq -y --no-install-recommends \
|
|
|
|
autoconf \
|
|
|
|
automake \
|
|
|
|
build-essential \
|
|
|
|
ca-certificates \
|
2022-03-01 13:19:19 +01:00
|
|
|
curl \
|
2022-01-26 19:11:29 +01:00
|
|
|
dirmngr \
|
|
|
|
gettext \
|
|
|
|
git \
|
|
|
|
gnupg \
|
2024-05-23 01:34:11 +02:00
|
|
|
jq \
|
2022-02-28 18:53:13 +01:00
|
|
|
libpq-dev \
|
2022-01-26 19:11:29 +01:00
|
|
|
libtool \
|
2022-03-01 13:19:19 +01:00
|
|
|
libffi-dev \
|
2023-07-31 15:40:21 +02:00
|
|
|
pkg-config \
|
|
|
|
libssl-dev \
|
2023-01-24 05:25:05 +01:00
|
|
|
protobuf-compiler \
|
2023-07-31 15:40:21 +02:00
|
|
|
python3.9 \
|
2022-03-01 14:28:58 +01:00
|
|
|
python3-dev \
|
2022-01-26 19:11:29 +01:00
|
|
|
python3-mako \
|
|
|
|
python3-pip \
|
2022-03-01 14:28:58 +01:00
|
|
|
python3-venv \
|
2022-01-26 19:11:29 +01:00
|
|
|
python3-setuptools \
|
2023-07-31 15:40:21 +02:00
|
|
|
libev-dev \
|
|
|
|
libevent-dev \
|
|
|
|
qemu-user-static \
|
2024-03-04 03:29:52 +01:00
|
|
|
wget \
|
2024-04-13 04:57:49 +02:00
|
|
|
unzip \
|
|
|
|
tclsh
|
|
|
|
|
|
|
|
ENV PYTHON_VERSION=3
|
|
|
|
RUN curl -sSL https://install.python-poetry.org | python3 -
|
|
|
|
RUN update-alternatives --install /usr/bin/python python /usr/bin/python3.9 1
|
|
|
|
RUN pip3 install --upgrade pip setuptools wheel
|
|
|
|
|
|
|
|
RUN wget -q https://zlib.net/fossils/zlib-1.2.13.tar.gz -O zlib.tar.gz && \
|
|
|
|
wget -q https://www.sqlite.org/2019/sqlite-src-3290000.zip -O sqlite.zip
|
|
|
|
|
|
|
|
WORKDIR /opt/lightningd
|
|
|
|
COPY . /tmp/lightning
|
|
|
|
RUN git clone --recursive /tmp/lightning . && \
|
|
|
|
git checkout $(git --work-tree=/tmp/lightning --git-dir=/tmp/lightning/.git rev-parse HEAD)
|
|
|
|
|
2024-05-23 01:34:11 +02:00
|
|
|
# Do not build python plugins (clnrest & wss-proxy) here, python doesn't support cross compilation.
|
|
|
|
RUN sed -i '/^clnrest\|^wss-proxy/d' pyproject.toml && \
|
2024-04-13 04:57:49 +02:00
|
|
|
/root/.local/bin/poetry export -o requirements.txt --without-hashes
|
|
|
|
RUN pip3 install -r requirements.txt && pip3 cache purge
|
|
|
|
WORKDIR /
|
|
|
|
|
|
|
|
FROM base-builder as base-builder-linux-amd64
|
|
|
|
|
|
|
|
FROM base-builder as base-builder-linux-arm64
|
|
|
|
ENV target_host=aarch64-linux-gnu \
|
|
|
|
target_host_rust=aarch64-unknown-linux-gnu \
|
|
|
|
target_host_qemu=qemu-aarch64-static
|
|
|
|
|
|
|
|
RUN apt-get install -qq -y --no-install-recommends \
|
|
|
|
libc6-arm64-cross \
|
|
|
|
gcc-${target_host} \
|
|
|
|
g++-${target_host}
|
|
|
|
|
|
|
|
ENV AR=${target_host}-ar \
|
|
|
|
AS=${target_host}-as \
|
|
|
|
CC=${target_host}-gcc \
|
|
|
|
CXX=${target_host}-g++ \
|
|
|
|
LD=${target_host}-ld \
|
|
|
|
STRIP=${target_host}-strip \
|
|
|
|
QEMU_LD_PREFIX=/usr/${target_host} \
|
|
|
|
HOST=${target_host} \
|
|
|
|
TARGET=${target_host_rust} \
|
|
|
|
RUSTUP_INSTALL_OPTS="--target ${target_host_rust} --default-host ${target_host_rust}" \
|
|
|
|
PKG_CONFIG_PATH="/usr/${target_host}/lib/pkgconfig"
|
|
|
|
|
|
|
|
ENV \
|
|
|
|
ZLIB_CONFIG="--prefix=${QEMU_LD_PREFIX}" \
|
|
|
|
SQLITE_CONFIG="--host=${target_host} --prefix=$QEMU_LD_PREFIX"
|
2022-01-26 19:11:29 +01:00
|
|
|
|
2024-04-13 04:57:49 +02:00
|
|
|
FROM base-builder as base-builder-linux-arm
|
|
|
|
|
|
|
|
ENV target_host=arm-linux-gnueabihf \
|
|
|
|
target_host_rust=armv7-unknown-linux-gnueabihf \
|
|
|
|
target_host_qemu=qemu-arm-static
|
|
|
|
|
|
|
|
RUN apt-get install -qq -y --no-install-recommends \
|
|
|
|
libc6-armhf-cross \
|
|
|
|
gcc-${target_host} \
|
|
|
|
g++-${target_host}
|
|
|
|
|
|
|
|
ENV AR=${target_host}-ar \
|
|
|
|
AS=${target_host}-as \
|
|
|
|
CC=${target_host}-gcc \
|
|
|
|
CXX=${target_host}-g++ \
|
|
|
|
LD=${target_host}-ld \
|
|
|
|
STRIP=${target_host}-strip \
|
|
|
|
QEMU_LD_PREFIX=/usr/${target_host} \
|
|
|
|
HOST=${target_host} \
|
|
|
|
TARGET=${target_host_rust} \
|
|
|
|
RUSTUP_INSTALL_OPTS="--target ${target_host_rust} --default-host ${target_host_rust}" \
|
|
|
|
PKG_CONFIG_PATH="/usr/${target_host}/lib/pkgconfig"
|
|
|
|
|
|
|
|
ENV \
|
|
|
|
ZLIB_CONFIG="--prefix=${QEMU_LD_PREFIX}" \
|
|
|
|
SQLITE_CONFIG="--host=${target_host} --prefix=$QEMU_LD_PREFIX"
|
|
|
|
|
|
|
|
FROM base-builder-${TARGETOS}-${TARGETARCH} as builder
|
|
|
|
|
|
|
|
ENV LIGHTNINGD_VERSION=master
|
|
|
|
|
|
|
|
RUN mkdir zlib && tar xvf zlib.tar.gz -C zlib --strip-components=1 \
|
|
|
|
&& cd zlib \
|
|
|
|
&& ./configure ${ZLIB_CONFIG} \
|
2022-11-11 15:48:53 +01:00
|
|
|
&& make \
|
|
|
|
&& make install && cd .. && \
|
2024-04-13 04:57:49 +02:00
|
|
|
rm zlib.tar.gz && \
|
|
|
|
rm -rf zlib
|
|
|
|
|
|
|
|
RUN unzip sqlite.zip \
|
|
|
|
&& cd sqlite-* \
|
|
|
|
&& ./configure --enable-static --disable-readline --disable-threadsafe --disable-load-extension ${SQLITE_CONFIG} \
|
2022-11-11 15:48:53 +01:00
|
|
|
&& make \
|
2024-04-13 04:57:49 +02:00
|
|
|
&& make install && cd .. && rm sqlite.zip && rm -rf sqlite-*
|
2019-09-26 03:54:43 +02:00
|
|
|
|
2022-05-18 11:22:28 +02:00
|
|
|
ENV RUST_PROFILE=release
|
|
|
|
ENV PATH=$PATH:/root/.cargo/bin/
|
2024-04-13 04:57:49 +02:00
|
|
|
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y ${RUSTUP_INSTALL_OPTS}
|
2022-05-18 11:22:28 +02:00
|
|
|
RUN rustup toolchain install stable --component rustfmt --allow-downgrade
|
|
|
|
|
2024-04-13 04:57:49 +02:00
|
|
|
COPY --from=downloader /usr/bin/${target_host_qemu} /usr/bin/${target_host_qemu}
|
2018-06-21 17:42:52 +02:00
|
|
|
WORKDIR /opt/lightningd
|
2023-07-31 15:40:21 +02:00
|
|
|
|
2024-04-13 04:57:49 +02:00
|
|
|
# If cross-compiling, need to tell it to cargo.
|
|
|
|
RUN ( ! [ -n "${target_host}" ] ) || \
|
|
|
|
(mkdir -p .cargo && echo "[target.${target_host_rust}]\nlinker = \"${target_host}-gcc\"" > .cargo/config)
|
2023-07-31 15:40:21 +02:00
|
|
|
|
2024-04-13 04:57:49 +02:00
|
|
|
# Weird errors with cargo for cln-grpc on arm7 https://github.com/ElementsProject/lightning/issues/6596
|
|
|
|
RUN ( ! [ "${target_host}" = "arm-linux-gnueabihf" ] ) || \
|
|
|
|
(sed -i '/documentation = "https:\/\/docs.rs\/cln-grpc"/a include = ["**\/*.*"]' cln-grpc/Cargo.toml)
|
2021-12-11 15:41:08 +01:00
|
|
|
|
2024-06-12 03:24:23 +02:00
|
|
|
# Ensure that the desired grpcio-tools & protobuf versions are installed
|
|
|
|
# https://github.com/ElementsProject/lightning/pull/7376#issuecomment-2161102381
|
|
|
|
RUN /root/.local/bin/poetry lock --no-update && \
|
|
|
|
/root/.local/bin/poetry install
|
|
|
|
|
2022-11-11 15:48:53 +01:00
|
|
|
RUN ./configure --prefix=/tmp/lightning_install --enable-static && \
|
2023-09-21 08:54:00 +02:00
|
|
|
make && \
|
2022-11-11 15:48:53 +01:00
|
|
|
/root/.local/bin/poetry run make install
|
2019-08-29 14:57:44 +02:00
|
|
|
|
2024-05-23 01:34:11 +02:00
|
|
|
# We need to build python plugins on the target's arch because python doesn't support cross build
|
2024-04-13 04:57:49 +02:00
|
|
|
FROM ${BASE_DISTRO} as builder-python
|
|
|
|
RUN apt-get update -qq && \
|
|
|
|
apt-get install -qq -y --no-install-recommends \
|
|
|
|
git \
|
|
|
|
curl \
|
|
|
|
libtool \
|
|
|
|
pkg-config \
|
|
|
|
autoconf \
|
|
|
|
automake \
|
|
|
|
build-essential \
|
|
|
|
libffi-dev \
|
|
|
|
libssl-dev \
|
|
|
|
python3.9 \
|
|
|
|
python3-dev \
|
|
|
|
python3-pip && \
|
|
|
|
apt-get clean && \
|
|
|
|
rm -rf /var/lib/apt/lists/*
|
|
|
|
|
|
|
|
RUN update-alternatives --install /usr/bin/python python /usr/bin/python3.9 1
|
|
|
|
ENV PATH=$PATH:/root/.cargo/bin/
|
|
|
|
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
|
|
|
|
RUN rustup toolchain install stable --component rustfmt --allow-downgrade
|
|
|
|
|
|
|
|
WORKDIR /opt/lightningd
|
|
|
|
COPY plugins/clnrest/requirements.txt plugins/clnrest/requirements.txt
|
2024-05-23 01:34:11 +02:00
|
|
|
COPY plugins/wss-proxy/requirements.txt plugins/wss-proxy/requirements.txt
|
2024-04-13 04:57:49 +02:00
|
|
|
ENV PYTHON_VERSION=3
|
2024-05-23 01:34:11 +02:00
|
|
|
RUN pip3 install -r plugins/clnrest/requirements.txt && \
|
|
|
|
pip3 install -r plugins/wss-proxy/requirements.txt && \
|
|
|
|
pip3 cache purge
|
2024-04-13 04:57:49 +02:00
|
|
|
|
|
|
|
FROM ${BASE_DISTRO} as final
|
2022-11-11 15:48:53 +01:00
|
|
|
|
|
|
|
RUN apt-get update && \
|
|
|
|
apt-get install -y --no-install-recommends \
|
2023-09-05 03:51:56 +02:00
|
|
|
tini \
|
2022-11-11 15:48:53 +01:00
|
|
|
socat \
|
|
|
|
inotify-tools \
|
2024-04-13 04:57:49 +02:00
|
|
|
jq \
|
2023-07-31 15:40:21 +02:00
|
|
|
python3.9 \
|
2022-11-11 15:48:53 +01:00
|
|
|
python3-pip \
|
|
|
|
libpq5 && \
|
2023-09-05 03:51:56 +02:00
|
|
|
apt-get clean && \
|
2022-11-11 15:48:53 +01:00
|
|
|
rm -rf /var/lib/apt/lists/*
|
2018-06-21 17:42:52 +02:00
|
|
|
|
|
|
|
ENV LIGHTNINGD_DATA=/root/.lightning
|
2018-06-26 02:17:53 +02:00
|
|
|
ENV LIGHTNINGD_RPC_PORT=9835
|
2019-08-29 14:57:44 +02:00
|
|
|
ENV LIGHTNINGD_PORT=9735
|
2020-07-05 14:29:48 +02:00
|
|
|
ENV LIGHTNINGD_NETWORK=bitcoin
|
2018-06-21 17:42:52 +02:00
|
|
|
|
2019-08-29 14:57:44 +02:00
|
|
|
RUN mkdir $LIGHTNINGD_DATA && \
|
|
|
|
touch $LIGHTNINGD_DATA/config
|
2018-06-21 17:42:52 +02:00
|
|
|
VOLUME [ "/root/.lightning" ]
|
2023-07-31 15:40:21 +02:00
|
|
|
|
2019-03-11 09:51:47 +01:00
|
|
|
COPY --from=builder /tmp/lightning_install/ /usr/local/
|
2024-04-13 04:57:49 +02:00
|
|
|
COPY --from=builder-python /usr/local/lib/python3.9/dist-packages/ /usr/local/lib/python3.9/dist-packages/
|
2019-08-29 14:57:44 +02:00
|
|
|
COPY --from=downloader /opt/bitcoin/bin /usr/bin
|
|
|
|
COPY --from=downloader /opt/litecoin/bin /usr/bin
|
2018-06-21 17:42:52 +02:00
|
|
|
COPY tools/docker-entrypoint.sh entrypoint.sh
|
|
|
|
|
2018-06-26 02:17:53 +02:00
|
|
|
EXPOSE 9735 9835
|
2019-08-29 14:57:44 +02:00
|
|
|
ENTRYPOINT [ "/usr/bin/tini", "-g", "--", "./entrypoint.sh" ]
|