forked from hailo-ai/tappas
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild_docker.sh
executable file
·106 lines (93 loc) · 3.85 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
#!/bin/bash
# Build docker must be in the parent directory. Otherwise copying the whole directory tree is not allowed
set -e
readonly platform_dir="release"
readonly dockerfile_dir="docker"
readonly dockerfile_tappas_base="Dockerfile.tappas_base"
readonly dockerfile_tappas="Dockerfile.tappas"
tag=latest
flags=""
gst_hailo_build_mode=release
target_platform="x86"
ubuntu_version="20.04"
gcc_version="12"
install_vaapi=false
function print_usage() {
echo "Run Hailo Docker:"
echo ""
echo "Options:"
echo " --help Show this help"
echo " --no-cache Build Docker without cache"
echo " --build-mode Build mode for Hailo's GStreamer elements - release/debug (Default is $gst_hailo_build_mode)"
echo " --target-platform Target platform [x86, arm, imx8, rpi(raspberry pi), hailo15], used for downloading only required media and hef files (Default is $target_platform)"
echo " --tag The selected tag, default is - $tag"
echo " --ubuntu-version Ubuntu version of the docker [20.04 / 21.04 / 22.04] - Default is $ubuntu_version"
echo " --install-vaapi Whether the Docker should be build VA-API as well"
exit 1
}
function check_docker_version() {
# https://stackoverflow.com/a/72057185/5708016
if [[ "${ubuntu_version}" == "22.04" ]]; then
docker_version=$(docker version --format '{{.Server.Version}}')
# Docker version could be x.y.z or x.y.z-beta.a
# This awk with multiple delimiters support them both
docker_version_major=$(echo "$docker_version" | awk -F'[.-]' '{print $1}')
docker_version_minor=$(echo "$docker_version" | awk -F'[.-]' '{print $2}')
docker_version_build=$(echo "$docker_version" | awk -F'[.-]' '{print $3}')
if [ "${docker_version_major}" -lt 20 ] &&
[ "${docker_version_minor}" -lt 10 ] &&
[ "${docker_version_build}" -lt 9 ]; then
echo "Docker version $docker_version is less than 20.10.9, can't build Ubuntu 22.04"
exit 1
fi
fi
}
function parse_args() {
while test $# -gt 0; do
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
print_usage
elif [ "$1" == "--no-cache" ]; then
flags="--no-cache"
elif [ "$1" == "--build-mode" ]; then
gst_hailo_build_mode=$2
shift
elif [ "$1" == "--target-platform" ]; then
target_platform=$2
if [ "$target_platform" == "rpi" ]; then
gcc_version="9"
fi
shift
elif [ "$1" == "--tag" ]; then
tag=$2
shift
elif [ "$1" == "--ubuntu-version" ]; then
ubuntu_version="$2"
shift
if [[ "${ubuntu_version}" != @(20.04|21.04|22.04) ]]; then
echo "Ubuntu version provided is not supported: $ubuntu_version"
print_usage
fi
if [[ "${ubuntu_version}" == 20.04 ]]; then
gcc_version="9"
fi
check_docker_version
elif [ "$1" == "--install-vaapi" ]; then
install_vaapi=true
else
echo "Unknown parameters, exiting"
print_usage
fi
shift
done
}
parse_args "$@"
# BuildKit is an improved backend to replace the legacy builder
export DOCKER_BUILDKIT=1
docker build $flags -f ${dockerfile_dir}/${dockerfile_tappas_base} -t hailo_tappas_base:"$tag" \
--build-arg ubuntu_version="$ubuntu_version" \
--build-arg skip_headers_install="$skip_headers_install" .
docker build $flags -f ${dockerfile_dir}/${dockerfile_tappas} -t hailo_tappas:"$tag" \
--build-arg gcc_version="$gcc_version" \
--build-arg target_platform="$target_platform" \
--build-arg gst_hailo_build_mode="$gst_hailo_build_mode" \
--build-arg install_vaapi=$install_vaapi .