-
Notifications
You must be signed in to change notification settings - Fork 4
/
install.sh
executable file
·196 lines (166 loc) · 5.45 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#!/bin/bash
script_dir=$(cd $(dirname $0) && pwd)
set -e
usage () {
echo -e "\nUSAGE: install.sh -e|--environment <ENVIRONMENT> \\"
echo -e " [ -i|--iaas <IAAS_NAME> -r|--registry <REGISTRY_DNS> -u|--user <USER_NAME> -p|--password <PASSWORD> ] \\"
echo -e " [ -t|--tools <PRODUCT_LIST> ] [ -x|--uninstall ]\n"
echo -e " This utility will install the 'devops' tools using images and charts uploaded to the"
echo -e " given private registry. It will also deploy Helm's tiller container to the kubernetes"
echo -e " cluster if has not been deployed.\n"
echo -e " -e|--environment <ENVIRONMENT> The namespace environment to deploy devops tools to."
echo -e " -i|--iaas <IAAS_NAME> The underlying IAAS for allocating IAAS specific resource such as persistent volumes."
echo -e " -r|--registry <REGISTRY_DNS> The FQDN or IP of the registry."
echo -e " -u|--user <USER_NAME> The name of the user to use to authenticate with private registry"
echo -e " -p|--password <PASSWORD> The password of the user."
echo -e " -t|--tools <PRODUCT_LIST> Comma separated list of tools to install or uninstall."
echo -e " If not provided then all the tools will be deployed."
echo -e " -x|--uninstall Uninstalls the tool.\n"
echo -e " Options --iaas, --registry, --username and --password are required for install.\n"
}
create_uaa_client() {
uaa_url=$1
admin_client_secret=$2
client_id=$3
client_secret=$4
scopes=$5
redirect_uri=$6
uaac target --skip-ssl-validation $uaa_url
uaac token client get admin -s $admin_client_secret
uaac client get $client_id >/dev/null 2>&1 || \
uaac client add $client_id \
--name "$client_id" \
--secret "$client_secret" \
--scope "$scopes" \
--authorities uaa.none \
--authorized_grant_types authorization_code,refresh_token,password \
--access_token_validity 3600 \
--refresh_token_validity 7200 \
--redirect_uri "$redirect_uri"
}
action=install
while [[ $# -gt 0 ]]; do
case "$1" in
'-?'|--help|help)
usage
exit 0
;;
-v|--debug)
set -x
;;
-i|--iaas)
iaas=$2
shift
;;
-e|--environment)
environment=$2
shift
;;
-r|--registry)
registry=$2
shift
;;
-u|--user)
user=$2
shift
;;
-p|--password)
password=$2
shift
;;
-t|--tools)
tools=$2
shift
;;
-x|--uninstall)
action=uninstall
;;
*)
usage
exit 1
;;
esac
shift
done
if [[ -z $environment \
|| ( $action == install \
&& ( -z $iaas \
|| -z $registry \
|| -z $user \
|| -z $password ) ) ]]; then
usage
exit 1
fi
ca_cert_file=${script_dir}/.certs/ca.crt
if [[ ! -e $ca_cert_file ]]; then
echo -e "\nERROR: Please provide a CA cert file at:"
echo -e " $ca_cert_file"
echo -e " to validate self-signed TLS end-points.\n"
exit 1
fi
###############
# Common Values
###############
install_config=${script_dir}/.install
common_config=${script_dir}/config/common
mkdir -p $install_config
env_domain=${ENV_DOMAIN:-}
postgresql_image_version=${POSTGRESQL_IMAGE_VERSION:-11.2.0}
postgresql_chart_version=${POSTGRESQL_CHART_VERSION:-3.15.0}
postgresql_config=${script_dir}/config/postgresql
redis_image_version=${REDIS_IMAGE_VERSION:-5.0.4}
redis_chart_version=${REDIS_CHART_VERSION:-6.4.3}
redis_config=${script_dir}/config/redis
minio_image_version=${MINIO_IMAGE_VERSION:-RELEASE.2019-03-20T22-38-47Z}
minio_mc_image_version=${MINIO_MC_IMAGE_VERSION:-RELEASE.2019-03-20T21-29-03Z}
minio_chart_version=${MINIO_CHART_VERSION:-2.4.9}
minio_config=${script_dir}/config/minio
# Interpolate common k8s and helm resource declaration files
eval "echo \"$(cat ${common_config}/namespace.yml)\"" \
> ${install_config}/namespace.yml
# Create common k8s and helm resources
if [[ -z `kubectl get pods -n kube-system | awk '/^tiller-/{ print $1 }'` ]]; then
# Install tiller offline
# https://github.com/helm/helm/issues/4540
tiller_version=${TILLER_VERSION:-v2.13.0}
echo -e "\n*** Resetting helm..."
set +e
kubectl delete \
-f ${common_config}/tiller-service-account.yml \
>/dev/null 2>&1
set -e
helm reset --force
echo -e "\n*** Initializing helm.."
helm init \
--tiller-image ${registry}/releng/tiller:${tiller_version}
kubectl create \
-f ${common_config}/tiller-service-account.yml
else
helm init --client-only >/dev/null 2>&1
fi
if [[ -z `kubectl get namespaces | awk "/^${environment} /{ print \$1 }"` ]]; then
kubectl create \
--filename ${install_config}/namespace.yml
kubectl set subject clusterrolebinding tiller --serviceaccount=${environment}:tiller
kubectl set subject clusterrolebinding tiller --serviceaccount=${environment}:default
fi
if [[ $action == install ]]; then
case "$iaas" in
google)
;;
vsphere)
if [[ -n $VSPHERE_DATASTORE ]]; then
echo -e "\nERROR! Please provide the vsphere data store to use for persistent\n"
echo -e " volumes via 'VSPHERE_DATASTORE' environment variable.\n"
exit 1
fi
;;
*)
echo -e "\nERROR! IAAS must be one of 'google' or 'vsphere'.\n"
exit 1
esac
helm_deployments=$(helm list)
fi
for t in $(echo $tools | sed 's|,| |g'); do
eval "source ${script_dir}/install-$t.sh $action"
done