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.
This commit is contained in:
Antonin Hildebrand 2019-04-26 19:57:00 +02:00
parent 536c7d1641
commit 07b065c912
14 changed files with 101 additions and 102 deletions

View file

@ -104,14 +104,17 @@ If you prefer to run the tool from a docker container:
```sh
cd docker
# review ./lndmanage/home/config_sample.ini
# note that settings are relevant to situation inside the docker container
# docker-compose.yml uses network_mode: host
# build the container
./build.sh
# run lndmanage inside container via a wrapper script
# prior running the container you must specify LND_HOME or ADMIN_MACAROON_FILE and TLS_CERT_FILE
export TLS_CERT_FILE=$HOME/.lnd/tls.cert
export ADMIN_MACAROON_FILE=$HOME/.lnd/data/chain/bitcoin/mainnet/admin.macaroon
# you might want to specify LND_GRPC_HOST as well
# look into _settings.sh for more details on container configuration
# run lndmanage inside a container via this wrapper script:
./lndmanage.sh status
```

3
docker/.gitignore vendored
View file

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

View file

@ -1,9 +1,29 @@
#!/usr/bin/env bash
# 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 use 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 lndmanage/home/config_template.ini
# note: docker uses network_mode: host
set -e -o pipefail
export LND_HOME=${LND_HOME:-$HOME/.lnd}
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 LNDMANAGE_SRC_DIR=${LNDMANAGE_SRC_DIR:-./..}
export LNDMANAGE_CACHE_DIR=${LNDMANAGE_CACHE_DIR:-./_volumes/lndmanage-cache}
export LNDMANAGE_AUX_DIR=${LNDMANAGE_AUX_DIR:-./_volumes/lndmanage-aux}
export LNDMANAGE_VERBOSE=${LNDMANAGE_VERBOSE}
PREFERRED_SHELL=${PREFERRED_SHELL:-fish}

View file

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

View file

@ -1,7 +0,0 @@
#!/usr/bin/env bash
cd "$(dirname "${BASH_SOURCE[0]}")"
. _settings.sh
exec docker-compose "$@"

View file

@ -1,25 +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 lndmanage from docker, you can use our wrapper script ./lndmanage.sh
# - see other scripts in this folder, also check the docker section in the main readme
version: '3.7'
services:
lndmanage:
image: lndmanage
container_name: lndmanage
command: ["run-service"]
network_mode: host
build:
context: ./lndmanage
dockerfile: Dockerfile
args:
- LNDMANAGE_HOST_SRC_PATH=_src
volumes:
- $LND_HOME:/root/.lnd
- $LNDMANAGE_CACHE_DIR:/root/lndmanage/cache

View file

@ -4,9 +4,8 @@ cd "$(dirname "${BASH_SOURCE[0]}")"
. _settings.sh
CONTAINER_ID=$(docker-compose ps -q lndmanage)
if [[ -z $(docker ps -q --no-trunc | grep "$CONTAINER_ID") ]]; then
exec ./dc run --rm lndmanage ${PREFERRED_SHELL}
if [[ $# -eq 0 ]]; then
exec ./lndmanage.sh inspect ${PREFERRED_SHELL}
else
exec ./dc exec lndmanage ${PREFERRED_SHELL}
fi
exec ./lndmanage.sh inspect "$@"
fi

View file

@ -4,9 +4,34 @@ cd "$(dirname "${BASH_SOURCE[0]}")"
. _settings.sh
CONTAINER_ID=$(docker-compose ps -q lndmanage)
if [[ -z $(docker ps -q --no-trunc | grep "$CONTAINER_ID") ]]; then
exec docker-compose run --rm lndmanage run-lndmanage "$@"
else
exec docker-compose exec lndmanage run-lndmanage "$@"
fi
abs_path() {
echo "$(cd "$1"; pwd -P)"
}
if [[ ! -e "$LNDMANAGE_CACHE_DIR" ]]; then
mkdir -p "$LNDMANAGE_CACHE_DIR"
fi
LNDMANAGE_CACHE_DIR_ABSOLUTE=$(abs_path "$LNDMANAGE_CACHE_DIR")
if [[ ! -e "$LNDMANAGE_AUX_DIR" ]]; then
mkdir -p "$LNDMANAGE_AUX_DIR"
fi
LNDMANAGE_AUX_DIR_ABSOLUTE=$(abs_path "$LNDMANAGE_AUX_DIR")
# we use LNDMANAGE_AUX_DIR as ad-hoc volume to pass admin.macaroon and tls.cert into our container
# it is mapped to /root/aux, config_template.ini assumes that
cp "$ADMIN_MACAROON_FILE" "$LNDMANAGE_AUX_DIR/admin.macaroon"
cp "$TLS_CERT_FILE" "$LNDMANAGE_AUX_DIR/tls.cert"
if [[ -n "$LNDMANAGE_VERBOSE" ]]; then
set -x
fi
exec docker run \
--rm \
--network host \
-v "$LNDMANAGE_CACHE_DIR_ABSOLUTE:/root/lndmanage/cache" \
-v "$LNDMANAGE_AUX_DIR_ABSOLUTE:/root/aux" \
-e "LND_GRPC_HOST=${LND_GRPC_HOST}" \
-ti \
lndmanage:local \
run-lndmanage "$@"

View file

@ -42,5 +42,4 @@ COPY "$LNDMANAGE_HOST_SRC_PATH" .
RUN pip install -r requirements.txt
WORKDIR /root
COPY "home" .
RUN cp config_sample.ini lndmanage/config.ini
COPY "home" .

View file

@ -1,5 +0,0 @@
#!/usr/bin/env bash
set -e -o pipefail
SERVICE_PIPE=${SERVICE_PIPE:-/root/service.pipe}

View file

@ -1,9 +0,0 @@
# network settings
[network]
lnd_grpc_host = 127.0.0.1:10009
# tls and admin macaroon can be found in .lnd folder
tls_cert_file = /root/.lnd/tls.cert
admin_macaroon_file = /root/.lnd/data/chain/bitcoin/mainnet/admin.macaroon
[logging]
loglevel = INFO

View file

@ -0,0 +1,8 @@
[network]
# see docker/build.sh
lnd_grpc_host = ${LND_GRPC_HOST}
tls_cert_file = /root/aux/tls.cert
admin_macaroon_file = /root/aux/admin.macaroon
[logging]
loglevel = INFO

View file

@ -2,15 +2,25 @@
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]}")"
. _shared.sh
eval_template() {
local template_file=$1
eval "cat <<TEMPLATE_EOF_MARKER
$(<${template_file})
TEMPLATE_EOF_MARKER
" 2> /dev/null
}
# we dynamically prepare config from template by baking in env variables
eval_template config_template.ini > lndmanage/config.ini
cd lndmanage
# report our action to the service if it is watching
if [[ -p "$SERVICE_PIPE" ]]; then
echo "[$$] > ./lndmanage.py $@" > "$SERVICE_PIPE"
fi
exec ./lndmanage.py "$@"

View file

@ -1,29 +0,0 @@
#!/usr/bin/env bash
set -e -o pipefail
if [[ ! $# -eq 0 ]]; then
exec "$@"
fi
cd "$(dirname "${BASH_SOURCE[0]}")"
. _shared.sh
cd lndmanage
echo "watching..."
finish() {
rm -f "$SERVICE_PIPE"
echo "finishing..."
}
trap finish EXIT
if [[ ! -p "$SERVICE_PIPE" ]]; then
mkfifo "$SERVICE_PIPE"
fi
while true; do
cat < "$SERVICE_PIPE"
done