|
| 1 | +# This dockerfile is meant to cross compile with a x64 machine for a arm32v7 host |
| 2 | +# It is using multi stage build: |
| 3 | +# * downloader: Download litecoin/bitcoin and qemu binaries needed for c-lightning |
| 4 | +# * builder: Cross compile c-lightning dependencies, then c-lightning itself with static linking |
| 5 | +# * final: Copy the binaries required at runtime |
| 6 | +# The resulting image uploaded to dockerhub will only contain what is needed for runtime. |
| 7 | +# From the root of the repository, run "docker build -t yourimage:yourtag -f contrib/linuxarm32v7.Dockerfile ." |
| 8 | +FROM debian:stretch-slim as downloader |
| 9 | + |
| 10 | +RUN set -ex \ |
| 11 | + && apt-get update \ |
| 12 | + && apt-get install -qq --no-install-recommends ca-certificates dirmngr wget \ |
| 13 | + qemu qemu-user-static qemu-user binfmt-support |
| 14 | + |
| 15 | +WORKDIR /opt |
| 16 | + |
| 17 | +ARG BITCOIN_VERSION=0.17.0 |
| 18 | +ENV BITCOIN_TARBALL bitcoin-$BITCOIN_VERSION-arm-linux-gnueabihf.tar.gz |
| 19 | +ENV BITCOIN_URL https://bitcoincore.org/bin/bitcoin-core-$BITCOIN_VERSION/$BITCOIN_TARBALL |
| 20 | +ENV BITCOIN_ASC_URL https://bitcoincore.org/bin/bitcoin-core-$BITCOIN_VERSION/SHA256SUMS.asc |
| 21 | + |
| 22 | +RUN mkdir /opt/bitcoin && cd /opt/bitcoin \ |
| 23 | + && wget -qO $BITCOIN_TARBALL "$BITCOIN_URL" \ |
| 24 | + && wget -qO bitcoin.asc "$BITCOIN_ASC_URL" \ |
| 25 | + && grep $BITCOIN_TARBALL bitcoin.asc | tee SHA256SUMS.asc \ |
| 26 | + && sha256sum -c SHA256SUMS.asc \ |
| 27 | + && BD=bitcoin-$BITCOIN_VERSION/bin \ |
| 28 | + && tar -xzvf $BITCOIN_TARBALL $BD/bitcoin-cli --strip-components=1 \ |
| 29 | + && rm $BITCOIN_TARBALL |
| 30 | + |
| 31 | +ENV LITECOIN_VERSION 0.14.2 |
| 32 | +ENV LITECOIN_TARBALL litecoin-$LITECOIN_VERSION-arm-linux-gnueabihf.tar.gz |
| 33 | +ENV LITECOIN_URL https://download.litecoin.org/litecoin-$LITECOIN_VERSION/linux/$LITECOIN_TARBALL |
| 34 | +ENV LITECOIN_SHA256 e79f2a8e8e1b9920d07cff8482237b56aa4be2623103d3d2825ce09a2cc2f6d7 |
| 35 | + |
| 36 | +# install litecoin binaries |
| 37 | +RUN mkdir /opt/litecoin && cd /opt/litecoin \ |
| 38 | + && wget -qO litecoin.tar.gz "$LITECOIN_URL" \ |
| 39 | + && echo "$LITECOIN_SHA256 litecoin.tar.gz" | sha256sum -c - \ |
| 40 | + && BD=litecoin-$LITECOIN_VERSION/bin \ |
| 41 | + && tar -xzvf litecoin.tar.gz $BD/litecoin-cli --strip-components=1 --exclude=*-qt \ |
| 42 | + && rm litecoin.tar.gz |
| 43 | + |
| 44 | +FROM debian:stretch-slim as builder |
| 45 | + |
| 46 | +ENV LIGHTNINGD_VERSION=master |
| 47 | +RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates autoconf automake build-essential git libtool python python3 wget gnupg dirmngr git \ |
| 48 | + libc6-armhf-cross gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf |
| 49 | + |
| 50 | +ENV target_host=arm-linux-gnueabihf |
| 51 | + |
| 52 | +ENV AR=${target_host}-ar \ |
| 53 | +AS=${target_host}-as \ |
| 54 | +CC=${target_host}-gcc \ |
| 55 | +CXX=${target_host}-g++ \ |
| 56 | +LD=${target_host}-ld \ |
| 57 | +STRIP=${target_host}-strip \ |
| 58 | +QEMU_LD_PREFIX=/usr/${target_host} \ |
| 59 | +HOST=${target_host} |
| 60 | + |
| 61 | +RUN wget -q https://zlib.net/zlib-1.2.11.tar.gz \ |
| 62 | +&& tar xvf zlib-1.2.11.tar.gz \ |
| 63 | +&& cd zlib-1.2.11 \ |
| 64 | +&& ./configure --prefix=$QEMU_LD_PREFIX \ |
| 65 | +&& make \ |
| 66 | +&& make install && cd .. && rm zlib-1.2.11.tar.gz && rm -rf zlib-1.2.11 |
| 67 | + |
| 68 | +RUN apt-get install -y --no-install-recommends unzip tclsh \ |
| 69 | +&& wget -q https://www.sqlite.org/2018/sqlite-src-3260000.zip \ |
| 70 | +&& unzip sqlite-src-3260000.zip \ |
| 71 | +&& cd sqlite-src-3260000 \ |
| 72 | +&& ./configure --enable-static --disable-readline --disable-threadsafe --disable-load-extension --host=${target_host} --prefix=$QEMU_LD_PREFIX \ |
| 73 | +&& make \ |
| 74 | +&& make install && cd .. && rm sqlite-src-3260000.zip && rm -rf sqlite-src-3260000 |
| 75 | + |
| 76 | +RUN wget -q https://gmplib.org/download/gmp/gmp-6.1.2.tar.xz \ |
| 77 | +&& tar xvf gmp-6.1.2.tar.xz \ |
| 78 | +&& cd gmp-6.1.2 \ |
| 79 | +&& ./configure --disable-assembly --prefix=$QEMU_LD_PREFIX --host=${target_host} \ |
| 80 | +&& make \ |
| 81 | +&& make install && cd .. && rm gmp-6.1.2.tar.xz && rm -rf gmp-6.1.2 |
| 82 | + |
| 83 | +COPY --from=downloader /usr/bin/qemu-arm-static /usr/bin/qemu-arm-static |
| 84 | +WORKDIR /opt/lightningd |
| 85 | +COPY . . |
| 86 | +ARG DEVELOPER=0 |
| 87 | +RUN ./configure --enable-static && make -j3 DEVELOPER=${DEVELOPER} && cp lightningd/lightning* cli/lightning-cli /usr/bin/ |
| 88 | + |
| 89 | +FROM arm32v7/debian:stretch-slim as final |
| 90 | +COPY --from=downloader /usr/bin/qemu-arm-static /usr/bin/qemu-arm-static |
| 91 | +RUN apt-get update && apt-get install -y --no-install-recommends socat inotify-tools \ |
| 92 | + && rm -rf /var/lib/apt/lists/* |
| 93 | + |
| 94 | +ENV LIGHTNINGD_DATA=/root/.lightning |
| 95 | +ENV LIGHTNINGD_PORT=9835 |
| 96 | + |
| 97 | +RUN mkdir $LIGHTNINGD_DATA && \ |
| 98 | + touch $LIGHTNINGD_DATA/config |
| 99 | +VOLUME [ "/root/.lightning" ] |
| 100 | + |
| 101 | +COPY --from=builder /opt/lightningd/cli/lightning-cli /usr/bin |
| 102 | +COPY --from=builder /opt/lightningd/lightningd/lightning* /usr/bin/ |
| 103 | +COPY --from=downloader /opt/bitcoin/bin /usr/bin |
| 104 | +COPY --from=downloader /opt/litecoin/bin /usr/bin |
| 105 | +COPY tools/docker-entrypoint.sh entrypoint.sh |
| 106 | + |
| 107 | +EXPOSE 9735 9835 |
| 108 | +ENTRYPOINT [ "./entrypoint.sh" ] |
0 commit comments