From 409586c45e3479924dd09c13b17cf001aa9fd8d4 Mon Sep 17 00:00:00 2001 From: Leopere Date: Sun, 28 Apr 2019 17:24:56 -0400 Subject: [PATCH 1/3] Graceful stopping is critical in Chainquery --- chainquery/Dockerfile-linux-x86_64-production | 1 + 1 file changed, 1 insertion(+) diff --git a/chainquery/Dockerfile-linux-x86_64-production b/chainquery/Dockerfile-linux-x86_64-production index 209ae25..c280476 100644 --- a/chainquery/Dockerfile-linux-x86_64-production +++ b/chainquery/Dockerfile-linux-x86_64-production @@ -20,4 +20,5 @@ RUN adduser chainquery --gecos GECOS --shell /bin/bash --disabled-password --hom COPY --from=prep /chainquery /start /usr/bin/ EXPOSE 6300 USER chainquery +STOPSIGNAL SIGINT CMD ["start"] -- 2.45.2 From 77ee9dc39d7cec6598031805d0be9b7e80df834a Mon Sep 17 00:00:00 2001 From: Leopere Date: Sun, 28 Apr 2019 17:26:58 -0400 Subject: [PATCH 2/3] Adding and enabling HEALTHCHECK --- chainquery/Dockerfile-linux-x86_64-production | 5 ++++- chainquery/stuff/healthcheck.sh | 3 +-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/chainquery/Dockerfile-linux-x86_64-production b/chainquery/Dockerfile-linux-x86_64-production index c280476..246ce78 100644 --- a/chainquery/Dockerfile-linux-x86_64-production +++ b/chainquery/Dockerfile-linux-x86_64-production @@ -9,6 +9,7 @@ RUN apt-get update && \ WORKDIR / SHELL ["/bin/bash", "-o", "pipefail", "-c"] COPY ./stuff/start.sh start +COPY ./stuff/healthcheck.sh healthcheck RUN curl -L -o /chainquery.zip $(curl -s https://api.github.com/repos/lbryio/chainquery/releases | grep -F 'Linux_x86_64.zip' | grep download | head -n 1 | cut -d'"' -f4) && \ unzip /chainquery.zip && \ rm /chainquery.zip @@ -17,7 +18,9 @@ FROM ubuntu:18.04 as app ADD https://raw.githubusercontent.com/lbryio/chainquery/master/config/default/chainqueryconfig.toml /etc/lbry/chainqueryconfig.toml.orig RUN adduser chainquery --gecos GECOS --shell /bin/bash --disabled-password --home /home/chainquery && \ chown -R chainquery:chainquery /etc/lbry -COPY --from=prep /chainquery /start /usr/bin/ +COPY --from=prep ./healthcheck /chainquery /start /usr/bin/ +HEALTHCHECK --interval=1m --timeout=30s \ + CMD healthcheck EXPOSE 6300 USER chainquery STOPSIGNAL SIGINT diff --git a/chainquery/stuff/healthcheck.sh b/chainquery/stuff/healthcheck.sh index 24cd27b..7584e38 100644 --- a/chainquery/stuff/healthcheck.sh +++ b/chainquery/stuff/healthcheck.sh @@ -1,3 +1,2 @@ #!/usr/bin/env bash -## TODO: Implement this at some point it requires CURL in the container. -curl http://localhost:6300/api/status +curl --fail http://localhost:6300/api/status || exit 1 -- 2.45.2 From d5a758383449b8d93ef2dab98504eecd57f90287 Mon Sep 17 00:00:00 2001 From: Ryan McGuire Date: Tue, 30 Apr 2019 14:28:07 -0400 Subject: [PATCH 3/3] Creates a layered configuration for lbrycrd start.sh --- lbrycrd/README.md | 44 +++++++++++++++++++++++++++++++++++ lbrycrd/stuff/start.sh | 52 +++++++++++++++++++++++++++++++++--------- 2 files changed, 85 insertions(+), 11 deletions(-) diff --git a/lbrycrd/README.md b/lbrycrd/README.md index 3817626..999d354 100644 --- a/lbrycrd/README.md +++ b/lbrycrd/README.md @@ -2,3 +2,47 @@ # Docker image tags `lbry/lbrycrd` `[linux-x86_64-production](https://github.com/lbryio/lbry-docker/blob/master/lbrycrd/Dockerfile-linux-x86_64-production)` (Latest release) + + +## Configuration + +The lbrycrd container comes with a default configuration you can use for +production. Extra configuration is optional. + +The container includes a `start` script that offers a flexible configuration +style. It allows you to mount your own `lbrycrd.conf` file, or use environment +variables, or a mix of both. + +### Environment variables + +The environment variables override the values in the mounted config file. If no +mounted config file exists, these variables are used to create a fresh config. + + * `PORT` - The main lbrycrd port + * `RPC_USER` - The rpc user + * `RPC_PASSWORD` - The rpc user's password + * `RPC_ALLOW_IP` - the subnet that is allowed rpc access + * `RPC_PORT` - The port to bind the rpc service to + * `RPC_BIND` - The ip address to bind the rpc service to + + +### Example run commands + +Running the default configuration: + +``` +docker run --rm -it -e RUN_MODE=default lbry/lbrycrd:linux-x86_64-production +``` + +Running with RPC password changed: + +``` +docker run --rm -it -e RUN_MODE=default -e RPC_PASSWORD=hunter2 lbry/lbrycrd:linux-x86_64-production +``` + +Running with a config file but with the RPC password still overridden: + +``` +docker run --rm -it -v /path/to/lbrycrd.conf:/etc/lbry/lbrycrd.conf -e RUN_MODE=default -e RPC_PASSWORD=hunter2 lbry/lbrycrd:linux-x86_64-production +``` + diff --git a/lbrycrd/stuff/start.sh b/lbrycrd/stuff/start.sh index 158b160..342ca3c 100755 --- a/lbrycrd/stuff/start.sh +++ b/lbrycrd/stuff/start.sh @@ -1,24 +1,54 @@ #!/usr/bin/env bash CONFIG_PATH=/etc/lbry/lbrycrd.conf +function override_config_option() { + # Remove existing config line from a config file + # and replace with environment fed value. + # Does nothing if the variable does not exist. + # var Name of ENV variable + # option Name of config option + # config Path of config file + local var=$1 option=$2 config=$3 + if [[ -v $var ]]; then + # Remove the existing config option: + sed -i "/^$option\W*=/d" $config + # Add the value from the environment: + echo "$option=${!var}" >> $config + fi +} + function set_config() { - CONFIG_PATH=/etc/lbry/lbrycrd.conf - if [ -f "$CONFIG_PATH" ] - then - echo "Using the config file that was mounted into the container." + if [ -d "$CONFIG_PATH" ]; then + echo "$CONFIG_PATH is a directory when it should be a file." + exit 1 + elif [ -f "$CONFIG_PATH" ]; then + echo "Merging the mounted config file with environment variables." + local MERGED_CONFIG=/tmp/lbrycrd_merged.conf + cat $CONFIG_PATH > $MERGED_CONFIG + echo "" >> $MERGED_CONFIG + override_config_option PORT port $MERGED_CONFIG + override_config_option RPC_USER rpcuser $MERGED_CONFIG + override_config_option RPC_PASSWORD rpcpassword $MERGED_CONFIG + override_config_option RPC_ALLOW_IP rpcallowip $MERGED_CONFIG + override_config_option RPC_PORT rpcport $MERGED_CONFIG + override_config_option RPC_BIND rpcbind $MERGED_CONFIG + # Make the new merged config file the new CONFIG_PATH + # This ensures that the original file the user mounted remains unmodified + CONFIG_PATH=$MERGED_CONFIG else echo "Creating a fresh config file from environment variables." ## Set config params - echo "rpcuser=$RPC_USER" > $CONFIG_PATH - echo "rpcpassword=$RPC_PASSWORD" >> $CONFIG_PATH - echo "rpcallowip=$RPC_ALLOW_IP" >> $CONFIG_PATH - echo "rpcport=9245" >> $CONFIG_PATH - echo "rpcbind=0.0.0.0" >> $CONFIG_PATH - #echo "bind=0.0.0.0" >> $CONFIG_PATH + echo "port=${PORT=9246}" > $CONFIG_PATH + echo "rpcuser=${RPC_USER=lbry}" >> $CONFIG_PATH + echo "rpcpassword=${RPC_PASSWORD=lbry}" >> $CONFIG_PATH + echo "rpcallowip=${RPC_ALLOW_IP=127.0.0.1/24}" >> $CONFIG_PATH + echo "rpcport=${RPC_PORT=9245}" >> $CONFIG_PATH + echo "rpcbind=${RPC_BIND=0.0.0.0}" >> $CONFIG_PATH fi + echo "Config: " + cat $CONFIG_PATH } - ## Ensure perms are correct prior to running main binary /usr/bin/fix-permissions -- 2.45.2