-
Notifications
You must be signed in to change notification settings - Fork 1
/
build-docker.sh
executable file
·131 lines (115 loc) · 3.29 KB
/
build-docker.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
#!/bin/bash
# Copyright (c) 2020, 2023 Carnegie Mellon University, IBM Corporation, and others
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
## termination hook
trap ctrl_c INT QUIT TERM
function ctrl_c() {
exit
}
source ./cabot-common/build-utils.sh
function help {
echo "Usage: $0 <option>"
echo "$0 [<option>] [<target>]"
echo ""
echo "-h show this help"
echo "-n no cache option to build docker image"
echo "-t <time_zone> set time zone"
echo "-u <uid> replace uid"
echo "-p prebuild images"
echo "-P <prefix> prebuild with prefix"
echo "-i build images"
echo "-w build workspace"
echo "-d debug build"
echo "Available services:"
show_available_services dcfiles
}
pwd=$(pwd)
scriptdir=$(dirname $0)
cd $scriptdir
scriptdir=$(pwd)
prefix=$(basename $scriptdir)
option="--progress=auto"
time_zone=$(cat /etc/timezone)
uid=$UID
prebuild=0
build_image=0
build_workspace=0
debug_build=0
export DOCKER_BUILDKIT=1
export COMPOSE_DOCKER_CLI_BUILD=1
while getopts "hno:t:u:pP:iwd" arg; do
case $arg in
h)
help
exit
;;
n)
option="$option --no-cache"
;;
o)
option=$OPTARG
;;
t)
time_zone=$OPTARG
;;
u)
uid=$OPTARG
;;
p)
prebuild=1
;;
P)
prebuild=1
prefix=${OPTARG}
;;
i)
build_image=1
;;
w)
build_workspace=1
;;
d)
debug_build=1
;;
esac
done
shift $((OPTIND-1))
targets=$@
if [[ $prebuild -eq 1 ]]; then
./cabot-common/prebuild_docker.sh -P $prefix -o "$option"
if [ $? != 0 ]; then exit 1; fi
fi
readarray -t dcfiles < <(ls docker-compose* | grep -v jetson | grep -v vs)
arch=$(uname -m)
if [ $arch != "x86_64" ] && [ $arch != "aarch64" ]; then
red "Unknown architecture: $arch"
exit 1
fi
if [[ $build_image -eq 1 ]]; then
build_image dcfiles targets option time_zone uid prefix arch
if [ $? != 0 ]; then exit 1; fi
fi
if [[ $build_workspace -eq 1 ]]; then
build_workspace dcfiles targets arch debug_build
if [ $? != 0 ]; then exit 1; fi
fi
if [[ $prebuild -eq 0 ]] && [[ $build_image -eq 0 ]] && [[ $build_workspace -eq 0 ]]; then
help
fi