11# This Dockerfile is used by buildx to build ARM64, AMD64, and ARM32 Docker images from an AMD64 host.
22# To speed up the build process, we are cross-compiling rather than relying on QEMU.
33# There are four main stages:
4- # * downloader: Downloads specific binaries needed for c- lightning for each architecture.
4+ # * downloader: Downloads specific binaries needed for core lightning for each architecture.
55# * builder: Cross-compiles for each architecture.
6- # * builder-python: Builds Python dependencies for cln-rest with QEMU.
6+ # * builder-python: Builds Python dependencies for clnrest & wss-proxy with QEMU.
77# * final: Creates the runtime image.
88
9+ ARG DEFAULT_TARGETPLATFORM="linux/amd64"
910ARG BASE_DISTRO="debian:bullseye-slim"
1011
11- FROM --platform=$BUILDPLATFORM ${BASE_DISTRO} as base-downloader
12+ FROM --platform=$BUILDPLATFORM ${BASE_DISTRO} AS base-downloader
1213RUN set -ex \
1314 && apt-get update \
1415 && apt-get install -qq --no-install-recommends ca-certificates dirmngr wget qemu-user-static binfmt-support
1516
16- FROM base-downloader as base-downloader-linux-amd64
17+ FROM base-downloader AS base-downloader-linux-amd64
1718ENV TARBALL_ARCH_FINAL=x86_64-linux-gnu
1819
19- FROM base-downloader as base-downloader-linux-arm64
20+ FROM base-downloader AS base-downloader-linux-arm64
2021ENV TARBALL_ARCH_FINAL=aarch64-linux-gnu
2122
22- FROM base-downloader as base-downloader-linux-arm
23+ FROM base-downloader AS base-downloader-linux-arm
2324ENV TARBALL_ARCH_FINAL=arm-linux-gnueabihf
2425
25- FROM base-downloader-${TARGETOS}-${TARGETARCH} as downloader
26+ FROM base-downloader-${TARGETOS}-${TARGETARCH} AS downloader
2627
2728RUN set -ex \
2829 && apt-get update \
@@ -54,7 +55,7 @@ RUN mkdir /opt/litecoin && cd /opt/litecoin \
5455 && tar -xzvf litecoin.tar.gz litecoin-$LITECOIN_VERSION/bin/litecoin-cli --strip-components=1 --exclude=*-qt \
5556 && rm litecoin.tar.gz
5657
57- FROM --platform=linux/amd64 ${BASE_DISTRO} as base-builder
58+ FROM --platform=${DEFAULT_TARGETPLATFORM} ${BASE_DISTRO} AS base-builder
5859RUN apt-get update -qq && \
5960 apt-get install -qq -y --no-install-recommends \
6061 autoconf \
@@ -86,6 +87,7 @@ RUN apt-get update -qq && \
8687 unzip \
8788 tclsh
8889
90+ ENV PATH="/root/.local/bin:$PATH"
8991ENV PYTHON_VERSION=3
9092RUN curl -sSL https://install.python-poetry.org | python3 -
9193RUN update-alternatives --install /usr/bin/python python /usr/bin/python3.9 1
@@ -100,14 +102,13 @@ RUN git clone --recursive /tmp/lightning . && \
100102 git checkout $(git --work-tree=/tmp/lightning --git-dir=/tmp/lightning/.git rev-parse HEAD)
101103
102104# Do not build python plugins (clnrest & wss-proxy) here, python doesn't support cross compilation.
103- RUN sed -i '/^clnrest\| ^wss-proxy/d' pyproject.toml && \
104- /root/.local/bin/poetry export -o requirements.txt --without-hashes
105+ RUN sed -i '/^clnrest\| ^wss-proxy/d' pyproject.toml && poetry export -o requirements.txt --without-hashes
105106RUN pip3 install -r requirements.txt && pip3 cache purge
106107WORKDIR /
107108
108- FROM base-builder as base-builder-linux-amd64
109+ FROM base-builder AS base-builder-linux-amd64
109110
110- FROM base-builder as base-builder-linux-arm64
111+ FROM base-builder AS base-builder-linux-arm64
111112ENV target_host=aarch64-linux-gnu \
112113 target_host_rust=aarch64-unknown-linux-gnu \
113114 target_host_qemu=qemu-aarch64-static
@@ -133,7 +134,7 @@ ENV \
133134ZLIB_CONFIG="--prefix=${QEMU_LD_PREFIX}" \
134135SQLITE_CONFIG="--host=${target_host} --prefix=$QEMU_LD_PREFIX"
135136
136- FROM base-builder as base-builder-linux-arm
137+ FROM base-builder AS base-builder-linux-arm
137138
138139ENV target_host=arm-linux-gnueabihf \
139140 target_host_rust=armv7-unknown-linux-gnueabihf \
@@ -160,7 +161,7 @@ ENV \
160161ZLIB_CONFIG="--prefix=${QEMU_LD_PREFIX}" \
161162SQLITE_CONFIG="--host=${target_host} --prefix=$QEMU_LD_PREFIX"
162163
163- FROM base-builder-${TARGETOS}-${TARGETARCH} as builder
164+ FROM base-builder-${TARGETOS}-${TARGETARCH} AS builder
164165
165166ENV LIGHTNINGD_VERSION=master
166167
@@ -179,7 +180,7 @@ RUN unzip sqlite.zip \
179180 && make install && cd .. && rm sqlite.zip && rm -rf sqlite-*
180181
181182ENV RUST_PROFILE=release
182- ENV PATH=$PATH: /root/.cargo/bin/
183+ ENV PATH=" /root/.cargo/bin:/root/.local/bin:$PATH"
183184RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y ${RUSTUP_INSTALL_OPTS}
184185RUN rustup toolchain install stable --component rustfmt --allow-downgrade
185186
@@ -196,15 +197,20 @@ RUN ( ! [ "${target_host}" = "arm-linux-gnueabihf" ] ) || \
196197
197198# Ensure that the desired grpcio-tools & protobuf versions are installed
198199# https://github.com/ElementsProject/lightning/pull/7376#issuecomment-2161102381
199- RUN /root/.local/bin/poetry lock --no-update && \
200- /root/.local/bin/poetry install
200+ RUN poetry lock --no-update && poetry install
201201
202- RUN ./configure --prefix=/tmp/lightning_install --enable-static && \
203- make && \
204- /root/.local/bin/poetry run make install
202+ RUN ./configure --enable-static && make && poetry run make install
203+
204+ # Export the requirements for the plugins so we can install them in builder-python stage
205+ WORKDIR /opt/lightningd/plugins/clnrest
206+ RUN poetry export -o requirements.txt --without-hashes
207+ WORKDIR /opt/lightningd/plugins/wss-proxy
208+ RUN poetry export -o requirements.txt --without-hashes
209+ WORKDIR /opt/lightningd
210+ RUN echo 'RUSTUP_INSTALL_OPTS="${RUSTUP_INSTALL_OPTS}"' > /tmp/rustup_install_opts.txt
205211
206212# We need to build python plugins on the target's arch because python doesn't support cross build
207- FROM ${BASE_DISTRO} as builder-python
213+ FROM ${BASE_DISTRO} AS builder-python
208214RUN apt-get update -qq && \
209215 apt-get install -qq -y --no-install-recommends \
210216 git \
@@ -222,27 +228,29 @@ RUN apt-get update -qq && \
222228 apt-get clean && \
223229 rm -rf /var/lib/apt/lists/*
224230
225- RUN curl -sSL https://install.python-poetry.org | python3 -
226231RUN update-alternatives --install /usr/bin/python python /usr/bin/python3.9 1
227-
228232ENV PYTHON_VERSION=3
229- WORKDIR /opt/lightningd
233+ RUN pip3 install --upgrade pip setuptools wheel
234+
235+ # Copy rustup_install_opts.txt file from builder
236+ COPY --from=builder /tmp/rustup_install_opts.txt /tmp/rustup_install_opts.txt
237+ # Setup ENV $RUSTUP_INSTALL_OPTS for this stage
238+ RUN export $(cat /tmp/rustup_install_opts.txt)
239+ ENV PATH="/root/.cargo/bin:$PATH"
240+ RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y ${RUSTUP_INSTALL_OPTS}
230241
231- COPY plugins/clnrest/pyproject.toml plugins/clnrest/pyproject.toml
232- COPY plugins/wss-proxy/pyproject.toml plugins/wss-proxy/pyproject.toml
242+ WORKDIR /opt/lightningd/plugins/clnrest
243+ COPY --from=builder /opt/lightningd/plugins/clnrest/requirements.txt .
244+ RUN pip3 install -r requirements.txt
233245
234- RUN cd plugins/clnrest && \
235- /root/.local/bin/poetry export -o requirements.txt --without-hashes && \
236- pip3 install -r requirements.txt && \
237- cd /opt/lightningd
246+ WORKDIR /opt/lightningd/ plugins/wss-proxy
247+ COPY --from=builder /opt/lightningd/plugins/wss-proxy/ requirements.txt .
248+ RUN pip3 install -r requirements.txt
249+ RUN pip3 cache purge
238250
239- RUN cd plugins/wss-proxy && \
240- /root/.local/bin/poetry export -o requirements.txt --without-hashes && \
241- pip3 install -r requirements.txt && \
242- cd /opt/lightningd && \
243- pip3 cache purge
251+ WORKDIR /opt/lightningd
244252
245- FROM ${BASE_DISTRO} as final
253+ FROM ${BASE_DISTRO} AS final
246254
247255RUN apt-get update && \
248256 apt-get install -y --no-install-recommends \
@@ -265,7 +273,9 @@ RUN mkdir $LIGHTNINGD_DATA && \
265273 touch $LIGHTNINGD_DATA/config
266274VOLUME [ "/root/.lightning" ]
267275
268- COPY --from=builder /tmp/lightning_install/ /usr/local/
276+ COPY --from=builder /usr/local/bin/lightning-cli /usr/local/bin/lightning-hsmtool /usr/local/bin/lightningd /usr/local/bin/reckless /usr/local/bin/
277+ COPY --from=builder /usr/local/libexec/ /usr/local/libexec
278+ COPY --from=builder /usr/local/share/ /usr/local/share
269279COPY --from=builder-python /usr/local/lib/python3.9/dist-packages/ /usr/local/lib/python3.9/dist-packages/
270280COPY --from=downloader /opt/bitcoin/bin /usr/bin
271281COPY --from=downloader /opt/litecoin/bin /usr/bin
0 commit comments