Skip to content

Commit

Permalink
Merge pull request #14 from darwin/drop-docker-compose
Browse files Browse the repository at this point in the history
docker: drop docker-compose dependency
  • Loading branch information
edouardparis authored Apr 29, 2019
2 parents 2f18d9a + 9e50120 commit cdcb1d0
Show file tree
Hide file tree
Showing 13 changed files with 150 additions and 87 deletions.
34 changes: 1 addition & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion docker/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
lntop/_src
_volumes
_volumes
.envrc
43 changes: 43 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -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
```
26 changes: 24 additions & 2 deletions docker/_settings.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}
11 changes: 10 additions & 1 deletion docker/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
"$@" \
.
5 changes: 4 additions & 1 deletion docker/clean.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
28 changes: 0 additions & 28 deletions docker/docker-compose.yml

This file was deleted.

6 changes: 5 additions & 1 deletion docker/inspect.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
34 changes: 33 additions & 1 deletion docker/lntop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 "$@"
2 changes: 2 additions & 0 deletions docker/lntop/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ RUN apk add --no-cache \
ca-certificates \
tini

ENTRYPOINT ["/sbin/tini", "--"]

ENV PATH $PATH:/root

ARG LNTOP_CONF_PATH
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 23 additions & 5 deletions docker/lntop/home/run-lntop
Original file line number Diff line number Diff line change
Expand Up @@ -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}

Expand All @@ -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 "$@"
11 changes: 0 additions & 11 deletions docker/lntop/home/run-service

This file was deleted.

0 comments on commit cdcb1d0

Please sign in to comment.