-
Notifications
You must be signed in to change notification settings - Fork 3
/
IBMCloud_KS.sh
executable file
·183 lines (169 loc) · 6 KB
/
IBMCloud_KS.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
#!/bin/bash
set -e
##################################################
####ENTER THESE VARIABLES TO USE THIS SCRIPT####
##################################################
#API_KEY is needed for bx commands for authentication
API_KEY=
CLUSTER_NAME=
#Default Dallas Region, dev space
REGION=ng
SPACE=dev
#Default IBM Cloud Registry at registry.${REGION}.bluemix.net. If docker repository hosted in https://cloud.docker.com is used, change the registry name to your docker username, then add docker password
REGISTRY=registry.${REGION}.bluemix.net
NAMESPACE=
DOCKER_PASSWORD=
IMAGE_TAG=latest
# Terminal Colors
red=$'\e[1;31m'
grn=$'\e[1;32m'
yel=$'\e[1;33m'
blu=$'\e[1;34m'
mag=$'\e[1;35m'
cyn=$'\e[1;36m'
end=$'\e[0m'
coffee=$'\xE2\x98\x95'
coffee3="${coffee} ${coffee} ${coffee}"
function usage {
echo "usage:"
echo "${cyn}To Install CLI and plugins${end}" $0 " [-p|--prep]"
echo "e.g.${grn} $0 -p${end}"
echo "${cyn}To Login IBM Cloud and Container Service${end}" $0 " [-l|--login]"
echo "e.g.${grn} $0 -l${end}"
echo "${cyn}To Clone git repository${end}" $0 " [-c|--clone]"
echo "e.g.${grn} $0 -c${end}"
echo "${cyn}To Deploy Containers to the Container Service${end}" $0 " [-d|--deploy]"
echo "e.g.${grn} $0 -d${end}"
echo "${cyn}To Populate DB${end}" $0 " [-db|--loaddb]"
echo "e.g.${grn} $0 -db${end}"
echo "${cyn}To Undeploy Containers from the Container Service${end}" $0 " [-u|--undeploy]"
echo "e.g.${grn} $0 -u${end}"
echo "${cyn}To Login, Clone, Deploy and Populate DB NOTE:It will pause 2 minutes before DB polulation. If DB is not populated, run -db separately${end}" $0 " [-a|--all]"
echo "e.g.${grn} $0 -a${end}"
echo "Details of all options:"
echo " -a Run below -l, -c, -d and -db commands"
echo " -p Install CLI and plugins"
echo " -l Login IBM Cloud and Container Service"
echo " -c Clone git repositories"
echo " -d Deploy Containers"
echo " -db Load DB"
echo " -u Undeploy Containers"
exit 1
}
[ -z $1 ] && { usage; }
printf "Region : ${cyn}$REGION${end}\n"
printf "Cluster : ${cyn}$CLUSTER_NAME${end}\n"
printf "Namespace : ${cyn}$NAMESPACE${end}\n"
BRANCH=master
LOGIN=false
CLI=false
CLONE=false
DEPLOY=false
UNDEPLOY=false
INGRESS=false
DB=false
PAUSE=false
while true; do
case "$1" in
-a | --all ) LOGIN=true;CLONE=true;DEPLOY=true;DB=true;PAUSE=true; shift;;
-p | --prep ) CLI=true; shift;;
-l | --login ) LOGIN=true; shift;;
-d | --deploy ) DEPLOY=true; shift;;
-db | --loaddb ) DB=true; shift;;
-u | --undeploy ) UNDEPLOY=true; shift;;
-c | --clone ) CLONE=true; shift;;
-pause | --pause ) PAUSE=true; shift;;
-- ) shift; break ;;
* ) break ;;
esac
done
if [ "$CLI" = true ] ; then
printf "${grn}Running install_cli.sh${end}\n"
./scripts/install_cli.sh
fi
if [[ "$LOGIN" = true && -n "${API_KEY// }" ]] ; then
printf "${grn}Running login_ibmcloud.sh with ${API_KEY} ${SPACE} ${REGION}${end}\n"
./scripts/login_ibmcloud.sh -a ${API_KEY} -c ${CLUSTER_NAME} -s ${SPACE} -r ${REGION}
fi
declare -a arr=("acmeair-authservice-java" "acmeair-bookingservice-java" "acmeair-customerservice-java" "acmeair-flightservice-java")
#declare -a arr=("acmeair-bookingservice-java")
if [[ "$CLONE" = true ]] ; then
printf "${cyn}Cloning Acmair Homogeneous Java Microservice${end}\n"
for i in "${arr[@]}"
do
git clone https://github.com/blueperf/${i}
done
fi
if [[ "$DEPLOY" = true ]] ; then
for i in "${arr[@]}"
do
printf "${cyn}Creating Image ${i} in ${REGISTRY}${end}\n"
YAML_FILE=${i}.yaml
DIRECTORY=${i}
if [[ ${REGISTRY} == *"bluemix.net"* ]] ; then
IMAGE_NAME=${REGISTRY}/${NAMESPACE}/${i}:${IMAGE_TAG}
else
IMAGE_NAME=${REGISTRY}/${i}:${IMAGE_TAG}
docker login -u ${REGISTRY} -p ${DOCKER_PASSWORD}
fi
echo ${IMAGE_NAME}
INGRESS=false
if [[ ${i} = *"auth"* ]] ; then
printf "${grn}Also generating Ingress${end}\n"
INGRESS=true
fi
./scripts/create_image.sh -i ${IMAGE_NAME} -d ${i} -f "Dockerfile"
./scripts/create_deployment.sh -c ${CLUSTER_NAME} -i ${IMAGE_NAME} -d ${i}/manifests-demo -y deploy-${i}.yaml -ing ${INGRESS}
done
fi
# Getting Cluster Configuration
unset KUBECONFIG
echo "${grn}Getting configuration for cluster ${CLUSTER_NAME}...${end}"
bx cs cluster-config ${CLUSTER_NAME}
eval "$(bx cs cluster-config ${CLUSTER_NAME} | tail -1)"
echo "KUBECONFIG is set to = $KUBECONFIG"
if [[ "$PAUSE" = true ]] ; then
printf "${grn}Pausing 2 minutes for Pods to be created & Liberty Server to startup${end}\n"
sleep 120
# Getting Cluster Configuration
unset KUBECONFIG
echo "${grn}Getting configuration for cluster ${CLUSTER_NAME}...${end}"
bx cs cluster-config ${CLUSTER_NAME}
eval "$(bx cs cluster-config ${CLUSTER_NAME} | tail -1)"
echo "KUBECONFIG is set to = $KUBECONFIG"
if [[ -z "${KUBECONFIG// }" ]]; then
echo "KUBECONFIG was not properly set. Exiting"
exit 1
fi
kubectl get deploy | grep acmeair
fi
if [[ "$DB" = true ]] ; then
eval INGRESS_URL="$(bx cs cluster-get ${CLUSTER_NAME} | grep "Ingress Subdomain" | cut -f 2)"
curl http://${INGRESS_URL}/booking/loader/load || true
printf "\n"
curl http://${INGRESS_URL}/flight/loader/load || true
printf "\n"
curl http://${INGRESS_URL}/customer/loader/load?numCustomers=10000 || true
printf "\n"
printf "${grn}Database Loaded${end}\n"
fi
if [[ "$UNDEPLOY" = true ]] ; then
# Getting Cluster Configuration
unset KUBECONFIG
echo "${grn}Getting configuration for cluster ${CLUSTER_NAME}...${end}"
bx cs cluster-config ${CLUSTER_NAME}
eval "$(bx cs cluster-config ${CLUSTER_NAME} | tail -1)"
echo "KUBECONFIG is set to = $KUBECONFIG"
if [[ -z "${KUBECONFIG// }" ]]; then
echo "KUBECONFIG was not properly set. Exiting"
exit 1
fi
for i in "${arr[@]}"
do
if [[ ${i} = *"auth"* ]] ; then
printf "${grn}Deleting Ingress${end}\n"
kubectl delete -f ${i}/manifests-demo/ing.yaml || true
fi
kubectl delete -f ${i}/manifests-demo/deploy-${i}.yaml || true
done
fi