This repository has been archived by the owner on Jun 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
deploy.sh
executable file
·84 lines (76 loc) · 2.92 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
#! /bin/bash
set -e
trap "rm security_group.json" EXIT
setEnvs () {
cf set-env "$1" BOSH_USERNAME "${BOSH_USERNAME}"
cf set-env "$1" BOSH_PASSWORD "${BOSH_PASSWORD}"
cf set-env "$1" BOSH_URI "${BOSH_URI}"
cf set-env "$1" BOSH_PORT 25555
if [ -n "${CF_DEPLOYMENT_NAME}" ]; then
cf set-env "$1" CF_DEPLOYMENT_NAME "${CF_DEPLOYMENT_NAME}"
fi
if [ -n "${ETCD_JOB_NAME}" ]; then
cf set-env "$1" ETCD_JOB_NAME "${ETCD_JOB_NAME}"
fi
if [ -n "${SSL_ENABLED}" ]; then
cf set-env "$1" SSL_ENABLED "${SSL_ENABLED}"
fi
if [ -n "${SKIP_SSL_VERIFICATION}" ]; then
cf set-env "$1" SKIP_SSL_VERIFICATION "${SKIP_SSL_VERIFICATION}"
fi
}
echo "Logging into CF..."
cf api https://api."${CF_SYS_DOMAIN}" --skip-ssl-validation
cf auth "${CF_DEPLOY_USERNAME}" "${CF_DEPLOY_PASSWORD}"
echo "Creating Org etcd-leader-monitor..."
cf create-org etcd-leader-monitor
echo "Targetting Org etcd-leader-monitor..."
cf target -o etcd-leader-monitor
echo "Creating Space etcd-leader-monitor..."
cf create-space etcd-leader-monitor
echo "Targetting Space etcd-leader-monitor..."
cf target -s etcd-leader-monitor
echo "Setting up security groups..."
if [ -z "${CF_NETWORKS}" ]; then
# Disable this shellcheck warning as we know how to spell correctly.
# shellcheck disable=SC2153
CF_NETWORKS="${CF_NETWORK}"
fi
echo "[" > security_group.json
last_subnet=$(echo "${CF_NETWORKS}" | awk -F, '{print $NF}')
for subnet in ${CF_NETWORKS//,/ } ;
do
cat >> security_group.json << EOF
{
"destination": "$subnet",
"protocol": "tcp",
"ports": "25555, 4001, 8443"
EOF
if [ "${subnet}" != "${last_subnet}" ];
then
echo " }," >> security_group.json
else
echo " }" >> security_group.json
fi
done
echo "]" >> security_group.json
if cf create-security-group etcd-leader-monitor security_group.json | grep -q "already exists"; then
cf update-security-group etcd-leader-monitor security_group.json
fi
cf bind-security-group etcd-leader-monitor etcd-leader-monitor etcd-leader-monitor
echo "Deploying apps..."
if [[ "$(cf app etcd-leader-monitor) || true)" == *"FAILED"* ]] ; then
cf push "${APP_NAME:-etcd-leader-monitor}" --no-start
setEnvs "${APP_NAME:-etcd-leader-monitor}"
cf start "${APP_NAME:-etcd-leader-monitor}"
else
echo "Zero downtime deploying etcd-leader-monitor..."
domain=$(cf app etcd-leader-monitor | grep -E 'urls|routes' | cut -d":" -f2 | xargs | cut -d"." -f 2-)
cf push "${APP_NAME:-etcd-leader-monitor}-green" -f manifest.yml -n "${APP_NAME:-etcd-leader-monitor}-green" --no-start
setEnvs "${APP_NAME:-etcd-leader-monitor}-green"
cf start "${APP_NAME:-etcd-leader-monitor}-green"
cf map-route "${APP_NAME:-etcd-leader-monitor}-green" "${domain}" -n "${APP_NAME:-etcd-leader-monitor}"
cf delete "${APP_NAME:-etcd-leader-monitor}" -f
cf rename "${APP_NAME:-etcd-leader-monitor}-green" "${APP_NAME:-etcd-leader-monitor}"
cf unmap-route "${APP_NAME:-etcd-leader-monitor}" "${domain}" -n "${APP_NAME:-etcd-leader-monitor}-green"
fi