-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuilder.sh
95 lines (83 loc) · 2.21 KB
/
builder.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
#!/bin/bash
# set -o pipefail
#
set -e
deps=""
buildcmd=""
workingdir=""
dockerimagename=zhijzhao/raspbian
usage ()
{
echo "build.sh [options]"
echo "options"
echo " --deplibs dependent libraries"
echo " --cmd <string> build command"
echo " --workingdir <folder> working directory on host which user code exists"
exit 1
}
process_args ()
{
save_next_arg=0
for arg in "$@"
do
if [ $save_next_arg == 1 ]
then
# save dependencies
deps=$arg
save_next_arg=0
elif [ $save_next_arg == 2 ]
then
# save build command
buildcmd=$arg
save_next_arg=0
elif [ $save_next_arg == 3 ]
then
#save working dir
workingdir=$arg
save_next_arg=0
else
case "$arg" in
"--deplibs" ) save_next_arg=1;;
"--cmd" ) save_next_arg=2;;
"--workingdir" ) save_next_arg=3;;
* ) usage;;
esac
fi
done
}
process_args "$@"
# configure workingdir as docker sharing folder
dockervoption=""
if [ "$workingdir" != "" ]; then
workingdir=$(echo $workingdir | sed 's/\\/\//g')
dockervoption="-v $workingdir:/source/"
fi
#install dependencies libs to docker images
echo -----------------------------
echo Step 1 pull docker image $dockerimagename and run it
echo -----------------------------
winpty docker pull $dockerimagename
containerid="$(docker run -it -d $dockervoption $dockerimagename)"
echo containderid $containerid
if [ "$deps" != "" ]; then
echo -----------------------------
echo Step 2 install dependencies: $deps
echo -----------------------------
#winpty docker exec -it $containerid apt-get update
installibs="winpty docker exec -it $containerid apt-get install $deps"
$installibs
fi
# run build command inside docker
if [ "$buildcmd" != "" ]; then
echo -----------------------------
echo Step 3 run command: $buildcmd
echo -----------------------------
shcmd="cd /source && $buildcmd"
winpty docker exec -it $containerid /bin/sh -c "$shcmd"
fi
if [ $? -eq 0 ]; then
echo application build succeeded!
else
echo application build failed!
exit $?
fi