Improve app to db connection setup (#332)
This commit is contained in:
parent
3ff54bc90f
commit
68db80f759
@ -13,7 +13,7 @@ install:
|
||||
|
||||
env:
|
||||
- BUILD="mkdir -p ./volumes/app/mattermost/{data,logs,config,plugins} && docker-compose up -d"
|
||||
- BUILD="docker run -d --name db -e POSTGRES_USER=mmuser -e POSTGRES_PASSWORD=mmuser_password -e POSTGRES_DB=mattermost mattermost-prod-db && sleep 5 && docker run -d --link db -p 80:8000 --name app mattermost-prod-app"
|
||||
- BUILD="docker run -d --name db -e POSTGRES_USER=mmuser -e POSTGRES_PASSWORD=mmuser_password -e POSTGRES_DB=mattermost mattermost-prod-db && sleep 5 && docker run -d --link db -p 80:8000 --name app -e MM_USERNAME=mmuser -e MM_PASSWORD=mmuser_password mattermost-prod-app"
|
||||
|
||||
script:
|
||||
- curl -sSf http://localhost > /dev/null
|
||||
|
@ -8,8 +8,6 @@ generate_salt() {
|
||||
# Read environment variables or set default values
|
||||
DB_HOST=${DB_HOST:-db}
|
||||
DB_PORT_NUMBER=${DB_PORT_NUMBER:-5432}
|
||||
MM_USERNAME=${MM_USERNAME:-mmuser}
|
||||
MM_PASSWORD=${MM_PASSWORD:-mmuser_password}
|
||||
MM_DBNAME=${MM_DBNAME:-mattermost}
|
||||
MM_CONFIG=${MM_CONFIG:-/mattermost/config/config.json}
|
||||
|
||||
@ -51,22 +49,22 @@ if [ "$1" = 'mattermost' ]; then
|
||||
jq '.SqlSettings.DriverName = "postgres"' $MM_CONFIG > $MM_CONFIG.tmp && mv $MM_CONFIG.tmp $MM_CONFIG
|
||||
jq '.SqlSettings.AtRestEncryptKey = "'$(generate_salt)'"' $MM_CONFIG > $MM_CONFIG.tmp && mv $MM_CONFIG.tmp $MM_CONFIG
|
||||
jq '.PluginSettings.Directory = "/mattermost/plugins/"' $MM_CONFIG > $MM_CONFIG.tmp && mv $MM_CONFIG.tmp $MM_CONFIG
|
||||
|
||||
# Configure database access
|
||||
if [[ -z "$MM_SQLSETTINGS_DATASOURCE" ]]
|
||||
then
|
||||
echo -ne "Configure database connection..."
|
||||
# URLEncode the password, allowing for special characters
|
||||
ENCODED_PASSWORD=$(printf %s $MM_PASSWORD | jq -s -R -r @uri)
|
||||
export MM_SQLSETTINGS_DATASOURCE="postgres://$MM_USERNAME:$ENCODED_PASSWORD@$DB_HOST:$DB_PORT_NUMBER/$MM_DBNAME?sslmode=disable&connect_timeout=10"
|
||||
echo OK
|
||||
else
|
||||
echo "Using existing database connection"
|
||||
fi
|
||||
else
|
||||
echo "Using existing config file" $MM_CONFIG
|
||||
fi
|
||||
|
||||
# Configure database access
|
||||
if [[ -z "$MM_SQLSETTINGS_DATASOURCE" && ! -z "$MM_USERNAME" && ! -z "$MM_PASSWORD" ]]
|
||||
then
|
||||
echo -ne "Configure database connection..."
|
||||
# URLEncode the password, allowing for special characters
|
||||
ENCODED_PASSWORD=$(printf %s $MM_PASSWORD | jq -s -R -r @uri)
|
||||
export MM_SQLSETTINGS_DATASOURCE="postgres://$MM_USERNAME:$ENCODED_PASSWORD@$DB_HOST:$DB_PORT_NUMBER/$MM_DBNAME?sslmode=disable&connect_timeout=10"
|
||||
echo OK
|
||||
else
|
||||
echo "Using existing database connection"
|
||||
fi
|
||||
|
||||
# Wait another second for the database to be properly started.
|
||||
# Necessary to avoid "panic: Failed to open sql connection pq: the database system is starting up"
|
||||
sleep 1
|
||||
|
Reference in New Issue
Block a user