-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.sh
More file actions
160 lines (130 loc) · 4.19 KB
/
build.sh
File metadata and controls
160 lines (130 loc) · 4.19 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
#!/bin/sh
#
#Copyright 2019 VMware, Inc.
#SPDX-License-Identifier: BSD-2-Clause
#
#####define all path
CURRENTPATH=`pwd` #make
OUTPUTJARFILESNUM=9
UIDISTFILENUM=18
TIMEOUTSECOND=600
BUILDLOG=$CURRENTPATH/build-log
SOURCECODEDIR=$CURRENTPATH/../../flowgate
OUTPUTJARPATH=$CURRENTPATH/jar-output
OUTPUTIMAGEPATH=$CURRENTPATH/docker-images-output
DOCKERMAVENBUILD=$CURRENTPATH/maven-docker-build
FLOWGATEIMAGESTAR=$OUTPUTIMAGEPATH/flowgate.tar
DOCKERCOMPOSEBUILDIMAGESFILE=$DOCKERMAVENBUILD/docker-compose.build.images.yml
DOCKERCOMPOSEBUILDJARFILE=$DOCKERMAVENBUILD/docker-compose.build.jar.yml
DOCKERCOMPOSERUNFILE=$DOCKERMAVENBUILD/docker-compose.run.images.yml
CONFTAR=$CURRENTPATH/conf.tar.gz
APACHERESOURCEDIR=/var/www/html
#####set version
if [[ $2 == '-version' ]]; then
INPUT=$3
FLOWGATE_VERSION=${INPUT:=v1.0}
echo $FLOWGATE_VERSION
else
echo "eg. 'bash build.sh ( ui | jar | image | save | copy2server | all ) -version v1.0'"
exit 0
fi
sed -i -e "s/FLOWGATE_VERSION/$FLOWGATE_VERSION/g" $DOCKERCOMPOSEBUILDIMAGESFILE
sed -i -e "s/FLOWGATE_VERSION/$FLOWGATE_VERSION/g" $DOCKERCOMPOSERUNFILE
sed -i -e "s/FLOWGATE_VERSION/$FLOWGATE_VERSION/g" $DOCKERCOMPOSEBUILDJARFILE
buildUi(){
echo "build UI..."
cd $SOURCECODEDIR/ui/
wget https://nodejs.org/dist/v11.2.0/node-v11.2.0-linux-x64.tar.gz
tar zxvf node-v11.2.0-linux-x64.tar.gz
export PATH=$PATH:$PWD/node-v11.2.0-linux-x64/bin
npm install -g @angular/cli@latest
npm install --unsafe-perm
ng build -prod -aot=false
}
buildAllJars(){
echo "build all project jar..."
if [ ! -d "$OUTPUTJARPATH" ];then
mkdir $OUTPUTJARPATH
else
rm $OUTPUTJARPATH/* -rf
fi
cd $CURRENTPATH
docker-compose -f $DOCKERCOMPOSEBUILDJARFILE build --force-rm --no-cache
docker-compose -f $DOCKERCOMPOSEBUILDJARFILE up -d
#####check jar-output finish or not
filesnum=`ls $OUTPUTJARPATH | wc -w`
currtime=`date "+%s"`
while(( $filesnum < $OUTPUTJARFILESNUM ))
do
sleep 1
filesnum=`ls $OUTPUTJARPATH | wc -w`
nowtime=`date "+%s"`
if [ $((nowtime-currtime)) -gt $TIMEOUTSECOND ]
then
echo "error. timeout. maybe build jar fault"
exit -1
fi
done
}
buildDockerImages(){
echo "build docker images..."
docker rm maven-build-container -f
docker rmi flowgate/vro-worker:$FLOWGATE_VERSION flowgate/vc-worker:$FLOWGATE_VERSION flowgate/nlyte-worker:$FLOWGATE_VERSION \
flowgate/management:$FLOWGATE_VERSION flowgate/infoblox-worker:$FLOWGATE_VERSION flowgate/labsdb-worker:$FLOWGATE_VERSION \
flowgate/poweriq-worker:$FLOWGATE_VERSION flowgate/aggregator:$FLOWGATE_VERSION flowgate/api:$FLOWGATE_VERSION \
flowgate/redis:$FLOWGATE_VERSION flowgate/mongodb:$FLOWGATE_VERSION maven-build:$FLOWGATE_VERSION
if [ ! -d "$OUTPUTIMAGEPATH" ];then
mkdir $OUTPUTIMAGEPATH
else
rm $OUTPUTIMAGEPATH/* -rf
fi
jarname=("flowgate-api" "vro-worker" "nlyte-worker" "poweriq-worker" "management" "infoblox-worker" "aggregator" "vc-worker" "labsdb-worker")
for j in "${jarname[@]}"
do
cp $OUTPUTJARPATH/$j-0.0.1-SNAPSHOT.jar $CURRENTPATH/$j
done
cd $CURRENTPATH
docker-compose -f $DOCKERCOMPOSEBUILDIMAGESFILE build --force-rm --no-cache
}
saveDockerImages(){
echo "save docker images..."
if [ -f "$FLOWGATEIMAGESTAR" ];then
rm -f $FLOWGATEIMAGESTAR
fi
docker save flowgate/vro-worker:$FLOWGATE_VERSION flowgate/vc-worker:$FLOWGATE_VERSION flowgate/nlyte-worker:$FLOWGATE_VERSION \
flowgate/management:$FLOWGATE_VERSION flowgate/infoblox-worker:$FLOWGATE_VERSION flowgate/labsdb-worker:$FLOWGATE_VERSION \
flowgate/poweriq-worker:$FLOWGATE_VERSION flowgate/aggregator:$FLOWGATE_VERSION flowgate/api:$FLOWGATE_VERSION \
flowgate/redis:$FLOWGATE_VERSION flowgate/mongodb:$FLOWGATE_VERSION >> $FLOWGATEIMAGESTAR
}
copyResourceToServer(){
echo "copy all resource to apache server..."
cp $DOCKERCOMPOSERUNFILE $FLOWGATEIMAGESTAR $CONFTAR $APACHERESOURCEDIR
}
case $1 in
"ui")
buildUi
;;
"jar")
buildAllJars
;;
"image")
buildDockerImages
;;
"save")
saveDockerImages
;;
"copy2server")
copyResourceToServer
;;
"all")
buildUi
buildAllJars
buildDockerImages
saveDockerImages
copyResourceToServer
echo "build success."
;;
*)
echo "bash build.sh ( ui | jar | image | save | copy2server | all ) -version v1.0"
;;
esac