Rewrite chainquery start script merge env with defaults
This commit is contained in:
parent
5f402ebc7a
commit
e6eb37aefa
1 changed files with 22 additions and 43 deletions
|
@ -1,51 +1,30 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
## Config setup
|
||||
# Override defaults with environment variables
|
||||
CONFIGFILE="${CONFIGFILE:-/etc/lbry/chainqueryconfig.toml}"
|
||||
DEBUGMODE="${DEBUGMODE:-false}"
|
||||
RPC_USER="${RPC_USER:-lbry}"
|
||||
RPC_PASSWORD="${RPC_PASSWORD:-lbry}"
|
||||
RPC_HOST="${RPC_HOST:-localhost}"
|
||||
MYSQL_SERVER="${MYSQL_SERVER:-localhost}"
|
||||
MYSQL_USER="${MYSQL_USER:-lbry}"
|
||||
MYSQL_PASSWORD="${MYSQL_PASSWORD:-lbry}"
|
||||
MYSQL_DATABASE="${MYSQL_DATABASE:-chainquery}"
|
||||
|
||||
## Setup Values
|
||||
DEBUGMODE=$(echo "debugmode=$DEBUGMODE")
|
||||
LBRYCRDURL=$(echo "lbrycrdurl=\"rpc://$RPC_USER:$RPC_PASSWORD@10.5.1.2:9245\"")
|
||||
MYSQLDSN=$(echo "mysqldsn=\"$MYSQL_USER:$MYSQL_PASSWORD@tcp($MYSQL_SERVER:3306)/$MYSQL_DATABASE\"")
|
||||
APIMYSQLDSN=$(echo "apimysqldsn=\"$MYSQL_USER:$MYSQL_PASSWORD@tcp($MYSQL_SERVER:3306)/$MYSQL_DATABASE\"")
|
||||
|
||||
## Setup Defaults
|
||||
DEBUGMODE_DEFAULT='#DEFAULT-debugmode=false'
|
||||
LBRYCRDURL_DEFAULT='#DEFAULT-lbrycrdurl="rpc://lbry:lbry@localhost:9245"'
|
||||
MYSQLDSN_DEFAULT='#DEFAULT-mysqldsn="lbry:lbry@tcp(localhost:3306)/chainquery"'
|
||||
APIMYSQLDSN_DEFAULT='#DEFAULT-apimysqldsn="lbry:lbry@tcp(localhost:3306)/chainquery"'
|
||||
|
||||
## Add setup value variable name to this list to get processed on container start
|
||||
CONFIG_SETTINGS=(
|
||||
DEBUGMODE
|
||||
LBRYCRDURL
|
||||
MYSQLDSN
|
||||
APIMYSQLDSN
|
||||
)
|
||||
|
||||
function set_configs() {
|
||||
## Set configs on container start if not already set.
|
||||
for i in "${!CONFIG_SETTINGS[@]}"; do
|
||||
## Indirect references http://tldp.org/LDP/abs/html/ivr.html
|
||||
eval FROM_STRING=\$"${CONFIG_SETTINGS[$i]}_DEFAULT"
|
||||
eval TO_STRING=\$${CONFIG_SETTINGS[$i]}
|
||||
## TODO: Add a bit more magic to make sure that you're only configuring things if not set by config mounts.
|
||||
sed -i "s~$FROM_STRING~"$TO_STRING"~g" /etc/lbry/chainqueryconfig.toml
|
||||
done
|
||||
echo "Reading config for debugging."
|
||||
cat /etc/lbry/chainqueryconfig.toml
|
||||
exec_chainquery() {
|
||||
CONFIG_DIR=$(dirname "${CONFIGFILE}")
|
||||
exec chainquery serve --configpath "$CONFIG_DIR"
|
||||
}
|
||||
|
||||
if [[ ! -f /etc/lbry/chainqueryconfig.toml ]]; then
|
||||
echo "[INFO]: Did not find chainqueryconfig.toml"
|
||||
echo " Installing default and configuring with provided environment variables if any."
|
||||
## Install fresh copy of config file.
|
||||
echo "cp -v /etc/lbry/chainqueryconfig.toml.orig /etc/lbry/chainqueryconfig.toml"
|
||||
cp -v /etc/lbry/chainqueryconfig.toml.orig /etc/lbry/chainqueryconfig.toml
|
||||
ls -lAh /etc/lbry/
|
||||
set_configs
|
||||
else
|
||||
if [[ -f "$CONFIGFILE" ]]; then
|
||||
echo "[INFO]: Found a copy of chainqueryconfig.toml in /etc/lbry"
|
||||
exec_chainquery
|
||||
fi
|
||||
|
||||
## For now keeping this simple. Potentially eventually add all command args as envvars for the Dockerfile or use safe way to add args via docker-compose.yml
|
||||
chainquery serve --configpath "/etc/lbry/"
|
||||
cat << EOF >> "${CONFIGFILE}"
|
||||
DEBUGMODE="${DEBUGMODE}"
|
||||
LBRYCRDURL="rpc://${RPC_USER}:${RPC_PASSWORD}@${RPC_HOST}:9245"
|
||||
MYSQLDSN="${MYSQL_USER}:${MYSQL_PASSWORD}@tcp(${MYSQL_SERVER}:3306)/$MYSQL_DATABASE"
|
||||
APIMYSQLDSN="${MYSQL_USER}:${MYSQL_PASSWORD}@tcp(${MYSQL_SERVER}:3306)/$MYSQL_DATABASE"
|
||||
EOF
|
||||
exec_chainquery
|
||||
|
|
Loading…
Reference in a new issue