-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdeploy-to-cf.sh
More file actions
executable file
·177 lines (148 loc) · 6.85 KB
/
deploy-to-cf.sh
File metadata and controls
executable file
·177 lines (148 loc) · 6.85 KB
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
#!/bin/bash
SCRIPTDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
source $SCRIPTDIR/.reporc
#################################################################################
# Configuration Data
#################################################################################
#This can be updated to use any string which will guarantee global uniqueness across your region (username, favorite cat, etc.)
UNIQUE_IDENTIFIER=${1:-${RANDOM}}
#The name of the user-provided-service we will create to connect to Service Discovery servers
SERVICE_DISCOVERY_UPS="eureka-service-discovery"
#The name of the user-provided-service we will create to connect to Config servers
CONFIG_SERVER_UPS="config-server"
#The name of the user-provided-service we will create to connect to zipkin
ZIPKIN_SERVER_UPS="zipkin-server"
#The name of the CloudAMQP Bluemix Service for hystrix integration.
CLOUDAMQP_SERVICE="cloudamqp-wfd-resiliency"
# The domain associated with your Bluemix region
DOMAIN="mybluemix.net"
#DOMAIN="eu-gb.mybluemix.net"
#DOMAIN="au-syd.mybluemix.net"
#################################################################################
# Create integration services
#################################################################################
############################ CloudAMQP Service ##################################
if [ -n "`cf services | grep ${CLOUDAMQP_SERVICE}`" ]; then
# Before creating a new CloudAMQP Service, we need to delete the old one and to do so we have to
# unbind any app bound to the old service.
MICROSERVICES=`cf services | grep ${CLOUDAMQP_SERVICE} | sed 's/^.* \(wfd.*$\)/\1/g' | sed 's/, / /g'`
if [ -n "$MICROSERVICES" ]; then
for MICROSERVICE in `echo ${MICROSERVICES}`
do
cf unbind-service ${MICROSERVICE} ${CLOUDAMQP_SERVICE}
done
else
cf delete-service ${CLOUDAMQP_SERVICE} -f
fi
else
# Create new CloudAMQP Service
cf create-service cloudamqp lemur ${CLOUDAMQP_SERVICE}
fi
#################################################################################
#################################################################################
# Deployment Code
#################################################################################
#Build all required repositories as a peer of the current directory (root microservices-refapp-netflix repository)
for REPO in ${CF_REQUIRED_REPOS[@]}; do
#PROJECT=$(echo ${REPO} | cut -d/ -f5 | cut -d. -f1)
echo -e "\nStarting ${REPO} project"
cd ../${REPO}
# Determine which JAR file we should use (since we have both Gradle and Maven possibilities)
RUNNABLE_JAR="$(find . -name "*-SNAPSHOT.jar" | sed -n 1p)"
# Create the route ahead of time to control access
COMPONENT=${REPO#refarch-cloudnative-}
CURRENT_SPACE=$(cf target | grep "Space:" | awk '{print $2}')
SERVICE_ROUTE="${COMPONENT}-${UNIQUE_IDENTIFIER}"
cf create-route ${CURRENT_SPACE} ${DOMAIN} --hostname ${SERVICE_ROUTE}
# Push application code
if [[ ${COMPONENT} == *"netflix-eureka"* ]]; then
# Push Eureka application code, leveraging metadata from manifest.yml
cf push \
${COMPONENT}-${UNIQUE_IDENTIFIER} \
-p ${RUNNABLE_JAR} \
-d ${DOMAIN} \
-n ${SERVICE_ROUTE}
RUN_RESULT=$?
# Create a user-provided-service instance of Eureka for easier binding
CHECK_SERVICE=$(cf service ${SERVICE_DISCOVERY_UPS})
if [[ "$?" == "0" ]]; then
cf delete-service -f ${SERVICE_DISCOVERY_UPS}
fi
cf create-user-provided-service ${SERVICE_DISCOVERY_UPS} -p "{\"uri\": \"http://${SERVICE_ROUTE}.${DOMAIN}/eureka/\"}"
elif [[ ${COMPONENT} == *"spring-config"* ]]; then
# Push Config Server application code, leveraging metadata from manifest.yml
cf push \
${COMPONENT}-${UNIQUE_IDENTIFIER} \
-p ${RUNNABLE_JAR} \
-d ${DOMAIN} \
-n ${SERVICE_ROUTE} \
--no-start
RUN_RESULT=$?
cf set-env ${COMPONENT}-${UNIQUE_IDENTIFIER} SPRING_PROFILES_ACTIVE cloud
cf bind-service ${COMPONENT}-${UNIQUE_IDENTIFIER} ${SERVICE_DISCOVERY_UPS}
cf bind-service ${COMPONENT}-${UNIQUE_IDENTIFIER} ${ZIPKIN_SERVER_UPS}
cf restage ${COMPONENT}-${UNIQUE_IDENTIFIER}
cf start ${COMPONENT}-${UNIQUE_IDENTIFIER}
# Create a user-provided-service instance of Config Server for easier binding
CHECK_SERVICE=$(cf service ${CONFIG_SERVER_UPS})
if [[ "$?" == "0" ]]; then
cf delete-service -f ${CONFIG_SERVER_UPS}
fi
cf create-user-provided-service ${CONFIG_SERVER_UPS} -p "{\"uri\": \"http://${SERVICE_ROUTE}.${DOMAIN}/\"}"
elif [[ ${COMPONENT} == *"zipkin"* ]]; then
# zipkin jar is downloaded, not built by us:
RUNNABLE_JAR="$(find . -name "zipkin.jar" | sed -n 1p)"
# Push zipkin server, leveraging metadata from manifest.yml
cf push \
${COMPONENT}-${UNIQUE_IDENTIFIER} \
-p ${RUNNABLE_JAR} \
-d ${DOMAIN} \
-n ${SERVICE_ROUTE} \
--no-start
RUN_RESULT=$?
cf bind-service ${COMPONENT}-${UNIQUE_IDENTIFIER} ${SERVICE_DISCOVERY_UPS}
cf restage ${COMPONENT}-${UNIQUE_IDENTIFIER}
cf start ${COMPONENT}-${UNIQUE_IDENTIFIER}
# Create a user-provided-service instance of zipkin for easier binding
CHECK_SERVICE=$(cf service ${ZIPKIN_SERVER_UPS})
if [[ "$?" == "0" ]]; then
cf delete-service -f ${ZIPKIN_SERVER_UPS}
fi
cf create-user-provided-service ${ZIPKIN_SERVER_UPS} -p "{\"uri\": \"http://${SERVICE_ROUTE}.${DOMAIN}/\"}"
elif [[ ${COMPONENT} == "netflix-hystrix-cf" ]]; then
# Hystrix Dashboard is a WAR application which uses Web Sockets.
RUNNABLE_WAR="$(find . -name "hystrix-dashboard-0.0.1.war" | sed -n 1p)"
# Push hystrix dashboard, leveraging metadata from manifest.yml
cf push \
${COMPONENT}-${UNIQUE_IDENTIFIER} \
-p ${RUNNABLE_WAR} \
-d ${DOMAIN} \
-n ${SERVICE_ROUTE} \
--no-start
RUN_RESULT=$?
cf set-env ${COMPONENT}-${UNIQUE_IDENTIFIER} SPRING_PROFILES_ACTIVE cloud
cf bind-service ${COMPONENT}-${UNIQUE_IDENTIFIER} ${ZIPKIN_SERVER_UPS}
cf bind-service ${COMPONENT}-${UNIQUE_IDENTIFIER} ${CLOUDAMQP_SERVICE}
else
# Push microservice component code, leveraging metadata from manifest.yml
cf push \
${COMPONENT}-${UNIQUE_IDENTIFIER} \
-p ${RUNNABLE_JAR} \
-d ${DOMAIN} \
-n ${SERVICE_ROUTE} \
--no-start
cf set-env ${COMPONENT}-${UNIQUE_IDENTIFIER} SPRING_PROFILES_ACTIVE cloud
cf bind-service ${COMPONENT}-${UNIQUE_IDENTIFIER} ${SERVICE_DISCOVERY_UPS}
cf bind-service ${COMPONENT}-${UNIQUE_IDENTIFIER} ${CONFIG_SERVER_UPS}
cf bind-service ${COMPONENT}-${UNIQUE_IDENTIFIER} ${ZIPKIN_SERVER_UPS}
cf bind-service ${COMPONENT}-${UNIQUE_IDENTIFIER} ${CLOUDAMQP_SERVICE}
cf start ${COMPONENT}-${UNIQUE_IDENTIFIER}
RUN_RESULT=$?
fi
if [ ${RUN_RESULT} -ne 0 ]; then
echo ${REPO}" failed to start successfully. Check logs in the local project directory for more details."
exit 1
fi
cd $SCRIPTDIR
done
cf apps