docker: drop docker-compose dependency

Instead of relying on docker-compose.yml, we use bash to pass
configuration to docker directly via commnad-line args.

We also use config template and prior each run we evaluate it
with current environment. So that settings like LND_GRPC_HOST
can be specified prior each run without a need to rebuild.
pull/14/head
Antonin Hildebrand 5 years ago
parent 2f18d9a37c
commit 9e50120dec

@ -42,39 +42,7 @@ 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/home/initial-config.toml
# if you have an existing .lntop directory, you can export it
# export LNTOP_HOME=~/.lntop
# ! change path to files in .lntop/config with user current directory /root !
# 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 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:
```sh
./logs.sh -f
```
To start from scratch:
```sh
./clean.sh
./build.sh --no-cache
```
If you prefer to run `lntop` from a docker container, `cd docker` and follow [`README`](docker/README.md) there.
## Compatibility

3
docker/.gitignore vendored

@ -1,2 +1,3 @@
lntop/_src
_volumes
_volumes
.envrc

@ -0,0 +1,43 @@
## Docker
To run `lntop` from a docker container:
```sh
# you should first review ./lntop/home/initial-config-template.toml
# note that paths are relevant to situation inside docker and we run under root
# so $HOME directory is /root
# build the container
./build.sh
# if you have an existing .lntop directory on host machine, you can export it:
# export LNTOP_HOME=~/.lntop
# if you have local lnd node on host machine, point LND_HOME to your actual lnd directory:
export LND_HOME=~/.lnd
# or alternatively if you have remote lnd node, specify paths to auth files explicitly:
# export TLS_CERT_FILE=/path/to/tls.cert
# export ADMIN_MACAROON_FILE=/path/to/admin.macaroon
# export LND_GRPC_HOST=//<remoteip>:10009
# look into _settings.sh for more details on container configuration
# run lntop from the container
./lntop.sh
# lntop data will be mapped to host folder at ./_volumes/lntop-data
# note that you can review/tweak ./_volumes/lntop-data/config-template.toml after first run
# the ./_volumes/lntop-data/config.toml is the effective (generated) config used by lntop run
```
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
```

@ -2,8 +2,30 @@
set -e -o pipefail
export LND_HOME=${LND_HOME:-$HOME/.lnd}
export LNTOP_HOME=${LNTOP_HOME:-./_volumes/lntop-data}
# you have two possible ways how to specify ADMIN_MACAROON_FILE and TLS_CERT_FILE
# 1. specify LND_HOME if it is located on your local machine, we derive default paths from there
# 2. specify env variables ADMIN_MACAROON_FILE and TLS_CERT_FILE
# also you want to specify LND_GRPC_HOST if your node is remote
# other config tweaks have to be done by changing lntop/home/initial-config-template.toml before build
# or ./_volumes/lntop-data/config-template.toml if you want to just an ad-hoc tweak of existing container
# note: docker uses network_mode: host
if [[ -z "$ADMIN_MACAROON_FILE" || -z "$TLS_CERT_FILE" ]]; then
if [[ -z "$LND_HOME" ]]; then
export LND_HOME="$HOME/.lnd"
echo "warning: LND_HOME is not set, assuming '$LND_HOME'"
fi
fi
export ADMIN_MACAROON_FILE=${ADMIN_MACAROON_FILE:-$LND_HOME/data/chain/bitcoin/mainnet/admin.macaroon}
export TLS_CERT_FILE=${TLS_CERT_FILE:-$LND_HOME/tls.cert}
export LND_GRPC_HOST=${LND_GRPC_HOST:-//127.0.0.1:10009}
export LNTOP_SRC_DIR=${LNTOP_SRC_DIR:-./..}
export LNTOP_HOME=${LNTOP_HOME:-./_volumes/lntop-data}
export LNTOP_AUX_DIR=${LNTOP_AUX_DIR:-./_volumes/lntop-aux}
export LNTOP_HOST_UID=${LNTOP_HOST_UID:-$(id -u)}
export LNTOP_HOST_GID=${LNTOP_HOST_GID:-$(id -g)}
export LNTOP_VERBOSE=${LNTOP_VERBOSE}

@ -16,5 +16,14 @@ rsync -a \
"$LNTOP_SRC_DIR" \
lntop/_src
cd lntop
echo "Building lntop docker container..."
exec docker-compose build "$@" lntop
if [[ -n "$LNTOP_VERBOSE" ]]; then
set -x
fi
exec docker build \
--build-arg LNTOP_SRC_PATH=_src \
-t lntop:local \
"$@" \
.

@ -11,4 +11,7 @@ if [[ -n "$CONTAINERS" ]]; then
fi
# clean source code stage
rm -rf lntop/_src
rm -rf lntop/_src
# clean volumes
rm -rf _volumes

@ -1,28 +0,0 @@
# 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-service"]
network_mode: host
build:
context: ./lntop
dockerfile: Dockerfile
args:
- LNTOP_SRC_PATH=_src
volumes:
- $LND_HOME:/root/.lnd
- $LNTOP_HOME:/root/.lntop
environment:
- LNTOP_HOST_UID
- LNTOP_HOST_GID

@ -4,4 +4,8 @@ cd "$(dirname "${BASH_SOURCE[0]}")"
. _settings.sh
exec docker exec -ti lntop fish
if [[ $# -eq 0 ]]; then
exec ./lntop.sh inspect ${PREFERRED_SHELL}
else
exec ./lntop.sh inspect "$@"
fi

@ -4,4 +4,36 @@ cd "$(dirname "${BASH_SOURCE[0]}")"
. _settings.sh
exec docker-compose run --rm --name lntop lntop /sbin/tini -- run-lntop
abs_path() {
echo "$(cd "$1"; pwd -P)"
}
if [[ ! -e "$LNTOP_HOME" ]]; then
mkdir -p "$LNTOP_HOME"
fi
LNTOP_HOME_ABSOLUTE=$(abs_path "$LNTOP_HOME")
if [[ ! -e "$LNTOP_AUX_DIR" ]]; then
mkdir -p "$LNTOP_AUX_DIR"
fi
LNTOP_AUX_DIR_ABSOLUTE=$(abs_path "$LNTOP_AUX_DIR")
# we use LNTOP_AUX_DIR as ad-hoc volume to pass admin.macaroon and tls.cert into our container
# it is mapped to /root/aux, config-template.toml assumes that
cp "$ADMIN_MACAROON_FILE" "$LNTOP_AUX_DIR/admin.macaroon"
cp "$TLS_CERT_FILE" "$LNTOP_AUX_DIR/tls.cert"
if [[ -n "$LNTOP_VERBOSE" ]]; then
set -x
fi
exec docker run \
--rm \
--network host \
-v "$LNTOP_HOME_ABSOLUTE:/root/.lntop" \
-v "$LNTOP_AUX_DIR_ABSOLUTE:/root/aux" \
-e "LNTOP_HOST_UID=${LNTOP_HOST_UID}" \
-e "LNTOP_HOST_GID=${LNTOP_HOST_GID}" \
-e "LND_GRPC_HOST=${LND_GRPC_HOST}" \
-ti \
lntop:local \
run-lntop "$@"

@ -26,6 +26,8 @@ RUN apk add --no-cache \
ca-certificates \
tini
ENTRYPOINT ["/sbin/tini", "--"]
ENV PATH $PATH:/root
ARG LNTOP_CONF_PATH

@ -5,9 +5,9 @@ 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"
address = "${LND_GRPC_HOST}"
cert = "/root/aux/tls.cert"
macaroon = "/root/aux/admin.macaroon"
macaroon_timeout = 60
max_msg_recv_size = 52428800
conn_timeout = 1000000

@ -2,10 +2,17 @@
set -e -o pipefail
# this is a special command to allow inspection on this container
if [[ "$1" == "inspect" ]]; then
shift
exec "$@"
fi
cd "$(dirname "${BASH_SOURCE[0]}")"
LNTOP_HOME_DIR=.lntop
LNTOP_CONFIG="$LNTOP_HOME_DIR/config.toml"
LNTOP_CONFIG_TEMPLATE="$LNTOP_HOME_DIR/config-template.toml"
LNTOP_HOST_GID=${LNTOP_HOST_GID:?required}
LNTOP_HOST_UID=${LNTOP_HOST_UID:?required}
@ -15,10 +22,21 @@ if [[ ! -d "$LNTOP_HOME_DIR" ]]; then
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"
eval_template() {
local template_file=$1
eval "cat <<TEMPLATE_EOF_MARKER
$(<${template_file})
TEMPLATE_EOF_MARKER
" 2> /dev/null
}
# stage template file only if it does not already exist
if [[ ! -e "$LNTOP_CONFIG_TEMPLATE" ]]; then
cp initial-config-template.toml "$LNTOP_CONFIG_TEMPLATE"
fi
exec lntop
# we dynamically prepare config from template by baking in env variables
echo "# !!! GENERATED !!! DO NOT EDIT THIS FILE, EDIT config-template.toml INSTEAD" > "$LNTOP_CONFIG"
eval_template initial-config-template.toml >> "$LNTOP_CONFIG"
exec lntop "$@"

@ -1,11 +0,0 @@
#!/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
Loading…
Cancel
Save