forked from crosscloudci/cross-cloud
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprovision.sh
executable file
·315 lines (289 loc) · 13.3 KB
/
provision.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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
#!/bin/bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
_retry() {
[ -z "${2}" ] && return 1
echo -n ${1}
until printf "." && "${@:2}" &>/dev/null; do sleep 5.2; done; echo "✓"
}
set -e
RED='\033[0;31m'
NC='\033[0m' # No Color
export TF_VAR_name="$2"
export TF_VAR_internal_tld=${TF_VAR_name}.cncf.demo
export TF_VAR_data_dir=$(pwd)/data/${TF_VAR_name}
export TF_VAR_aws_key_name=${TF_VAR_name}
export TF_VAR_packet_api_key=${PACKET_AUTH_TOKEN}
if [ ! -e $KUBERNETES_IMAGE ] ; then
export TF_VAR_kubelet_image_url=$KUBERNETES_IMAGE
fi
if [ ! -e $KUBERNETES_TAG ] ; then
export TF_VAR_kubelet_image_tag=$KUBERNETES_TAG
fi
# tfstate, sslcerts, and ssh keys are currently stored in TF_VAR_data_dir
mkdir -p $TF_VAR_data_dir
# Run CMD
if [ "$1" = "aws-deploy" ] ; then
cd ${DIR}/aws
if [ "$3" = "s3" ]; then
cp ../s3-backend.tf .
terraform init \
-backend-config 'bucket=aws65972563' \
-backend-config "key=aws-${TF_VAR_name}" \
-backend-config 'region=ap-southeast-2'
# ensure kubeconfig is written to disk on infrastructure refresh
terraform taint -module=kubeconfig null_resource.kubeconfig || true
time terraform apply ${DIR}/aws
elif [ "$3" = "file" ]; then
cp ../file-backend.tf .
terraform init \
-backend-config "path=/cncf/data/${TF_VAR_name}/terraform.tfstate"
# ensure kubeconfig is written to disk on infrastructure refresh
terraform taint -module=kubeconfig null_resource.kubeconfig || true ${DIR}/aws
time terraform apply ${DIR}/aws
fi
ELB=$(terraform output external_elb)
export KUBECONFIG=${TF_VAR_data_dir}/kubeconfig
echo "❤ Polling for cluster life - this could take a minute or more"
_retry "❤ Waiting for DNS to resolve for ${ELB}" ping -c1 "${ELB}"
_retry "❤ Curling apiserver external elb" curl --insecure --silent "https://${ELB}"
_retry "❤ Trying to connect to cluster with kubectl" kubectl cluster-info
kubectl cluster-info
elif [ "$1" = "aws-destroy" ] ; then
cd ${DIR}/aws
if [ "$3" = "s3" ]; then
cp ../s3-backend.tf .
terraform init \
-backend-config 'bucket=aws65972563' \
-backend-config "key=aws-${TF_VAR_name}" \
-backend-config 'region=ap-southeast-2'
time terraform destroy -force ${DIR}/aws
elif [ "$3" = "file" ]; then
cp ../file-backend.tf .
terraform init \
-backend-config "path=/cncf/data/${TF_VAR_name}/terraform.tfstate"
time terraform destroy -force ${DIR}/aws
fi
elif [ "$1" = "azure-deploy" ] ; then
# There are some dependency issues around cert,sshkey,k8s_cloud_config, and dns
# since they use files on disk that are created on the fly
# should probably move these to data resources
cd ${DIR}/azure
if [ "$3" = "s3" ]; then
cp ../s3-backend.tf .
terraform init \
-backend-config 'bucket=aws65972563' \
-backend-config "key=${TF_VAR_name}" \
-backend-config 'region=ap-southeast-2'
# ensure kubeconfig is written to disk on infrastructure refresh
terraform taint -module=kubeconfig null_resource.kubeconfig || true
terraform apply -target null_resource.ssl_ssh_cloud_gen ${DIR}/azure && \
terraform apply -target module.dns.null_resource.dns_gen ${DIR}/azure && \
time terraform apply ${DIR}/azure
elif [ "$3" = "file" ]; then
cp ../file-backend.tf .
terraform init \
-backend-config "path=/cncf/data/${TF_VAR_name}/terraform.tfstate"
# ensure kubeconfig is written to disk on infrastructure refresh
terraform taint -module=kubeconfig null_resource.kubeconfig || true
terraform apply -target null_resource.ssl_ssh_cloud_gen ${DIR}/azure && \
terraform apply -target module.dns.null_resource.dns_gen ${DIR}/azure && \
time terraform apply ${DIR}/azure
fi
elif [ "$1" = "azure-destroy" ] ; then
cd ${DIR}/azure
if [ "$3" = "s3" ]; then
cp ../s3-backend.tf .
terraform init \
-backend-config 'bucket=aws65972563' \
-backend-config "key=${TF_VAR_name}" \
-backend-config 'region=ap-southeast-2'
terraform destroy -force -target null_resource.ssl_ssh_cloud_gen ${DIR}/azure && \
terraform destroy -force -target module.dns.null_resource.dns_gen ${DIR}/azure && \
terraform apply -target null_resource.ssl_ssh_cloud_gen ${DIR}/azure && \
terraform apply -target module.dns.null_resource.dns_gen ${DIR}/azure && \
time terraform destroy -force ${DIR}/azure || true
elif [ "$3" = "file" ]; then
cp ../file-backend.tf .
terraform init \
-backend-config "path=/cncf/data/${TF_VAR_name}/terraform.tfstate"
terraform destroy -force -target null_resource.ssl_ssh_cloud_gen ${DIR}/azure && \
terraform destroy -force -target module.dns.null_resource.dns_gen ${DIR}/azure && \
terraform apply -target null_resource.ssl_ssh_cloud_gen ${DIR}/azure && \
terraform apply -target module.dns.null_resource.dns_gen ${DIR}/azure && \
time terraform destroy -force ${DIR}/azure || true
fi
elif [ "$1" = "packet-deploy" ] ; then
cd ${DIR}/packet
if [ "$3" = "s3" ]; then
cp ../s3-backend.tf .
terraform init \
-backend-config 'bucket=aws65972563' \
-backend-config "key=packet-${TF_VAR_name}" \
-backend-config 'region=ap-southeast-2'
# ensure kubeconfig is written to disk on infrastructure refresh
terraform taint -module=kubeconfig null_resource.kubeconfig || true ${DIR}/packet
terraform taint null_resource.set_dns || true ${DIR}/packet
time terraform apply ${DIR}/packet
elif [ "$3" = "file" ]; then
cp ../file-backend.tf .
terraform init \
-backend-config "path=/cncf/data/${TF_VAR_name}/terraform.tfstate"
# ensure kubeconfig is written to disk on infrastructure refresh
terraform taint -module=kubeconfig null_resource.kubeconfig || true ${DIR}/packet
time terraform apply ${DIR}/packet
fi
ELB=$(terraform output endpoint)
export KUBECONFIG=${TF_VAR_data_dir}/kubeconfig
echo "❤ Polling for cluster life - this could take a minute or more"
_retry "❤ Waiting for DNS to resolve for ${ELB}" ping -c1 "${ELB}"
_retry "❤ Curling apiserver external elb" curl --insecure --silent "https://${ELB}"
_retry "❤ Trying to connect to cluster with kubectl" kubectl cluster-info
kubectl cluster-info
elif [ "$1" = "packet-destroy" ] ; then
cd ${DIR}/packet
if [ "$3" = "s3" ]; then
cp ../s3-backend.tf .
terraform init \
-backend-config 'bucket=aws65972563' \
-backend-config "key=packet-${TF_VAR_name}" \
-backend-config 'region=ap-southeast-2'
time terraform destroy -force ${DIR}/packet
elif [ "$3" = "file" ]; then
cp ../file-backend.tf .
terraform init \
-backend-config "path=/cncf/data/${TF_VAR_name}/terraform.tfstate"
time terraform destroy -force ${DIR}/packet
fi
elif [ "$1" = "gce-deploy" ] ; then
cd ${DIR}/gce
if [ "$3" = "s3" ]; then
cp ../s3-backend.tf .
terraform init \
-backend-config 'bucket=aws65972563' \
-backend-config "key=gce-${TF_VAR_name}" \
-backend-config 'region=ap-southeast-2'
# ensure kubeconfig is written to disk on infrastructure refresh
terraform taint -module=kubeconfig null_resource.kubeconfig || true ${DIR}/gce
time terraform apply -target module.vpc.google_compute_subnetwork.cncf ${DIR}/gce
time terraform apply ${DIR}/gce
elif [ "$3" = "file" ]; then
cp ../file-backend.tf .
terraform init \
-backend-config "path=/cncf/data/${TF_VAR_name}/terraform.tfstate"
# ensure kubeconfig is written to disk on infrastructure refresh
terraform taint -module=kubeconfig null_resource.kubeconfig || true ${DIR}/gce
time terraform apply -target module.vpc.google_compute_subnetwork.cncf ${DIR}/gce
time terraform apply ${DIR}/gce
fi
ELB=$(terraform output external_lb)
export KUBECONFIG=${TF_VAR_data_dir}/kubeconfig
echo "❤ Polling for cluster life - this could take a minute or more"
_retry "❤ Waiting for DNS to resolve for ${ELB}" ping -c1 "${ELB}"
_retry "❤ Curling apiserver external elb" curl --insecure --silent "https://${ELB}"
_retry "❤ Trying to connect to cluster with kubectl" kubectl cluster-info
kubectl cluster-info
elif [ "$1" = "gce-destroy" ] ; then
cd ${DIR}/gce
if [ "$3" = "s3" ]; then
cp ../s3-backend.tf .
terraform init \
-backend-config 'bucket=aws65972563' \
-backend-config "key=gce-${TF_VAR_name}" \
-backend-config 'region=ap-southeast-2'
time terraform destroy -force ${DIR}/gce || true # Allow to Fail and clean up network on next step
time terraform destroy -force -target module.vpc.google_compute_subnetwork.cncf ${DIR}/gce
elif [ "$3" = "file" ]; then
cp ../file-backend.tf .
terraform init \
-backend-config "path=/cncf/data/${TF_VAR_name}/terraform.tfstate"
time terraform destroy -force ${DIR}/gce || true # Allow to Fail and clean up network on next step
time terraform destroy -force -target module.vpc.google_compute_subnetwork.cncf ${DIR}/gce
fi
elif [ "$1" = "gke-deploy" ] ; then
cd ${DIR}/gke
if [ "$3" = "s3" ]; then
cp ../s3-backend.tf .
terraform init \
-backend-config 'bucket=aws65972563' \
-backend-config "key=gke-${TF_VAR_name}" \
-backend-config 'region=ap-southeast-2'
# ensure kubeconfig is written to disk on infrastructure refresh
terraform taint -module=kubeconfig null_resource.kubeconfig || true
time terraform apply -target module.vpc ${DIR}/gke && \
time terraform apply ${DIR}/gke
elif [ "$3" = "file" ]; then
cp ../file-backend.tf .
terraform init \
-backend-config "path=/cncf/data/${TF_VAR_name}/terraform.tfstate"
# ensure kubeconfig is written to disk on infrastructure refresh
terraform taint -module=kubeconfig null_resource.kubeconfig || true
time terraform apply -target module.vpc ${DIR}/gke && \
time terraform apply ${DIR}/gke
fi
ELB=$(terraform output endpoint)
export KUBECONFIG=${TF_VAR_data_dir}/kubeconfig
echo "❤ Polling for cluster life - this could take a minute or more"
_retry "❤ Waiting for DNS to resolve for ${ELB}" ping -c1 "${ELB}"
_retry "❤ Curling apiserver external elb" curl --insecure --silent "https://${ELB}"
_retry "❤ Trying to connect to cluster with kubectl" kubectl cluster-info
kubectl cluster-info
elif [ "$1" = "gke-destroy" ] ; then
cd ${DIR}/gke
if [ "$3" = "s3" ]; then
cp ../s3-backend.tf .
terraform init \
-backend-config 'bucket=aws65972563' \
-backend-config "key=gke-${TF_VAR_name}" \
-backend-config 'region=ap-southeast-2'
time terraform destroy -force -target module.cluster.google_container_cluster.cncf ${DIR}/gke || true
echo "sleep" && sleep 10 && \
time terraform destroy -force -target module.vpc.google_compute_network.cncf ${DIR}/gke || true
time terraform destroy -force ${DIR}/gke || true
elif [ "$3" = "file" ]; then
cp ../file-backend.tf .
terraform init \
-backend-config "path=/cncf/data/${TF_VAR_name}/terraform.tfstate"
time terraform destroy -force -target module.cluster.google_container_cluster.cncf ${DIR}/gke || true
echo "sleep" && sleep 10 && \
time terraform destroy -force -target module.vpc.google_compute_network.cncf ${DIR}/gke || true
time terraform destroy -force ${DIR}/gke || true
fi
elif [ "$1" = "bluemix-deploy" ] ; then
cd ${DIR}/bluemix
if [ "$3" = "s3" ]; then
cp ../s3-backend.tf .
terraform init \
-backend-config 'bucket=aws65972563' \
-backend-config "key=bluemix-${TF_VAR_name}" \
-backend-config 'region=ap-southeast-2'
# ensure kubeconfig is written to disk on infrastructure refresh
terraform taint null_resource.kubeconfig || true
time terraform apply ${DIR}/bluemix
elif [ "$3" = "file" ]; then
cp ../file-backend.tf .
terraform init \
-backend-config "path=/cncf/data/${TF_VAR_name}/terraform.tfstate"
# ensure kubeconfig is written to disk on infrastructure refresh
terraform taint null_resource.kubeconfig || true
time terraform apply ${DIR}/bluemix
fi
export KUBECONFIG=${TF_VAR_data_dir}/kubeconfig
echo "❤ Polling for cluster life - this could take a minute or more"
_retry "❤ Trying to connect to cluster with kubectl" kubectl cluster-info
kubectl cluster-info
elif [ "$1" = "bluemix-destroy" ] ; then
cd ${DIR}/gke
if [ "$3" = "s3" ]; then
cp ../s3-backend.tf .
terraform init \
-backend-config 'bucket=aws65972563' \
-backend-config "key=bluemix-${TF_VAR_name}" \
-backend-config 'region=ap-southeast-2'
time terraform destroy -force ${DIR}/bluemix
elif [ "$3" = "file" ]; then
cp ../file-backend.tf .
terraform init \
-backend-config "path=/cncf/data/${TF_VAR_name}/terraform.tfstate"
time terraform destroy -force ${DIR}/bluemix
fi
fi