forked from nemonik/hands-on-DevOps-gen2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·115 lines (78 loc) · 3.15 KB
/
install.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/usr/bin/env bash
# Copyright (C) 2021 Michael Joseph Walsh - All Rights Reserved
# You may use, distribute and modify this code under the
# terms of the the license.
#
# You should have received a copy of the license with
# this file. If not, please email <mjwalsh@nemonik.com>
set -e
set -a
skip_encrypted_variables=true
. ../.env
gitlab_protocol="${gitlab_protocol,,}"
if [ "${gitlab_protocol}" == "https" ]; then
gitlab_entrypoint="websecure"
gitlab_tls="true"
gitlab_https="true"
else
gitlab_entrypoint="web"
gitlab_tls="false"
gitlab_https="false"
fi
db_key_base=`pwgen -Bsv1 64`
secret_key_base=`pwgen -Bsv1 64`
otp_key_base=`pwgen -Bsv1 64`
is_current_context_correct
is_cluster_running
images_into_registry gitlab_images
template_file ./templates/gitlab-chart-values.yaml.tpl gitlab-chart-values.yaml
template_file ./templates/gitlab-IngressTcpRoute.yaml.tpl gitlab-IngressTcpRoute.yaml
notify "Spinning up GitLab..."
helm repo add nemonik https://nemonik.github.io/helm-charts/
helm repo update
create_namespace ${gitlab_namespace}
helm install gitlab nemonik/gitlab --namespace ${gitlab_namespace} -f gitlab-chart-values.yaml
kubectl apply -f gitlab-IngressTcpRoute.yaml
gitlab_pod_name=`kubectl get pod -n ${gitlab_namespace} -l "app.kubernetes.io/component=gitlab" -o json | jq -r '.items | .[] | .metadata.name'`
notify "Waiting for pod/${gitlab_pod_name} -n ${gitlab_namespace} to become ready..."
kubectl wait --for=condition=Ready pod/${gitlab_pod_name} -n ${gitlab_namespace} --timeout 600s
notify "Waiting til GitLab is responding to https requests..."
loop=0
while : ; do
if [ $loop -eq 15 ]; then
warn
warn "GitLab appears to have failed to come up in the expected amount on time. Abnormal, but this doesn't mean it will never come up. The automation will keep trying til either GitLab comes up or you interrupt the automation."
warn
fi
if curl --silent ${gitlab_protocol}://${gitlab_fdqn} | grep -q "sign_in"; then
notify "Performing post ready configuration setup..."
notify "Creating GitLab automation token..."
read gitlab_pod_name gitlab_token < <(create_automation_token)
notify "Configuring GitLab via REST api..."
rest_api_loop=0
for (( ; ; )); do
if [ $rest_api_loop -eq 15 ]; then
warn
warn "GitLab REST API is refusing to let us to connect. The autonation will keep trying til either this works or you interrupt the automation."
warn
fi
output=`curl --silent --request PUT --header "PRIVATE-TOKEN: $gitlab_token" "${gitlab_protocol}://${gitlab_fdqn}/api/v4/application/settings?${gitlab_settings}" | jq '.' 2>&1`
if [[ "${output}" == *"401 Unauthorized"* ]] || [[ "${output}" == *"Invalid numeric literal"* ]]; then
echo $output | jq -r "."
else
echo $output | jq -r "."
break
fi
sleep 5
notify " Attempting again..."
((rest_api_loop++))
done
revoke_automation_token $gitlab_pod_name $gitlab_token
notify "Completed post step."
break
fi
notify " Still waiting for GitLab to respond to ${gitlab_protocol} requests..."
((loop=loop+1))
sleep 60
done
notify "Done."