Skip to content

Commit

Permalink
Environment variable to set database port (CO-2153)
Browse files Browse the repository at this point in the history
  • Loading branch information
skoranda committed Aug 6, 2021
1 parent 228751f commit fa51250
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 12 deletions.
50 changes: 38 additions & 12 deletions comanage-registry-base/comanage_utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ function comanage_utils::consume_injected_environment() {
COMANAGE_REGISTRY_DATASOURCE
COMANAGE_REGISTRY_DATABASE
COMANAGE_REGISTRY_DATABASE_HOST
COMANAGE_REGISTRY_DATABASE_PORT
COMANAGE_REGISTRY_DATABASE_USER
COMANAGE_REGISTRY_DATABASE_USER_PASSWORD
COMANAGE_REGISTRY_EMAIL_FROM
Expand Down Expand Up @@ -362,6 +363,7 @@ function comanage_utils::manage_tier_environment() {
# Globals:
# COMANAGE_REGISTRY_DATABASE
# COMANAGE_REGISTRY_DATABASE_HOST
# COMANAGE_REGISTRY_DATABASE_PORT
# COMANAGE_REGISTRY_DATABASE_USER
# COMANAGE_REGISTRY_DATABASE_USER_PASSWORD
# COMANAGE_REGISTRY_DATASOURCE
Expand All @@ -380,26 +382,50 @@ function comanage_utils::prepare_database_config() {
local database_config
database_config="$COMANAGE_REGISTRY_DIR/local/Config/database.php"

if [[ ! -e "$database_config" ]]; then
cat > "$database_config" <<EOF
# File already exists so return.
if [[ -e "$database_config" ]]; then
return
fi

# File does not exist so create it.
local php_string

read -r -d '' php_string <<'EOF'
<?php
class DATABASE_CONFIG {
public \$default = array(
'datasource' => '${COMANAGE_REGISTRY_DATASOURCE:-Database/Postgres}',
public $default = array(
'persistent' => false,
'host' => '${COMANAGE_REGISTRY_DATABASE_HOST:-comanage-registry-database}',
'login' => '${COMANAGE_REGISTRY_DATABASE_USER:-registry_user}',
'password' => '${COMANAGE_REGISTRY_DATABASE_USER_PASSWORD:-password}',
'database' => '${COMANAGE_REGISTRY_DATABASE:-registry}',
'prefix' => 'cm_',
);
}
EOF
echo "Wrote new database configuration file ${database_config}" > "$OUTPUT"

php_string+=$'\n '
php_string+="'datasource' => '${COMANAGE_REGISTRY_DATASOURCE:-Database/Postgres}',"

php_string+=$'\n '
php_string+="'host' => '${COMANAGE_REGISTRY_DATABASE_HOST:-comanage-registry-database}',"

php_string+=$'\n '
php_string+="'login' => '${COMANAGE_REGISTRY_DATABASE_USER:-registry_user}',"

php_string+=$'\n '
php_string+="'password' => '${COMANAGE_REGISTRY_DATABASE_USER_PASSWORD:-password}',"

php_string+=$'\n '
php_string+="'database' => '${COMANAGE_REGISTRY_DATABASE:-registry}',"

# The value of port is an integer.
if [[ -n "${COMANAGE_REGISTRY_DATABASE_PORT}" ]]; then
php_string+=$'\n '
php_string+="'port' => ${COMANAGE_REGISTRY_DATABASE_PORT},"
fi

php_string+=$'\n );\n}\n';

printf "%s" "$php_string" > $database_config

echo "Wrote new database configuration file ${database_config}" > "$OUTPUT"
}

##########################################
Expand Down
8 changes: 8 additions & 0 deletions docs/comanage-registry-common-environment-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ provided that the file it points to exists and is readable.
* Example: database-server.my.org
* Note: \[[2](#note02)\]

```COMANAGE_REGISTRY_DATABASE_PORT```

* Description: database server port
* Required: no
* Default: unset
* Example: 5433
* Note: \[[2](#note02)\]

```COMANAGE_REGISTRY_DATABASE_USER```

* Description: database username
Expand Down

0 comments on commit fa51250

Please sign in to comment.