-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdeploy.sh
159 lines (143 loc) · 3.97 KB
/
deploy.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
#!/bin/bash -x
if [[ "$1" == 'dev' ]];
then
cluster='a1-ops-dev'
namespace='supporttools-dev'
imagetag=${BUILD_NUMBER}
purge=false
hpa=false
minReplicas=1
maxReplicas=1
ingress='dev.support.tools'
class="dev"
synccdn=false
elif [[ "$1" == 'qas' ]];
then
cluster='a1-ops-dev'
namespace='supporttools-qas'
imagetag=${BUILD_NUMBER}
purge=false
hpa=true
minReplicas=3
maxReplicas=5
ingress='qas.support.tools'
class="qas"
synccdn=true
elif [[ "$1" == 'tst' ]];
then
cluster='a1-ops-dev'
namespace='supporttools-tst'
imagetag=${BUILD_NUMBER}
purge=false
hpa=true
minReplicas=3
maxReplicas=5
ingress='tst.support.tools'
class="tst"
synccdn=true
elif [[ "$1" == 'stg' ]];
then
cluster='a1-ops-prd'
namespace='supporttools-stg'
imagetag=${BUILD_NUMBER}
purge=false
hpa=true
minReplicas=3
maxReplicas=5
ingress='stg.support.tools'
class="stg"
synccdn=true
elif [[ "$1" == 'prd' ]];
then
cluster='a1-ops-prd'
namespace='supporttools-prd'
imagetag=${BUILD_NUMBER}
purge=false
hpa=true
minReplicas=3
maxReplicas=7
ingress='support.tools'
class="prd"
synccdn=true
else
cluster='a1-ops-dev'
namespace='supporttools-mst'
imagetag=${DRONE_BUILD_NUMBER}
purge=false
hpa=true
minReplicas=1
maxReplicas=1
ingress='mst.support.tools'
class="mst"
synccdn=false
fi
if [ ! -z "${TAG}" ]
then
echo "Using tag ${TAG}"
imagetag=${TAG}
fi
echo "Cluster:" ${cluster}
echo "Deploying to namespace: ${namespace}"
echo "Image tag: ${imagetag}"
echo "Purge: ${purge}"
echo "HPA: ${hpa}"
echo "Installing kubectl"
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
echo "Installing helm"
curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3
chmod 700 get_helm.sh
bash get_helm.sh
echo "Installing rancher-projects"
curl -fsSL -o rancher-projects.tar.gz https://github.com/SupportTools/rancher-projects/releases/download/v0.2.2/rancher-projects_0.2.2_linux_amd64.tar.gz
tar -xvf rancher-projects.tar.gz
chmod +x rancher-projects
mv rancher-projects /usr/local/bin/rancher-projects
echo "Settings up project, namespace, and kubeconfig"
rancher-projects \
--rancher-server ${CATTLE_SERVER} \
--rancher-access-key ${CATTLE_ACCESS_KEY} \
--rancher-secret-key ${CATTLE_SECRET_KEY} \
--cluster-name ${cluster} \
--project-name "SupportTools" \
--namespace ${namespace} \
--create-kubeconfig \
--kubeconfig "kubeconfig"
if [ ! -f kubeconfig ]
then
echo "Problem creating kubeconfig"
exit 1
fi
export KUBECONFIG=kubeconfig
if ! kubectl cluster-info
then
echo "Problem connecting to the cluster"
exit 1
fi
echo "#############################################################################"
echo "Node information"
kubectl get nodes -o wide
echo "#############################################################################"
echo "Creating namespace"
kubectl create ns ${namespace} --dry-run=client -o yaml | kubectl apply -f -
echo "Adding labels to namespace"
kubectl label ns ${namespace} team=SupportTools --overwrite
kubectl label ns ${namespace} app=website --overwrite
kubectl label ns ${namespace} ns-purge=${purge} --overwrite
kubectl label ns ${namespace} class=${class} --overwrite
echo "Deploying website"
helm upgrade --install website ./charts/website \
--namespace ${namespace} \
-f ./charts/website/values.yaml \
--set image.tag=${imagetag} \
--set ingress.host=${ingress} \
--set autoscaling.minReplicas=${maxReplicas} \
--set autoscaling.maxReplicas=${maxReplicas} \
--set webcache.replicaCount=${maxReplicas} \
--force
echo "Waiting for frontend to be ready"
timeout 15m kubectl -n ${namespace} rollout status deployment frontend
echo "Recycling web-cache"
timeout 15m kubectl -n ${namespace} rollout restart deployment web-cache --ignore-not-found
echo "Waiting for web-cache to be ready"
timeout 15m kubectl -n ${namespace} rollout status deployment web-cache || true