From ea394c75c77e6933b1dd0c9b3161ab53cc285cf2 Mon Sep 17 00:00:00 2001 From: Antonin Hildebrand Date: Thu, 11 Apr 2019 23:54:07 +0200 Subject: [PATCH] add docker support --- README.md | 31 +++++++++++++++++++++++++++ docker/.gitignore | 1 + docker/build.sh | 16 ++++++++++++++ docker/clean.sh | 12 +++++++++++ docker/docker-compose.yml | 25 ++++++++++++++++++++++ docker/inspect.sh | 7 ++++++ docker/lntop.sh | 7 ++++++ docker/lntop/Dockerfile | 45 +++++++++++++++++++++++++++++++++++++++ docker/lntop/config.toml | 14 ++++++++++++ docker/lntop/home/run | 11 ++++++++++ docker/logs.sh | 7 ++++++ 11 files changed, 176 insertions(+) create mode 100644 docker/.gitignore create mode 100755 docker/build.sh create mode 100755 docker/clean.sh create mode 100644 docker/docker-compose.yml create mode 100755 docker/inspect.sh create mode 100755 docker/lntop.sh create mode 100644 docker/lntop/Dockerfile create mode 100644 docker/lntop/config.toml create mode 100755 docker/lntop/home/run create mode 100755 docker/logs.sh diff --git a/README.md b/README.md index 79df6ea..92931ea 100644 --- a/README.md +++ b/README.md @@ -39,3 +39,34 @@ conn_timeout = 1000000 pool_capacity = 3 ``` Change macaroon path according to your network. + +## Docker + +If you prefer to run `lntop` from a docker container: + +```sh +cd docker + +# now you should review ./lntop/config.toml + +# point LND_HOME to your actual lnd directory +# we recommend using .envrc with direnv +export LND_HOME=~/.lnd + +# build the container +./build.sh + +# run lntop from the contaner +./lntop.sh +``` + +To see `lntop` logs, you can tail them in another terminal session via: +```sh +./logs.sh -f +``` + +To start from scratch: +```sh +./clean.sh +./build.sh --no-cache +``` \ No newline at end of file diff --git a/docker/.gitignore b/docker/.gitignore new file mode 100644 index 0000000..a977a0f --- /dev/null +++ b/docker/.gitignore @@ -0,0 +1 @@ +lntop/_src \ No newline at end of file diff --git a/docker/build.sh b/docker/build.sh new file mode 100755 index 0000000..6b50ce4 --- /dev/null +++ b/docker/build.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash + +set -e -o pipefail + +cd "$(dirname "${BASH_SOURCE[0]}")" + +LND_HOME=${LND_HOME:?required} +LNTOP_SRC_DIR=${LNTOP_SRC_DIR:-./..} + +# we rsync repo sources to play well with docker cache +echo "Staging lntop source code..." +mkdir -p lntop/_src +rsync -a --exclude='.git/' --exclude='docker/' --exclude='README.md' --exclude='LICENSE' "$LNTOP_SRC_DIR" lntop/_src + +echo "Building lntop docker container..." +exec docker-compose build "$@" lntop \ No newline at end of file diff --git a/docker/clean.sh b/docker/clean.sh new file mode 100755 index 0000000..2f8b87e --- /dev/null +++ b/docker/clean.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash + +set -e -o pipefail + +# stop and remove all containers from lntop image (see https://stackoverflow.com/a/32074098/84283) +CONTAINERS=$(docker ps -a -q --filter ancestor=lntop --format="{{.ID}}") +if [[ -n "$CONTAINERS" ]]; then + docker rm $(docker stop ${CONTAINERS}) +fi + +# clean source code stage +rm -rf lntop/_src \ No newline at end of file diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml new file mode 100644 index 0000000..bc6f42e --- /dev/null +++ b/docker/docker-compose.yml @@ -0,0 +1,25 @@ +# we have a really simple setup here +# we use docker-compose only as a convenient way to specify docker build parameters via a yaml file +# you could as well use Dockerfile directly with `docker build` and config passed via command-line args +# +# tips: +# - to run lntop from docker, you can use our wrapper script ./lntop.sh +# - see other scripts in this folder, also check the docker section in the main readme + +version: '3.7' + +services: + + lntop: + image: lntop + container_name: lntop + command: ["run"] + network_mode: host + build: + context: ./lntop + dockerfile: Dockerfile + args: + - LNTOP_SRC_PATH=_src + - LNTOP_CONF_PATH=config.toml + volumes: + - $LND_HOME:/root/.lnd diff --git a/docker/inspect.sh b/docker/inspect.sh new file mode 100755 index 0000000..c6d23e5 --- /dev/null +++ b/docker/inspect.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +set -e -o pipefail + +LND_HOME=${LND_HOME:?required} + +exec docker exec -ti lntop fish \ No newline at end of file diff --git a/docker/lntop.sh b/docker/lntop.sh new file mode 100755 index 0000000..8da240f --- /dev/null +++ b/docker/lntop.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +set -e -o pipefail + +LND_HOME=${LND_HOME:?required} + +exec docker-compose run --rm --name lntop lntop /sbin/tini -- lntop \ No newline at end of file diff --git a/docker/lntop/Dockerfile b/docker/lntop/Dockerfile new file mode 100644 index 0000000..d433f21 --- /dev/null +++ b/docker/lntop/Dockerfile @@ -0,0 +1,45 @@ +FROM golang:1.12-alpine as builder + +# install build dependencies +RUN apk add --no-cache --update git gcc musl-dev + +ARG LNTOP_SRC_PATH + +WORKDIR /root/_build + +# we want to populate the module cache based on the go.{mod,sum} files. +COPY "$LNTOP_SRC_PATH/go.mod" . +COPY "$LNTOP_SRC_PATH/go.sum" . + +# pre-cache deps +# see https://container-solutions.com/faster-builds-in-docker-with-go-1-11/ +RUN go mod download + +WORKDIR $GOPATH/src/github.com/edouardparis/lntop +COPY "$LNTOP_SRC_PATH" . + +ENV GO111MODULE=on +RUN go install ./... + +# --------------------------------------------------------------------------------------------------------------------------- + +FROM golang:1.12-alpine as final + +RUN apk add --no-cache \ + bash fish \ + ca-certificates \ + tini + +ENV PATH $PATH:/root + +ARG LNTOP_CONF_PATH + +# copy the binaries and entrypoint from the builder image. +COPY --from=builder /go/bin/lntop /bin/ + +WORKDIR /root + +COPY "home" . + +RUN mkdir ".lntop" +COPY "$LNTOP_CONF_PATH" ".lntop/" \ No newline at end of file diff --git a/docker/lntop/config.toml b/docker/lntop/config.toml new file mode 100644 index 0000000..b5f518b --- /dev/null +++ b/docker/lntop/config.toml @@ -0,0 +1,14 @@ +[logger] +type = "development" # "production" +dest = "/root/.lntop/lntop.log" + +[network] +name = "lnd" +type = "lnd" +address = "//127.0.0.1:10009" +cert = "/root/.lnd/tls.cert" +macaroon = "/root/.lnd/data/chain/bitcoin/mainnet/admin.macaroon" +macaroon_timeout = 60 +max_msg_recv_size = 52428800 +conn_timeout = 1000000 +pool_capacity = 3 \ No newline at end of file diff --git a/docker/lntop/home/run b/docker/lntop/home/run new file mode 100755 index 0000000..71931db --- /dev/null +++ b/docker/lntop/home/run @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +set -e -o pipefail + +if [[ ! $# -eq 0 ]]; then + exec "$@" +fi + +echo "this docker-compose service is not designed to be launched via docker-compose up" +echo "exec lntop via ./lntop.sh or directly via docker, e.g. \`docker exec -ti lntop lntop\`" +exit 1 \ No newline at end of file diff --git a/docker/logs.sh b/docker/logs.sh new file mode 100755 index 0000000..f0d4038 --- /dev/null +++ b/docker/logs.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +set -e -o pipefail + +LND_HOME=${LND_HOME:?required} + +exec docker exec lntop tail /root/.lntop/lntop.log "$@" \ No newline at end of file