2
0
mirror of https://github.com/edouardparis/lntop synced 2024-11-16 00:12:44 +00:00

Merge pull request #7 from darwin/lntop-volume

docker: map lntop data as a volume to host folder
This commit is contained in:
Edouard 2019-04-13 17:46:20 +02:00 committed by GitHub
commit 238995cda8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 63 additions and 21 deletions

View File

@ -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:

3
docker/.gitignore vendored
View File

@ -1 +1,2 @@
lntop/_src
lntop/_src
_volumes

9
docker/_settings.sh Executable file
View File

@ -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)}

View File

@ -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

View File

@ -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}}")

View File

@ -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

View File

@ -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

View File

@ -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
exec docker-compose run --rm --name lntop lntop /sbin/tini -- run-lntop

View File

@ -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" .

24
docker/lntop/home/run-lntop Executable file
View File

@ -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

View File

@ -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 "$@"