Skip to content

Commit

Permalink
Adapt Dockerfile for BTCPay deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasDorier committed Apr 10, 2024
1 parent a2a136f commit e86abf4
Show file tree
Hide file tree
Showing 13 changed files with 183 additions and 449 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Docker packaging
on:
push:
tags:
- 'basedon-*'

jobs:
main:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
-
name: Set up QEMU
uses: docker/setup-qemu-action@v3
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
-
name: Environment variables
run: env
-
name: Create images
env:
DOCKERHUB_USER: ${{ secrets.DOCKERHUB_USER }}
DOCKERHUB_PASS: ${{ secrets.DOCKERHUB_PASS }}
DOCKERHUB_REPO: ${{ vars.DOCKERHUB_REPO }}
shell: bash
run: |
LATEST_TAG=${GITHUB_REF#refs/tags/}
LATEST_TAG=${LATEST_TAG:8} #trim "basedon-" from tag
echo "$DOCKERHUB_PASS" | docker login -u "$DOCKERHUB_USER" --password-stdin
docker buildx create --use
DOCKER_BUILDX_OPTS="--platform linux/amd64,linux/arm64,linux/arm/v7 --push"
docker buildx build $DOCKER_BUILDX_OPTS -t $DOCKERHUB_REPO:$LATEST_TAG .
15 changes: 0 additions & 15 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@ resolver = "2"
members = [
"cln-rpc",
"cln-grpc",
"plugins",
"plugins/grpc-plugin",
"plugins"
]
41 changes: 37 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,30 @@
# * final: Copy the binaries required at runtime
# The resulting image uploaded to dockerhub will only contain what is needed for runtime.
# From the root of the repository, run "docker build -t yourimage:yourtag ."
FROM debian:bullseye-slim as downloader

FROM debian:bullseye-slim as base-downloader

FROM --platform=$BUILDPLATFORM debian:bullseye-slim as base-downloader
RUN set -ex \
&& apt-get update \
&& apt-get install -qq --no-install-recommends ca-certificates dirmngr wget

FROM --platform=$BUILDPLATFORM base-downloader as base-downloader-linux-amd64
ENV TARBALL_ARCH_FINAL=x86_64-linux-gnu
ENV DESCHASHPLUGIN_ARCH=linux-amd64
ENV DESCHASHPLUGIN_HASH=deadc00c68fac80b2718d92f69bf06acd8fff646228d497bbb76a4f0a12ca217

FROM --platform=$BUILDPLATFORM base-downloader as base-downloader-linux-arm64
ENV TARBALL_ARCH_FINAL=aarch64-linux-gnu
ENV DESCHASHPLUGIN_ARCH=linux-arm64
ENV DESCHASHPLUGIN_HASH=d48c3e5aede77bd9cb72d78689ce12c0327f624435cb0496b3eacb92df416363

FROM --platform=$BUILDPLATFORM base-downloader as base-downloader-linux-arm
ENV TARBALL_ARCH_FINAL=arm-linux-gnueabihf
ENV DESCHASHPLUGIN_ARCH=linux-arm
ENV DESCHASHPLUGIN_HASH=f7df336c72dd1674bd18ff23862a410b6a9691a3e13752264dcffa0950e21c74

FROM base-downloader-${TARGETOS}-${TARGETARCH} as downloader

RUN set -ex \
&& apt-get update \
Expand All @@ -14,9 +37,7 @@ RUN set -ex \
WORKDIR /opt


ARG BITCOIN_VERSION=22.0
ARG TARBALL_ARCH=x86_64-linux-gnu
ENV TARBALL_ARCH_FINAL=$TARBALL_ARCH
ENV BITCOIN_VERSION=22.0
ENV BITCOIN_TARBALL bitcoin-${BITCOIN_VERSION}-${TARBALL_ARCH_FINAL}.tar.gz
ENV BITCOIN_URL https://bitcoincore.org/bin/bitcoin-core-$BITCOIN_VERSION/$BITCOIN_TARBALL
ENV BITCOIN_ASC_URL https://bitcoincore.org/bin/bitcoin-core-$BITCOIN_VERSION/SHA256SUMS
Expand All @@ -39,6 +60,14 @@ RUN mkdir /opt/litecoin && cd /opt/litecoin \
&& tar -xzvf litecoin.tar.gz litecoin-$LITECOIN_VERSION/bin/litecoin-cli --strip-components=1 --exclude=*-qt \
&& rm litecoin.tar.gz

ENV DESCHASHPLUGIN_URL https://github.com/nbd-wtf/invoicewithdescriptionhash/releases/download/v1.4/invoicewithdescriptionhash-v1.4-${DESCHASHPLUGIN_ARCH}.tar.gz
ENV DESCHASHPLUGIN_SHA256 ${DESCHASHPLUGIN_HASH}
RUN mkdir /opt/deschashplugin && cd /opt/deschashplugin \
&& wget -qO invoicewithdescriptionhash.tar.gz "$DESCHASHPLUGIN_URL" \
&& echo "$DESCHASHPLUGIN_SHA256 invoicewithdescriptionhash.tar.gz" | sha256sum -c - \
&& tar -xzvf invoicewithdescriptionhash.tar.gz && rm invoicewithdescriptionhash.tar.gz \
&& chmod a+x invoicewithdescriptionhash

FROM debian:bullseye-slim as builder

ENV LIGHTNINGD_VERSION=master
Expand Down Expand Up @@ -135,13 +164,17 @@ ENV LIGHTNINGD_PORT=9735
ENV LIGHTNINGD_NETWORK=bitcoin

RUN mkdir $LIGHTNINGD_DATA && \
mkdir /etc/bundledplugins && \
mkdir $LIGHTNINGD_DATA/plugins && \
touch $LIGHTNINGD_DATA/config
VOLUME [ "/root/.lightning" ]

COPY --from=builder /tmp/lightning_install/ /usr/local/
COPY --from=builder /usr/local/lib/python3.9/dist-packages/ /usr/local/lib/python3.9/dist-packages/
COPY --from=downloader /opt/bitcoin/bin /usr/bin
COPY --from=downloader /opt/litecoin/bin /usr/bin
COPY --from=downloader /opt/deschashplugin $LIGHTNINGD_DATA/plugins
COPY --from=downloader /opt/deschashplugin /etc/bundledplugins
COPY tools/docker-entrypoint.sh entrypoint.sh

EXPOSE 9735 9835
Expand Down
8 changes: 0 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -384,14 +384,6 @@ GRPC_GEN = \
$(GRPC_PATH)/node_pb2_grpc.py \
$(GRPC_PATH)/primitives_pb2.py

ALL_TEST_GEN += $(GRPC_GEN)

$(GRPC_GEN) &: cln-grpc/proto/node.proto cln-grpc/proto/primitives.proto
$(PYTHON) -m grpc_tools.protoc -I cln-grpc/proto cln-grpc/proto/node.proto --python_out=$(GRPC_PATH)/ --grpc_python_out=$(GRPC_PATH)/ --experimental_allow_proto3_optional
$(PYTHON) -m grpc_tools.protoc -I cln-grpc/proto cln-grpc/proto/primitives.proto --python_out=$(GRPC_PATH)/ --experimental_allow_proto3_optional
find $(GRPC_DIR)/ -type f -name "*.py" -print0 | xargs -0 sed -i'.bak' -e 's/^import \(.*\)_pb2 as .*__pb2/from pyln.grpc import \1_pb2 as \1__pb2/g'
find $(GRPC_DIR)/ -type f -name "*.py.bak" -print0 | xargs -0 rm -f

# We make pretty much everything depend on these.
ALL_GEN_HEADERS := $(filter %gen.h,$(ALL_C_HEADERS))
ALL_GEN_SOURCES := $(filter %gen.c,$(ALL_C_SOURCES))
Expand Down
1 change: 0 additions & 1 deletion plugins/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,3 @@ tracing = { version = "^0.1", features = ["async-await", "log"] }

[dev-dependencies]
tokio = { version = "1", features = ["macros", "rt-multi-thread", ] }
cln-grpc = { version = "0.1", path = "../cln-grpc" }
14 changes: 1 addition & 13 deletions plugins/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,6 @@ endif
PLUGINS := $(C_PLUGINS)
PLUGIN_ALL_OBJS := $(PLUGIN_ALL_SRC:.c=.o)

ifneq ($(RUST),0)
# Builtin plugins must be in this plugins dir to work when we're executed
# *without* make install.
plugins/cln-grpc: target/${RUST_PROFILE}/cln-grpc
@cp $< $@

PLUGINS += plugins/cln-grpc
endif

PLUGIN_COMMON_OBJS := \
bitcoin/base58.o \
bitcoin/block.o \
Expand Down Expand Up @@ -253,11 +244,8 @@ CLN_PLUGIN_EXAMPLES := \

CLN_PLUGIN_SRC = $(shell find plugins/src -name "*.rs")

target/${RUST_PROFILE}/cln-grpc: ${CLN_PLUGIN_SRC}
cargo build ${CARGO_OPTS} --bin cln-grpc

ifneq ($(RUST),0)
DEFAULT_TARGETS += $(CLN_PLUGIN_EXAMPLES) plugins/cln-grpc
DEFAULT_TARGETS += $(CLN_PLUGIN_EXAMPLES)
endif

clean: plugins-clean
Expand Down
22 changes: 13 additions & 9 deletions plugins/bcli.c
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,7 @@ static void wait_and_check_bitcoind(struct plugin *p)
pid_t child;
const char **cmd = gather_args(bitcoind, "getnetworkinfo", NULL);
bool printed = false;
bool isWarmup = false;
char *output = NULL;

for (;;) {
Expand Down Expand Up @@ -1004,17 +1005,20 @@ static void wait_and_check_bitcoind(struct plugin *p)
/* bitcoin/src/rpc/protocol.h:
* RPC_IN_WARMUP = -28, //!< Client still warming up
*/
if (WEXITSTATUS(status) != 28) {
if (WEXITSTATUS(status) == 1)
bitcoind_failure(p, "Could not connect to bitcoind using"
" bitcoin-cli. Is bitcoind running?");
bitcoind_failure(p, tal_fmt(bitcoind, "%s exited with code %i: %s",
cmd[0], WEXITSTATUS(status), output));
}
isWarmup = WEXITSTATUS(status) == 28;

if (!printed) {
plugin_log(p, LOG_UNUSUAL,
"Waiting for bitcoind to warm up...");
if (isWarmup)
{
plugin_log(p, LOG_UNUSUAL,
"Waiting for bitcoind to warm up...");
}
else
{
plugin_log(p, LOG_UNUSUAL,
tal_fmt(bitcoind, "%s exited with code %i: %s... retrying",
cmd[0], WEXITSTATUS(status), output));
}
printed = true;
}
sleep(1);
Expand Down
30 changes: 0 additions & 30 deletions plugins/grpc-plugin/Cargo.toml

This file was deleted.

Loading

0 comments on commit e86abf4

Please sign in to comment.