-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpush-simulation.sh
executable file
·129 lines (110 loc) · 3.18 KB
/
push-simulation.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
##############################################################
# Licensed Materials - Property of IBM
#
# (C) Copyright IBM Corp. 2011 All rights reserved.
#
# US Government Users Restricted Rights - Use, duplication or
# disclosure restricted by GSA ADP Schedule Contract with
# IBM Corp.
###############################################################
#!/bin/sh
# Script to simulate a cf push for containers.
# Read properties
. config.cfg
# clean working directory
printf "Cleaning working directory..."
if [ -d "$WORK_DIR" ]; then
rm -rf $WORK_DIR >>log_file.log 2>&1
fi
if [ -d "artifacts" ]; then
rm -rf artifacts >>log_file.log 2>&1
fi
printf "DONE\n"
# Create artifact location
mkdir artifacts
# Copy Dockerfile into artifacts folder for container creation
cp Dockerfile artifacts
# Clone repo
printf "Cloning working directory..."
git clone $GIT_REPO >>log_file.log 2>&1
if [ $? -ne 0 ]; then
printf "\n"
printf "[ERROR]: An error has ocurred pulling the code from its GitHub repository\n"
exit 1
fi
printf "DONE\n"
# build repo
printf "Building app..."
cd $WORK_DIR
mvn clean package >>log_file.log 2>&1
if [ $? -ne 0 ]; then
printf "\n"
printf "[ERROR]: An error has ocurred building the app\n"
exit 1
fi
cd ..
printf "DONE\n"
# Grab artifacts needed during container creation
#for artifact in $ARTIFACT_LIST
#do
#cp $artifact artifacts
#done
printf "Copying build output..."
cp $WORK_DIR/$ARTIFACT_LIST artifacts
BUILD_OUTPUT=`basename $ARTIFACT_LIST`
mv artifacts/$BUILD_OUTPUT artifacts/app.jar
printf "DONE\n"
# Bluemix login
. $BMX_CREDENTIALS_FILE
. $BMX_PASS_FILE
printf "Logging into Bluemix..."
cf login -a $BMX_API -o $BMX_ORG -s $BMX_SPACE -u $BMX_USER -p $BMX_PASS >>log_file.log 2>&1
if [ $? -ne 0 ]; then
printf "\n"
printf "[ERROR]: An error has ocurred logging into Bluemix\n"
exit 1
fi
printf "DONE\n"
# Container service login
printf "Initializing Bluemix containers..."
cf ic init >>log_file.log 2>&1
if [ $? -ne 0 ]; then
printf "\n"
printf "[ERROR]: An error has ocurred initializing Bluemix containers\n"
exit 1
fi
printf "DONE\n"
# Build container in Bluemix
cd artifacts
printf "Building the container in Bluemix..."
cf ic build -t $BMX_REGISTRY/$BMX_NAMESPACE/$CONTAINER_IMAGE:latest . >>log_file.log 2>&1
if [ $? -ne 0 ]; then
printf "\n"
printf "[ERROR]: An error has ocurred building the container\n"
exit 1
fi
printf "DONE\n"
# Spin up conatiner group
printf "Spinning up the container in a container group in Bluemix..."
CONTAINER_GROUP_ID=`cf ic group create --name $CONTAINER_GROUP_NAME -p 8180 -m 256 --min 1 --max 2 --desired 1 $BMX_REGISTRY/$BMX_NAMESPACE/$APP_NAME:latest | grep id | sed 's/^.*id: //g' | sed 's/).*$//g'`
if [ $? -ne 0 ]; then
printf "\n"
printf "[ERROR]: An error has ocurred spinning up the container\n"
exit 1
fi
printf "DONE\n"
# Wait for the container group creation to finish
ITERATION=0
while [[ `cf ic group list | grep $CONTAINER_GROUP_ID | grep COMPLETE | wc -l` -ne 1 && $ITERATION -lt 10 ]]
do
ITERATION=$((ITERATION + 1))
sleep 10
done
if [ $ITERATION -eq 10 ]
then
echo "An error has occured while creating the container group"
exit 1
fi
exit 0
# Create public route
# Map public route to the container group