-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathdeploy-argocd-apps.sh
executable file
·79 lines (69 loc) · 2.26 KB
/
deploy-argocd-apps.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/bash -e
set -ex
if [ "$#" -ne 1 ] || ([ "$1" != "production" ] && [ "$1" != "staging" ] ); then
echo "Usage: $0 <staging/production>" >&2
exit 1
fi
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
main() {
verify_permissions || exit $?
verify_pvc_binding
deploy_apps "$1"
}
verify_permissions() {
if [ "$(kubectl auth can-i '*' '*' --all-namespaces)" != "yes" ]; then
echo
echo "[ERROR] User '$(oc whoami)' does not have the required 'cluster-admin' role." 1>&2
echo "Log into the cluster with a user with the required privileges (e.g. kubeadmin) and retry."
return 1
fi
}
verify_pvc_binding(){
local pvc_resources="${ROOT}/argo-cd-apps/dependencies/pre-deployment-pvc-binding"
echo "Creating PVC from '$pvc_resources' using the cluster's default storage class"
kubectl apply -k "$pvc_resources"
echo "PVC binding successfull"
}
deploy_tekton_secret() {
if ! kubectl get secret tekton-results-postgres -n tekton-pipelines; then
local db_password
db_password="$(openssl rand -base64 20)"
kubectl create secret generic tekton-results-postgres \
--namespace="tekton-pipelines" \
--from-literal=POSTGRES_USER=postgres \
--from-literal=POSTGRES_PASSWORD="$db_password"
fi
}
deploy_keycloak_secret() {
if ! kubectl get secret keycloak-db-secret -n keycloak; then
local db_password
db_password="$(openssl rand -base64 20)"
kubectl create secret generic keycloak-db-secret \
--namespace=keycloak \
--from-literal=POSTGRES_USER=postgres \
--from-literal=POSTGRES_PASSWORD="$db_password"
fi
}
check_namespace() {
kubectl get namespace "$1" &>/dev/null
return $?
}
deploy_apps() {
environment=$(echo "$1")
echo "Deploying applications"
kubectl apply -k "${ROOT}/argo-cd-apps/app-of-app-sets/${environment}"
while true; do
if check_namespace "tekton-pipelines" && check_namespace "keycloak"; then
deploy_tekton_secret
deploy_keycloak_secret
break
else
echo -n .
sleep 1
fi
done
echo "Applications deployed"
}
if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then
main "$@"
fi