forked from bdpiprava/node-bulletin-board
-
Notifications
You must be signed in to change notification settings - Fork 30
/
app-deployment.sh
executable file
·58 lines (48 loc) · 2.39 KB
/
app-deployment.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
#!/usr/bin/env bash
sed -i "s~#{image}~$ARTIFACT_IMAGE~g" bulletin-board-deployment.json
if [ -z $KUBE_TOKEN ]; then
echo "FATAL: Environment Variable KUBE_TOKEN must be specified."
exit ${2:-1}
fi
if [ -z $NAMESPACE ]; then
echo "FATAL: Environment Variable NAMESPACE must be specified."
exit ${2:-1}
fi
echo
echo "Namespace $NAMESPACE"
status_code=$(curl -sSk -H "Authorization: Bearer $KUBE_TOKEN" \
"https://$KUBERNETES_SERVICE_HOST:$KUBERNETES_PORT_443_TCP_PORT/apis/apps/v1beta2/namespaces/$NAMESPACE/deployments/bulletin-board-deployment" \
-X GET -o /dev/null -w "%{http_code}")
if [ $status_code == 200 ]; then
echo
echo "Updating deployment"
curl --fail -H 'Content-Type: application/strategic-merge-patch+json' -sSk -H "Authorization: Bearer $KUBE_TOKEN" \
"https://$KUBERNETES_SERVICE_HOST:$KUBERNETES_PORT_443_TCP_PORT/apis/apps/v1beta2/namespaces/$NAMESPACE/deployments/bulletin-board-deployment" \
-X PATCH -d @bulletin-board-deployment.json
else
echo
echo "Creating deployment"
curl --fail -H 'Content-Type: application/json' -sSk -H "Authorization: Bearer $KUBE_TOKEN" \
"https://$KUBERNETES_SERVICE_HOST:$KUBERNETES_PORT_443_TCP_PORT/apis/apps/v1beta2/namespaces/$NAMESPACE/deployments" \
-X POST -d @bulletin-board-deployment.json
fi
status_code=$(curl -sSk -H "Authorization: Bearer $KUBE_TOKEN" \
"https://$KUBERNETES_SERVICE_HOST:$KUBERNETES_PORT_443_TCP_PORT/api/v1/namespaces/$NAMESPACE/services/bulletin-board-service" \
-X GET -o /dev/null -w "%{http_code}")
if [ $status_code == 404 ]; then
echo
echo "Creating service"
curl --fail -H 'Content-Type: application/json' -sSk -H "Authorization: Bearer $KUBE_TOKEN" \
"https://$KUBERNETES_SERVICE_HOST:$KUBERNETES_PORT_443_TCP_PORT/api/v1/namespaces/$NAMESPACE/services" \
-X POST -d @bulletin-board-service.json
fi
status_code=$(curl -sSk -H "Authorization: Bearer $KUBE_TOKEN" \
"https://$KUBERNETES_SERVICE_HOST:$KUBERNETES_PORT_443_TCP_PORT/apis/extensions/v1beta1/namespaces/$NAMESPACE/ingresses/bulletin-board-ingress" \
-X GET -o /dev/null -w "%{http_code}")
if [ $status_code == 404 ]; then
echo
echo "Creating ingress"
curl --fail -H 'Content-Type: application/json' -sSk -H "Authorization: Bearer $KUBE_TOKEN" \
"https://$KUBERNETES_SERVICE_HOST:$KUBERNETES_PORT_443_TCP_PORT/apis/extensions/v1beta1/namespaces/$NAMESPACE/ingresses" \
-X POST -d @bulletin-board-ingress.json
fi