-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·419 lines (374 loc) · 12 KB
/
build.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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
#! /bin/bash
export BASE_DIR=$( cd "$(dirname "$0")" ; pwd )
export BUILD_TAGS=""
DOCKER_IMAGE="edge-orchestration"
BINARY_FILE="edge-orchestration"
PKG_LIST=(
"common/errormsg"
"common/errors"
"common/logmgr"
"common/networkhelper"
"common/networkhelper/detector"
"common/resourceutil"
"common/resourceutil/cpu"
"common/resourceutil/native"
"common/resourceutil/types/servicemgrtypes"
"common/types/configuremgrtypes"
"common/types/servicemgrtypes"
"controller/configuremgr"
"controller/configuremgr/container"
"controller/configuremgr/native"
"controller/discoverymgr"
"controller/discoverymgr/wrapper"
"controller/scoringmgr"
"controller/servicemgr"
"controller/servicemgr/executor"
"controller/servicemgr/executor/androidexecutor"
"controller/servicemgr/executor/containerexecutor"
"controller/servicemgr/executor/nativeexecutor"
"controller/servicemgr/notification"
"db/bolt/common"
"db/bolt/configuration"
"db/bolt/network"
"db/bolt/resource"
"db/bolt/service"
"db/bolt/system"
"db/bolt/wrapper"
"db/helper"
"interfaces/capi"
"interfaces/javaapi"
"orchestrationapi"
"restinterface"
"restinterface/cipher"
"restinterface/cipher/dummy"
"restinterface/cipher/sha256"
"restinterface/client"
"restinterface/client/restclient"
"restinterface/externalhandler"
"restinterface/internalhandler"
"restinterface/resthelper"
"restinterface/route"
)
export CONTAINER_VERSION="baobab"
export BUILD_DATE=$(date +%Y%m%d.%H%M)
function set_secure_option() {
echo ""
echo "-----------------------------------"
echo " Set tags for secure build"
echo "-----------------------------------"
export BUILD_TAGS="secure"
}
function install_3rdparty_packages() {
echo ""
echo "-----------------------------------"
echo " Install 3rd-party packages"
echo "-----------------------------------"
### Install glide on Ubuntu
### sudo add-apt-repository -y ppa:masterminds/glide && sudo apt-get update
### sudo apt-get install -y glide
### glide update
glide install
### Set GOPATH and link of vendor directory
export GOPATH=$BASE_DIR:$BASE_DIR/vendor:$GOPATH
ORG_VENDOR_DIR='vendor'
CUR_VENDOR_DIR='vendor/src'
if [ ! -d $BASE_DIR/$CUR_VENDOR_DIR ]; then
ln -s $BASE_DIR/$ORG_VENDOR_DIR $BASE_DIR/$CUR_VENDOR_DIR
fi
###apply patch of zeroconf
git apply --directory=$ORG_VENDOR_DIR/github.com/grandcat/zeroconf $BASE_DIR/src/controller/discoverymgr/wrapper/zeroconfEdgeOrchestration.patch
### Exception case from package dependencies
rm -rf $BASE_DIR/vendor/github.com/docker/distribution/vendor/github.com/opencontainers
rm -rf $BASE_DIR/vendor/github.com/docker/docker/vendor/github.com/docker/go-connections/nat
}
function install_prerequisite() {
echo ""
echo "-----------------------------------"
echo " Install prerequisite packages"
echo "-----------------------------------"
pkg_list=(
"github.com/axw/gocov/gocov"
"github.com/matm/gocov-html"
"golang.org/x/lint/golint"
"github.com/Songmu/make2help/cmd/make2help"
"golang.org/x/mobile/cmd/gomobile"
"golang.org/x/mobile/cmd/gobind"
)
idx=1
for pkg in "${pkg_list[@]}"; do
echo -ne "(${idx}/${#pkg_list[@]}) go get -u $pkg"
go get -u $pkg
if [ $? -ne 0 ]; then
echo -e "\n\033[31m"download fail"\033[0m"
exit 1
fi
echo ": Done"
idx=$((idx+1))
done
}
function build_clean() {
echo ""
echo "-----------------------------------"
echo " Build clean"
echo "-----------------------------------"
make clean
}
function build_binary() {
echo ""
echo "----------------------------------------"
echo " Create Executable binary from GoMain"
echo "----------------------------------------"
export GOPATH=$BASE_DIR/GoMain:$GOPATH
make build-binary || exit 1
}
function build_object() {
echo ""
echo "----------------------------------------"
echo " Create Static object of Orchestration"
echo "----------------------------------------"
make build-object-c || exit 1
}
function build_test() {
echo ""
echo "-------------------------------------"
echo " Build test to calculate Coverage"
echo "-------------------------------------"
export GOARCH=amd64
export CC="gcc"
sudo systemctl stop ${SERVICE_FILE}
sudo systemctl status ${SERVICE_FILE}
mkdir -p /tmp/foo
stop_docker_container
if [[ $1 == "" ]]; then
echo ""
echo "---------------------------"
echo " build test for ALL pkgs"
echo "---------------------------"
make test-go TEST_PKG_DIRS=./src/...
else
idx=0
for pkg in "${PKG_LIST[@]}"; do
if [[ "$pkg" == *"$1"* ]]; then
break
fi
idx=$((idx+1))
done
if [ $idx -ge ${#PKG_LIST[@]} ]; then
echo ""
echo " ERROR!!! There is no package for $1"
else
echo "---------------------------------------"
echo " build test for ${PKG_LIST[$idx]}"
echo "---------------------------------------"
make test-go TEST_PKG_DIRS=${PKG_LIST[$idx]}
fi
fi
}
function lint_src_code() {
echo ""
echo "---------------------------------------"
echo " Analysis source code golint & go vet"
echo "---------------------------------------"
make lint
}
function draw_callvis() {
echo ""
echo "**********************************"
echo " Draw Call Graph "
echo " 1) Install go-callvis"
echo " $ go get -u github.com/TrueFurby/go-callvis"
echo " $ cd \$GOPATH/src/github.com/TrueFurby/go-callvis && make"
echo " 2) To use this, do comment last line of build.sh"
echo " ex) #build_clean_vendor "
echo "**********************************"
export GOPATH=$BASE_DIR/GoMain:$GOPATH
go-callvis -http localhost:7010 -group pkg,type -nostd ./GoMain/src/main/main.go &
}
function build_object_x86() {
echo ""
echo ""
echo "**********************************"
echo " Target Binary arch is i386 "
echo "**********************************"
export GOARCH=386
export CC="gcc"
export ARCH=x86
build_object
}
function build_object_x86-64() {
echo ""
echo ""
echo "**********************************"
echo " Target Binary arch is amd64 "
echo "**********************************"
export GOARCH=amd64
export CC="gcc"
export ARCH=x86-64
build_object
}
function build_object_arm() {
echo ""
echo ""
echo "**********************************"
echo " Target Binary arch is armv7 "
echo "**********************************"
export GOARCH=arm GOARM=7
export CC="arm-linux-gnueabi-gcc"
export ARCH=arm
build_object
}
function build_object_aarch64() {
echo ""
echo ""
echo "**********************************"
echo " Target Binary arch is arm64 "
echo "**********************************"
export GOARCH=arm64
export CC="aarch64-linux-gnu-gcc"
export ARCH=aarch64
build_object
}
function build_object_result() {
echo ""
echo ""
echo "**********************************"
echo " Edge-orchestration Archive "
echo "**********************************"
make build-result
}
function build_clean_vendor() {
echo ""
echo "-------------------------------------"
echo " Clean up 3rdParty directory"
echo "-------------------------------------"
make clean-tmp-packages
}
function build_android() {
echo ""
echo "**********************************"
echo " Target Binary is for Android "
echo "**********************************"
echo ""
echo "-------------------------------------------"
echo " Create Android archive from Java interface"
echo "-------------------------------------------"
make build-object-java || exit 1
}
function build_docker_container() {
echo ""
echo ""
echo "**********************************"
echo " Create Docker container "
echo "**********************************"
docker rm -f $DOCKER_IMAGE
docker rmi -f $DOCKER_IMAGE:$CONTAINER_VERSION
make build-container || exit 1
}
function run_docker_container() {
### Add temporarily, TO DO: move files into container
echo ""
echo "--------------------------------------------"
echo " Create prerequisite Folder [SuperUser]"
echo "--------------------------------------------"
sudo mkdir -p /var/edge-orchestration/log
sudo mkdir -p /var/edge-orchestration/apps
sudo mkdir -p /var/edge-orchestration/data/db
sudo mkdir -p /var/edge-orchestration/data/cert
sudo mkdir -p /var/edge-orchestration/user
sudo mkdir -p /var/edge-orchestration/device
echo ""
echo "**********************************"
echo " Run Docker container "
echo "**********************************"
docker run -it -d \
--privileged \
--network="host" \
--name $DOCKER_IMAGE \
-v /var/edge-orchestration/:/var/edge-orchestration/:rw \
-v /var/run/docker.sock:/var/run/docker.sock:rw \
-v /proc/:/process/:ro \
$DOCKER_IMAGE:$CONTAINER_VERSION
docker container ls
}
function stop_docker_container() {
echo ""
echo "**********************************"
echo " Stop Docker container "
echo "**********************************"
docker stop $DOCKER_IMAGE
docker ps -a
}
case "$1" in
"container")
if [ "$2" == "secure" ]; then
set_secure_option
fi
install_prerequisite
install_3rdparty_packages
build_binary
build_docker_container
run_docker_container
;;
"object")
if [ "$2" == "secure" ]; then
set_secure_option
fi
install_prerequisite
install_3rdparty_packages
build_clean
build_android
build_object_x86
build_object_aarch64
build_object_arm
build_object_x86-64
build_object_result
;;
"test")
install_prerequisite
install_3rdparty_packages
build_test $2
;;
"lint")
install_prerequisite
install_3rdparty_packages
lint_src_code
;;
"callvis")
install_3rdparty_packages
draw_callvis
;;
"clean")
build_clean
;;
"")
install_prerequisite
install_3rdparty_packages
build_binary
build_docker_container
run_docker_container
;;
"secure")
set_secure_option
install_prerequisite
install_3rdparty_packages
build_binary
build_docker_container
run_docker_container
;;
*)
echo "build script"
echo "Usage:"
echo "----------------------------------------------------------------------------------------------"
echo " $0 : build edge-orchestration by default container"
echo " $0 secure : build edge-orchestration by default container with secure option"
echo " $0 container : build Docker container as build system environmet"
echo " $0 container secure : build Docker container as build system environmet with secure option"
echo " $0 object : build object (c-object, java-object)"
echo " $0 object secure : build object (c-object, java-object) with secure option"
echo " $0 clean : build clean"
echo " $0 test [PKG_NAME] : run unittests (optional for PKG_NAME)"
echo "----------------------------------------------------------------------------------------------"
exit 0
;;
esac
build_clean_vendor