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.
This commit is contained in:
parent
4ac62282c4
commit
0cb0f3c125
2 changed files with 58 additions and 20 deletions
5
changelogs/unreleased/48004-db-initialize-migrate.yml
Normal file
5
changelogs/unreleased/48004-db-initialize-migrate.yml
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
title: Support db migration and initialization for Auto DevOps
|
||||
merge_request: 21955
|
||||
author:
|
||||
type: added
|
|
@ -587,6 +587,7 @@ rollout 100%:
|
|||
secret_name=''
|
||||
fi
|
||||
|
||||
if [[ -n "$DB_INITIALIZE" && -z "$(helm ls -q "^$name$")" ]]; then
|
||||
helm upgrade --install \
|
||||
--wait \
|
||||
--set service.enabled="$service_enabled" \
|
||||
|
@ -604,10 +605,42 @@ rollout 100%:
|
|||
--set postgresql.postgresUser="$POSTGRES_USER" \
|
||||
--set postgresql.postgresPassword="$POSTGRES_PASSWORD" \
|
||||
--set postgresql.postgresDatabase="$POSTGRES_DB" \
|
||||
--set application.initializeCommand="$DB_INITIALIZE" \
|
||||
--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"
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue