forked from lf-edge/edge-home-orchestration-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·586 lines (535 loc) · 17.2 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
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
#! /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/sigmgr"
"common/types/configuremgrtypes"
"common/types/servicemgrtypes"
"controller/configuremgr"
"controller/configuremgr/container"
"controller/configuremgr/native"
"controller/discoverymgr"
"controller/discoverymgr/wrapper"
"controller/scoringmgr"
"controller/securemgr/verifier"
"controller/securemgr/authenticator"
"controller/servicemgr"
"controller/servicemgr/executor"
"controller/servicemgr/executor/androidexecutor"
"controller/servicemgr/executor/containerexecutor"
"controller/servicemgr/executor/nativeexecutor"
"controller/servicemgr/notification"
"controller/mnedcmgr"
"controller/mnedcmgr/client"
"controller/mnedcmgr/connectionutil"
"controller/mnedcmgr/server"
"controller/mnedcmgr/tunmgr"
"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 set_mnedc_server_option() {
echo ""
echo "-----------------------------------"
echo " Set tags for start mnedc server"
echo "-----------------------------------"
if [ "$1" == "secure" ]; then
export BUILD_TAGS="securemnedcserver"
else
export BUILD_TAGS="mnedcserver"
fi
}
function set_mnedc_client_option() {
echo ""
echo "-----------------------------------"
echo " Set tags for start mnedc client"
echo "-----------------------------------"
if [ "$1" == "secure" ]; then
export BUILD_TAGS="securemnedcclient"
else
export BUILD_TAGS="mnedcclient"
fi
}
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"
"github.com/dgrijalva/jwt-go"
)
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_binaries() {
echo ""
echo ""
echo "**********************************"
echo " Target Binary arch is "$1
echo "**********************************"
case $1 in
x86)
export GOARCH=386
export ARCH=x86
;;
x86_64)
export GOARCH=amd64
export ARCH=x86-64
;;
arm)
export GOARCH=arm GOARM=7
export ARCH=arm
;;
arm64)
export GOARCH=arm64
export ARCH=aarch64
;;
*)
echo "Target arch isn't supported" && exit 1
;;
esac
build_binary
}
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_objects() {
case $1 in
x86)
build_object_x86
export ANDROID_TARGET="android/386";;
x86_64)
build_object_x86-64
export ANDROID_TARGET="android/amd64";;
arm)
build_object_arm
export ANDROID_TARGET="android/arm";;
arm64)
build_object_aarch64
export ANDROID_TARGET="android/arm64";;
*)
build_object_x86
build_object_x86-64
build_object_arm
build_object_aarch64
export ANDROID_TARGET="android";;
esac
build_android
}
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
case $1 in
x86)
CONTAINER_ARCH="i386"
;;
x86_64)
CONTAINER_ARCH="amd64"
;;
arm)
CONTAINER_ARCH="arm32v7"
;;
arm64)
CONTAINER_ARCH="arm64v8"
;;
*)
case "$(uname -m)" in
"i386"|"i686")
CONTAINER_ARCH="i386"
;;
"x86_64")
CONTAINER_ARCH="amd64"
;;
"armv7l")
CONTAINER_ARCH="arm32v7"
;;
"aarch64")
CONTAINER_ARCH="arm64v8"
;;
*)
echo "Target arch isn't supported" && exit 1
;;
esac
;;
esac
make build-container CONTAINER_ARCH=$CONTAINER_ARCH || 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
sudo mkdir -p /var/edge-orchestration/mnedc
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")
install_prerequisite
install_3rdparty_packages
if [ "$2" == "secure" ]; then
set_secure_option
build_binaries $3
build_docker_container $3
docker save -o $BASE_DIR/GoMain/bin/edge-orchestration.tar edge-orchestration
if [ "$3" == "x86_64" ]; then
run_docker_container
fi
else
build_binaries $2
build_docker_container $2
docker save -o $BASE_DIR/GoMain/bin/edge-orchestration.tar edge-orchestration
if [ "$2" == "x86_64" ]; then
run_docker_container
fi
fi
;;
"object")
case "$2" in
"secure")
if [ "$3" == "mnedcserver" ]; then
set_mnedc_server_option $2
elif [ "$3" == "mnedcclient" ]; then
set_mnedc_client_option $2
elif [ "$3" == "" ]; then
set_secure_option
fi
;;
"mnedcserver")
set_mnedc_server_option $3
;;
"mnedcclient")
set_mnedc_client_option $3
;;
esac
install_prerequisite
install_3rdparty_packages
build_clean
if [ "$2" == "secure" ]; then
build_objects $3
else
build_objects $2
fi
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
;;
"mnedcserver")
set_mnedc_server_option $2
install_prerequisite
install_3rdparty_packages
build_binary
build_docker_container
run_docker_container
;;
"mnedcclient")
set_mnedc_client_option $2
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 Docker container"
echo " $0 secure : build edge-orchestration by default Docker container with secure option"
echo " $0 container [Arch] : build Docker container Arch:{x86, x86_64, arm, arm64}"
echo " $0 container secure [Arch] : build Docker container with secure option Arch:{x86, x86_64, arm, arm64}"
echo " $0 object [Arch] : build object (c-object, java-object), Arch:{x86, x86_64, arm, arm64} (default:all)"
echo " $0 object secure [Arch] : build object (c-object, java-object) with secure option, Arch:{x86, x86_64, arm, arm64} (default:all)"
echo " $0 mnedcserver : build edge-orchestration by default container with MNEDC server running option"
echo " $0 mnedcserver secure : build edge-orchestration by default container with MNEDC server running option in secure mode"
echo " $0 mnedcclient : build edge-orchestration by default container with MNEDC client running option"
echo " $0 mnedcclient secure : build edge-orchestration by default container with MNEDC client running option in secure mode"
echo " $0 clean : build clean"
echo " $0 test [PKG_NAME] : run unittests (optional for PKG_NAME)"
echo "-------------------------------------------------------------------------------------------------------------------------------------------"
exit 0
;;
esac
build_clean_vendor