Commit 0cb0f3c1 authored by Thong Kuah's avatar Thong Kuah

Process $DB_INITIALIZE and $DB_MIGRATE variables

if $DB_INITIALIZE is present, deploy an initial release
where only $DB_INITIALIZE is run in a special job (and deployments are
not rendered/loaded). This is then followed by second release with
deployments as usual.

if $DB_MIGRATE, set this value which will trigger a pre-upgrade helm
hook.
parent 4ac62282
---
title: Support db migration and initialization for Auto DevOps
merge_request: 21955
author:
type: added
...@@ -587,26 +587,59 @@ rollout 100%: ...@@ -587,26 +587,59 @@ rollout 100%:
secret_name='' secret_name=''
fi fi
helm upgrade --install \ if [[ -n "$DB_INITIALIZE" && -z "$(helm ls -q "^$name$")" ]]; then
--wait \ helm upgrade --install \
--set service.enabled="$service_enabled" \ --wait \
--set releaseOverride="$CI_ENVIRONMENT_SLUG" \ --set service.enabled="$service_enabled" \
--set image.repository="$CI_APPLICATION_REPOSITORY" \ --set releaseOverride="$CI_ENVIRONMENT_SLUG" \
--set image.tag="$CI_APPLICATION_TAG" \ --set image.repository="$CI_APPLICATION_REPOSITORY" \
--set image.pullPolicy=IfNotPresent \ --set image.tag="$CI_APPLICATION_TAG" \
--set image.secrets[0].name="$secret_name" \ --set image.pullPolicy=IfNotPresent \
--set application.track="$track" \ --set image.secrets[0].name="$secret_name" \
--set application.database_url="$DATABASE_URL" \ --set application.track="$track" \
--set service.url="$CI_ENVIRONMENT_URL" \ --set application.database_url="$DATABASE_URL" \
--set replicaCount="$replicas" \ --set service.url="$CI_ENVIRONMENT_URL" \
--set postgresql.enabled="$postgres_enabled" \ --set replicaCount="$replicas" \
--set postgresql.nameOverride="postgres" \ --set postgresql.enabled="$postgres_enabled" \
--set postgresql.postgresUser="$POSTGRES_USER" \ --set postgresql.nameOverride="postgres" \
--set postgresql.postgresPassword="$POSTGRES_PASSWORD" \ --set postgresql.postgresUser="$POSTGRES_USER" \
--set postgresql.postgresDatabase="$POSTGRES_DB" \ --set postgresql.postgresPassword="$POSTGRES_PASSWORD" \
--namespace="$KUBE_NAMESPACE" \ --set postgresql.postgresDatabase="$POSTGRES_DB" \
"$name" \ --set application.initializeCommand="$DB_INITIALIZE" \
chart/ --namespace="$KUBE_NAMESPACE" \
"$name" \
chart/
helm upgrade --reuse-values \
--wait \
--set application.initializeCommand="" \
--set application.migrateCommand="$DB_MIGRATE" \
--namespace="$KUBE_NAMESPACE" \
"$name" \
chart/
else
helm upgrade --install \
--wait \
--set service.enabled="$service_enabled" \
--set releaseOverride="$CI_ENVIRONMENT_SLUG" \
--set image.repository="$CI_APPLICATION_REPOSITORY" \
--set image.tag="$CI_APPLICATION_TAG" \
--set image.pullPolicy=IfNotPresent \
--set image.secrets[0].name="$secret_name" \
--set application.track="$track" \
--set application.database_url="$DATABASE_URL" \
--set service.url="$CI_ENVIRONMENT_URL" \
--set replicaCount="$replicas" \
--set postgresql.enabled="$postgres_enabled" \
--set postgresql.nameOverride="postgres" \
--set postgresql.postgresUser="$POSTGRES_USER" \
--set postgresql.postgresPassword="$POSTGRES_PASSWORD" \
--set postgresql.postgresDatabase="$POSTGRES_DB" \
--set application.migrateCommand="$DB_MIGRATE" \
--namespace="$KUBE_NAMESPACE" \
"$name" \
chart/
fi
kubectl rollout status -n "$KUBE_NAMESPACE" -w "deployment/$name" kubectl rollout status -n "$KUBE_NAMESPACE" -w "deployment/$name"
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment