Commit df6354b8 authored by Thong Kuah's avatar Thong Kuah

DRY up some functions in Auto-DevOps script

- DRY up setting deploy name

- DRY up application_secret_name
parent 1d41e587
...@@ -607,6 +607,9 @@ rollout 100%: ...@@ -607,6 +607,9 @@ rollout 100%:
# A: dmFsdWUxCg== # A: dmFsdWUxCg==
# B: bXVsdGkgd29yZCB2YWx1ZQo= # B: bXVsdGkgd29yZCB2YWx1ZQo=
function create_application_secret() { function create_application_secret() {
track="${1-stable}"
export APPLICATION_SECRET_NAME=$(application_secret_name "$track")
bash -c ' bash -c '
function k8s_prefixed_variables() { function k8s_prefixed_variables() {
env | sed -n "s/^K8S_SECRET_\(.*\)$/\1/p" env | sed -n "s/^K8S_SECRET_\(.*\)$/\1/p"
...@@ -619,10 +622,28 @@ rollout 100%: ...@@ -619,10 +622,28 @@ rollout 100%:
' '
} }
function deploy_name() {
name="$CI_ENVIRONMENT_SLUG"
track="${1-stable}"
if [[ "$track" != "stable" ]]; then
name="$name-$track"
fi
echo $name
}
function application_secret_name() {
track="${1-stable}"
name=$(deploy_name "$track")
echo "${name}-secret"
}
function deploy() { function deploy() {
track="${1-stable}" track="${1-stable}"
percentage="${2:-100}" percentage="${2:-100}"
name="$CI_ENVIRONMENT_SLUG" name=$(deploy_name "$track")
replicas="1" replicas="1"
service_enabled="true" service_enabled="true"
...@@ -631,7 +652,6 @@ rollout 100%: ...@@ -631,7 +652,6 @@ rollout 100%:
# if track is different than stable, # if track is different than stable,
# re-use all attached resources # re-use all attached resources
if [[ "$track" != "stable" ]]; then if [[ "$track" != "stable" ]]; then
name="$name-$track"
service_enabled="false" service_enabled="false"
postgres_enabled="false" postgres_enabled="false"
fi fi
...@@ -644,8 +664,7 @@ rollout 100%: ...@@ -644,8 +664,7 @@ rollout 100%:
secret_name='' secret_name=''
fi fi
export APPLICATION_SECRET_NAME="${name}-secret" create_application_secret "$track"
create_application_secret
if [[ -n "$DB_INITIALIZE" && -z "$(helm ls -q "^$name$")" ]]; then if [[ -n "$DB_INITIALIZE" && -z "$(helm ls -q "^$name$")" ]]; then
echo "Deploying first release with database initialization..." echo "Deploying first release with database initialization..."
...@@ -712,11 +731,7 @@ rollout 100%: ...@@ -712,11 +731,7 @@ rollout 100%:
function scale() { function scale() {
track="${1-stable}" track="${1-stable}"
percentage="${2-100}" percentage="${2-100}"
name="$CI_ENVIRONMENT_SLUG" name=$(deploy_name "$track")
if [[ "$track" != "stable" ]]; then
name="$name-$track"
fi
replicas=$(get_replicas "$track" "$percentage") replicas=$(get_replicas "$track" "$percentage")
...@@ -910,18 +925,14 @@ rollout 100%: ...@@ -910,18 +925,14 @@ rollout 100%:
function delete() { function delete() {
track="${1-stable}" track="${1-stable}"
name="$CI_ENVIRONMENT_SLUG" name=$(deploy_name "$track")
if [[ "$track" != "stable" ]]; then
name="$name-$track"
fi
if [[ -n "$(helm ls -q "^$name$")" ]]; then if [[ -n "$(helm ls -q "^$name$")" ]]; then
helm delete --purge "$name" helm delete --purge "$name"
fi fi
application_secret_name="${name}-secret" secret_name=$(application_secret_name "$track")
kubectl delete secret --ignore-not-found -n "$KUBE_NAMESPACE" "$application_secret_name" kubectl delete secret --ignore-not-found -n "$KUBE_NAMESPACE" "$secret_name"
} }
before_script: before_script:
......
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