22
33set -e
44
5- [[ " $TRACE " ]] && set -x
5+ [[ " ${TRACE} " ]] &&
6+ set -x
67
78export AUTO_DEPLOY_ENVIRONMENT_VALUES_FILE=/tmp/auto-deploy-environment-values.yaml
8- export RELEASE_NAME=${HELM_RELEASE_NAME:- $CI_ENVIRONMENT_SLUG }
9+ export RELEASE_NAME=${HELM_RELEASE_NAME:- ${ CI_ENVIRONMENT_SLUG} }
910
1011export POSTGRESQL_VERSION=${POSTGRESQL_VERSION:- " 11.10.0" }
1112export REDIS_VERSION=${REDIS_VERSION:- " 6.0.9" }
@@ -25,6 +26,10 @@ for i in "${APPS[@]}"; do
2526 source <(
2627 cat << EOF
2728 export ${i^^} _RELEASE_NAME="${RELEASE_NAME} -${i} ";
29+ export ${i^^} _DB="\$ {${i^^} _DB:-${RELEASE_NAME} }"
30+ export ${i^^} _USER="\$ {${i^^} _USER:-${RELEASE_NAME} }"
31+ export ${i^^} _PASSWORD="\$ {${i^^} _PASSWORD:-${RELEASE_NAME} }"
32+ export ${i^^} _ROOT_PASSWORD="\$ {${i^^} _ROOT_PASSWORD:-${RELEASE_NAME} }"
2833EOF
2934 )
3035done
@@ -111,7 +116,8 @@ function add_custom_chart_repository() {
111116}
112117
113118function ensure_namespace() {
114- kubectl get namespace " ${KUBE_NAMESPACE} " || kubectl create namespace " ${KUBE_NAMESPACE} "
119+ kubectl get namespace " ${KUBE_NAMESPACE} " ||
120+ kubectl create namespace " ${KUBE_NAMESPACE} "
115121}
116122
117123function write_environment_values_file() {
@@ -160,11 +166,11 @@ function persist_environment_url() {
160166
161167function auto_database_uri() {
162168
163- # this function gets called for a DB only if DB_ENABLED is true
169+ # this function gets called for a DB only if * DB_ENABLED is true
164170
165- # if DB_ENABLED is true & DB_URI is set by user
171+ # if * DB_ENABLED is true & * DB_URI is set by user
166172 # then we will provision the DB
167- # but DB_URI will still contain the value set by user
173+ # but * DB_URI will still contain the value set by user
168174
169175 db=${1}
170176 case " ${db} " in
@@ -206,40 +212,31 @@ function install_app() {
206212 fi
207213
208214 if [[ " ${MARIADB_ENABLED} " == " true" ]]; then
209-
210- yq eval --null-input ' .auth.database= env(MARIADB_DB)' > mariadb-specific-values.yaml
215+ yq eval --null-input ' .auth.database = env(MARIADB_DB)' > mariadb-specific-values.yaml
211216 yq eval ' .auth.username = env(MARIADB_USER)' -i mariadb-specific-values.yaml
212217 yq eval ' .auth.password = env(MARIADB_PASSWORD)' -i mariadb-specific-values.yaml
213218 yq eval ' .auth.rootPassword = env(MARIADB_ROOT_PASSWORD)' -i mariadb-specific-values.yaml
214-
215- # metrics.enabled: true
216- # rbac.create=true
217- # architecture: replication
218- # secondary.replicaCount: 2
219- # auth.forcePassword: true
220- # auth.usePasswordFiles: true
221219 fi
222220 if [[ " ${MYSQL_ENABLED} " == " true" ]]; then
223- yq eval --null-input ' .auth.database= env(MYSQL_DB)' > mysql-specific-values.yaml
221+ yq eval --null-input ' .auth.database = env(MYSQL_DB)' > mysql-specific-values.yaml
224222 yq eval ' .auth.username = env(MYSQL_USER)' -i mysql-specific-values.yaml
225223 yq eval ' .auth.password = env(MYSQL_PASSWORD)' -i mysql-specific-values.yaml
226224 yq eval ' .auth.rootPassword = env(MYSQL_ROOT_PASSWORD)' -i mysql-specific-values.yaml
227225 fi
228-
226+ if [[ " ${REDIS_ENABLED} " == " true" ]]; then
227+ yq eval --null-input ' .password = env(REDIS_PASSWORD)' > redis-specific-values.yaml
228+ fi
229+ if [[ " ${MONGODB_ENABLED} " == " true" ]]; then
230+ yq eval --null-input ' .auth.database = env(MONGODB_DB)' > mongodb-specific-values.yaml
231+ yq eval ' .auth.username = env(MONGODB_USER)' -i mongodb-specific-values.yaml
232+ yq eval ' .auth.password = env(MONGODB_PASSWORD)' -i mongodb-specific-values.yaml
233+ yq eval ' .auth.rootPassword = env(MONGODB_ROOT_PASSWORD)' -i mongodb-specific-values.yaml
234+ fi
229235 if [[ " ${POSTGRESQL_ENABLED} " == " true" ]]; then
230-
231236 yq eval --null-input ' .postgresqlDatabase = env(POSTGRESQL_DB)' > postgresql-specific-values.yaml
232237 yq eval ' .postgresqlUsername = env(POSTGRESQL_USER)' -i postgresql-specific-values.yaml
233238 yq eval ' .postgresqlPassword = env(POSTGRESQL_PASSWORD)' -i postgresql-specific-values.yaml
234239 yq eval ' .postgresqlPostgresPassword = env(POSTGRESQL_ROOT_PASSWORD)' -i postgresql-specific-values.yaml
235-
236- # metrics.enabled
237- # rbac.create
238- # replication.enabled: true
239- # replication.readReplicas: 2
240- # replication.synchronousCommit: "on"
241- # replication.numSynchronousReplicas: 1
242- # usePasswordFile
243240 fi
244241
245242 # shellcheck disable=SC1090
@@ -261,10 +258,8 @@ function install_app() {
261258 --wait \
262259 --version "\$ {${i^^} _CHART_VERSION}" \
263260 --set fullnameOverride="$name " \
264- --set ${i} Username="\$ {${i^^} _USER}" \
265- --set ${i} Password="\$ {${i^^} _PASSWORD}" \
266- --set ${i} Database="\$ {${i^^} _DB}" \
267261 --set image.tag="\$ {${i^^} _VERSION}" \
262+ --values "${i} -specific-values.yaml" \
268263 "\$ {${i} _helm_values_args[@]}" \
269264 \$ {${i^^} _HELM_UPGRADE_EXTRA_ARGS} \
270265 --namespace="${KUBE_NAMESPACE} " \
@@ -309,13 +304,13 @@ EOF
309304 ${i} _uri=$( auto_database_uri " ${i} " )
310305 export ${i} _uri;
311306 elif [[ -v ${i^^} _URI ]]; then
312- # if DB_URI is passed by user then set it in pod
307+ # if * DB_URI is passed by user then set it in pod
313308 ${i} _uri=\$ {${i^^} _URI}
314309 export ${i} _uri;
315310 fi
316- # if DB_ENABLED is true & DB_URI is set by user
311+ # if * DB_ENABLED is true & * DB_URI is set by user
317312 # then we will provision the DB
318- # but DB_URI will still contain the value set by user
313+ # but * DB_URI will still contain the value set by user
319314EOF
320315 )
321316 done
0 commit comments