From c9e0a51c6941dceeaa49e5ba69ee89d832b52985 Mon Sep 17 00:00:00 2001 From: Antonin Hildebrand Date: Sat, 13 Apr 2019 12:41:35 +0200 Subject: [PATCH] docker: map lntop data as a volume to host folder --- README.md | 4 +++- docker/.gitignore | 3 ++- docker/_settings.sh | 9 +++++++ docker/build.sh | 14 +++++++---- docker/clean.sh | 4 +++- docker/docker-compose.yml | 7 ++++-- docker/inspect.sh | 4 ++-- docker/lntop.sh | 6 ++--- docker/lntop/Dockerfile | 5 +--- .../{config.toml => home/initial-config.toml} | 0 docker/lntop/home/run-lntop | 24 +++++++++++++++++++ docker/lntop/home/{run => run-service} | 0 docker/logs.sh | 4 ++-- 13 files changed, 63 insertions(+), 21 deletions(-) create mode 100755 docker/_settings.sh rename docker/lntop/{config.toml => home/initial-config.toml} (100%) create mode 100755 docker/lntop/home/run-lntop rename docker/lntop/home/{run => run-service} (100%) diff --git a/README.md b/README.md index d07748e..4f6ca1d 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ If you prefer to run `lntop` from a docker container: ```sh cd docker -# now you should review ./lntop/config.toml +# now you should review ./lntop/home/initial-config.toml # point LND_HOME to your actual lnd directory # we recommend using .envrc with direnv @@ -58,6 +58,8 @@ export LND_HOME=~/.lnd # run lntop from the container ./lntop.sh + +# lntop data will be mapped to host folder at ./_volumes/lntop-data ``` To see `lntop` logs, you can tail them in another terminal session via: diff --git a/docker/.gitignore b/docker/.gitignore index a977a0f..527e972 100644 --- a/docker/.gitignore +++ b/docker/.gitignore @@ -1 +1,2 @@ -lntop/_src \ No newline at end of file +lntop/_src +_volumes \ No newline at end of file diff --git a/docker/_settings.sh b/docker/_settings.sh new file mode 100755 index 0000000..6c3b66b --- /dev/null +++ b/docker/_settings.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +set -e -o pipefail + +export LND_HOME=${LND_HOME:-$HOME/.lnd} +export LNTOP_HOME=${LNTOP_HOME:-./_volumes/lntop-data} +export LNTOP_SRC_DIR=${LNTOP_SRC_DIR:-./..} +export LNTOP_HOST_UID=${LNTOP_HOST_UID:-$(id -u)} +export LNTOP_HOST_GID=${LNTOP_HOST_GID:-$(id -g)} diff --git a/docker/build.sh b/docker/build.sh index 6b50ce4..3776d71 100755 --- a/docker/build.sh +++ b/docker/build.sh @@ -1,16 +1,20 @@ #!/usr/bin/env bash -set -e -o pipefail - cd "$(dirname "${BASH_SOURCE[0]}")" -LND_HOME=${LND_HOME:?required} -LNTOP_SRC_DIR=${LNTOP_SRC_DIR:-./..} +. _settings.sh # 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 +rsync -a \ + --exclude='.git/' \ + --exclude='.idea/' \ + --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 index 2f8b87e..9e926f3 100755 --- a/docker/clean.sh +++ b/docker/clean.sh @@ -1,6 +1,8 @@ #!/usr/bin/env bash -set -e -o pipefail +cd "$(dirname "${BASH_SOURCE[0]}")" + +. _settings.sh # 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}}") diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index bc6f42e..2332fe4 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -13,13 +13,16 @@ services: lntop: image: lntop container_name: lntop - command: ["run"] + command: ["run-service"] network_mode: host build: context: ./lntop dockerfile: Dockerfile args: - LNTOP_SRC_PATH=_src - - LNTOP_CONF_PATH=config.toml volumes: - $LND_HOME:/root/.lnd + - $LNTOP_HOME:/root/.lntop + environment: + - LNTOP_HOST_UID + - LNTOP_HOST_GID diff --git a/docker/inspect.sh b/docker/inspect.sh index c6d23e5..7573d62 100755 --- a/docker/inspect.sh +++ b/docker/inspect.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash -set -e -o pipefail +cd "$(dirname "${BASH_SOURCE[0]}")" -LND_HOME=${LND_HOME:?required} +. _settings.sh exec docker exec -ti lntop fish \ No newline at end of file diff --git a/docker/lntop.sh b/docker/lntop.sh index 8da240f..25a9426 100755 --- a/docker/lntop.sh +++ b/docker/lntop.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash -set -e -o pipefail +cd "$(dirname "${BASH_SOURCE[0]}")" -LND_HOME=${LND_HOME:?required} +. _settings.sh -exec docker-compose run --rm --name lntop lntop /sbin/tini -- lntop \ No newline at end of file +exec docker-compose run --rm --name lntop lntop /sbin/tini -- run-lntop \ No newline at end of file diff --git a/docker/lntop/Dockerfile b/docker/lntop/Dockerfile index 63ae28e..9a3b48b 100644 --- a/docker/lntop/Dockerfile +++ b/docker/lntop/Dockerfile @@ -35,7 +35,4 @@ COPY --from=builder /go/bin/lntop /bin/ WORKDIR /root -COPY "home" . - -RUN mkdir ".lntop" -COPY "$LNTOP_CONF_PATH" ".lntop/" +COPY "home" . \ No newline at end of file diff --git a/docker/lntop/config.toml b/docker/lntop/home/initial-config.toml similarity index 100% rename from docker/lntop/config.toml rename to docker/lntop/home/initial-config.toml diff --git a/docker/lntop/home/run-lntop b/docker/lntop/home/run-lntop new file mode 100755 index 0000000..ae49bd3 --- /dev/null +++ b/docker/lntop/home/run-lntop @@ -0,0 +1,24 @@ +#!/usr/bin/env bash + +set -e -o pipefail + +cd "$(dirname "${BASH_SOURCE[0]}")" + +LNTOP_HOME_DIR=.lntop +LNTOP_CONFIG="$LNTOP_HOME_DIR/config.toml" +LNTOP_HOST_GID=${LNTOP_HOST_GID:?required} +LNTOP_HOST_UID=${LNTOP_HOST_UID:?required} + +# make sure lntop's home dir exists (should be mapped to host via a volume) +if [[ ! -d "$LNTOP_HOME_DIR" ]]; then + mkdir -p "$LNTOP_HOME_DIR" + chown ${LNTOP_HOST_UID}:${LNTOP_HOST_GID} "$LNTOP_HOME_DIR" +fi + +# prepare config file only if it does not already exist +if [[ ! -e "$LNTOP_CONFIG" ]]; then + cp initial-config.toml "$LNTOP_CONFIG" + chown ${LNTOP_HOST_UID}:${LNTOP_HOST_GID} "$LNTOP_CONFIG" +fi + +exec lntop \ No newline at end of file diff --git a/docker/lntop/home/run b/docker/lntop/home/run-service similarity index 100% rename from docker/lntop/home/run rename to docker/lntop/home/run-service diff --git a/docker/logs.sh b/docker/logs.sh index f0d4038..24a8406 100755 --- a/docker/logs.sh +++ b/docker/logs.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash -set -e -o pipefail +cd "$(dirname "${BASH_SOURCE[0]}")" -LND_HOME=${LND_HOME:?required} +. _settings.sh exec docker exec lntop tail /root/.lntop/lntop.log "$@" \ No newline at end of file