2018-10-14 14:30:06 +02:00
#!/usr/bin/env bash
2018-10-03 19:39:28 +02:00
2018-11-12 03:11:09 +01:00
## Config setup
2018-11-05 04:42:35 +01:00
2018-11-12 03:11:09 +01:00
## Setup Values
DEBUGMODE = ${ DEBUGMODE :- false }
LBRYCRDURL = " rpc:// ${ RPC_USER :- lbryrpc } : ${ RPC_PASSWORD :- changeme } @10.5.1.2:9245 "
MYSQLDSN = " ${ MYSQL_USER :- changeme } : ${ MYSQL_PASSWORD :- changeme } @tcp( ${ MYSQL_SERVER :- 10 .5.1.10 } :3306)/ ${ MYSQL_DATABASE :- chainquery } "
APIMYSQLDSN = " ${ MYSQL_USER :- changeme } : ${ MYSQL_PASSWORD :- changeme } @tcp( ${ MYSQL_SERVER :- 10 .5.1.10 } :3306)/ ${ MYSQL_DATABASE :- chainquery } "
## Setup Defaults
DEBUGMODE_DEFAULT = '#DEFAULT-debugquerymode=false'
LBRYCRDURL_DEFAULT = '#DEFAULT-lbrycrdurl="rpc://lbry:lbry@localhost:9245"'
MYSQLDSN_EFAULT = '#DEFAULT-mysqldsn="lbry:lbry@tcp(localhost:3306)/chainquery"'
APIMYSQLDSN_DEFAULT = '#DEFAULT-apihostport="0.0.0.0:6300"'
## Add setup value variable name to this list to get processed on container start
CONFIG_SETTINGS = (
DEBUGMODE
LBRYCRDURL
MYSQLDSN_
APIMYSQLDSN
)
2018-11-12 03:14:36 +01:00
function set_configs( ) {
2018-11-12 03:11:09 +01:00
## Set configs on container start if not already set.
for i in " ${ !CONFIG_SETTINGS[@] } " ; do
echo ${ CONFIG_SETTINGS [ $i ] } "_KEY"
## 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/chainquery/chainqueryconfig.toml
done
}
if [ [ ! -f /etc/chainquery/chainqueryconfig.toml ] ] ; then
echo "[INFO]: Found no chainqueryconfig.toml"
echo " Installing default and configuring with provided environment variables if any."
2018-11-12 03:13:20 +01:00
## Install fresh copy of config file.
cp /etc/chainquery/chainqueryconfig.toml.orig /etc/chainquery/chainqueryconfig.toml
2018-11-12 03:11:09 +01:00
set_configs
else
echo "[INFO]: Found a copy of chainqueryconfig.toml in /etc/chainquery"
echo " Attempting to non destructively install any new environment configurations."
set_configs
fi
2018-11-05 04:42:35 +01:00
2018-10-03 19:39:28 +02:00
## 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
2018-11-05 04:42:35 +01:00
chainquery serve -c "/etc/chainquery/"