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