Merge pull request #8 from xcompass/configurable-params

Allow db host, name user and password to be configurable
This commit is contained in:
Yi EungJun 2016-04-17 18:47:07 +09:00
commit 6918117793
3 changed files with 22 additions and 7 deletions

View File

@ -23,7 +23,7 @@
},
"SqlSettings": {
"DriverName": "postgres",
"DataSource": "postgres://mmuser:mmuser_password@db:DB_PORT/mattermost?sslmode=disable&connect_timeout=10",
"DataSource": "postgres://MM_USERNAME:MM_PASSWORD@DB_HOST:DB_PORT/MM_DBNAME?sslmode=disable&connect_timeout=10",
"DataSourceReplicas": [],
"MaxIdleConns": 10,
"MaxOpenConns": 10,

View File

@ -1,17 +1,26 @@
#!/bin/bash
config=/mattermost/config/config.json
DB_HOST=${DB_HOST:-db}
DB_PORT_5432_TCP_PORT=${DB_PORT_5432_TCP_PORT:-5432}
MM_USERNAME=${MM_USERNAME:-mmuser}
MM_PASSWORD=${MM_PASSWORD:-mmuser_password}
MM_DBNAME=${MM_DBNAME:-mattermost}
echo -ne "Configure database connection..."
if [ ! -f $config ]
then
cp /config.template.json $config
sed -Ei "s/DB_HOST/$DB_HOST/" $config
sed -Ei "s/DB_PORT/$DB_PORT_5432_TCP_PORT/" $config
sed -Ei "s/MM_USERNAME/$MM_USERNAME/" $config
sed -Ei "s/MM_PASSWORD/$MM_PASSWORD/" $config
sed -Ei "s/MM_DBNAME/$MM_DBNAME/" $config
echo OK
else
echo SKIP
fi
echo "Wait until database is ready..."
until nc -z db $DB_PORT_5432_TCP_PORT
until nc -z $DB_HOST $DB_PORT_5432_TCP_PORT
do
sleep 1
done

View File

@ -1,6 +1,12 @@
export PGUSER=postgres
psql <<- EOSQL
CREATE DATABASE mattermost;
CREATE USER mmuser WITH PASSWORD 'mmuser_password';
GRANT ALL PRIVILEGES ON DATABASE mattermost to mmuser;
#!/bin/bash
set -e
MM_USERNAME=${MM_USERNAME:-mmuser}
MM_PASSWORD=${MM_PASSWORD:-mmuser_password}
MM_DBNAME=${MM_DBNAME:-mattermost}
psql -v ON_ERROR_STOP=1 --username "postgres" <<- EOSQL
CREATE DATABASE $MM_DBNAME;
CREATE USER $MM_USERNAME WITH PASSWORD '$MM_PASSWORD';
GRANT ALL PRIVILEGES ON DATABASE $MM_DBNAME to $MM_USERNAME;
EOSQL