From 031858fbae662a6841052072e97acb74c0da8e36 Mon Sep 17 00:00:00 2001 From: Pan Luo Date: Fri, 15 Apr 2016 21:04:33 -0700 Subject: [PATCH] Allow db host, name user and password to be configurable --- app/config.template.json | 2 +- app/docker-entry.sh | 11 ++++++++++- db/make_db.sh | 16 +++++++++++----- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/app/config.template.json b/app/config.template.json index 7f5e90c..70af3ec 100644 --- a/app/config.template.json +++ b/app/config.template.json @@ -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, diff --git a/app/docker-entry.sh b/app/docker-entry.sh index 44179a6..2a35b63 100644 --- a/app/docker-entry.sh +++ b/app/docker-entry.sh @@ -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 diff --git a/db/make_db.sh b/db/make_db.sh index 0b749ad..b105960 100644 --- a/db/make_db.sh +++ b/db/make_db.sh @@ -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