Debian Codegraph @

dockerfiles/build.sh

raw symbols SCIP
1 #!/bin/bashscip-shell filesystem . . `/bin/bash`.
2
3 export DOCKER_BUILDKIT=1
4 : "${IMAGE_PREFIX:=docker.io/labgrid/}"
5 : "${IMAGE_TAG:=latest}"
6
7 diescip-shell shell shell-project 0.0.0 die(). () {
8 local msg
9 msg="${1}"
10
11 echoscip-shell system . . echo. "[fatal] ${msg}" >&2
12 exit 1
13 }
14
15 log_infoscip-shell shell shell-project 0.0.0 log_info().() {
16 local msg
17 msg="${1}"
18
19 echoscip-shell system . . echo. "[info] ${msg}"
20 }
21
22 has_dockerscip-shell shell shell-project 0.0.0 has_docker().() {
23 command -v docker >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1
24 }
25
26 has_podmanscip-shell shell shell-project 0.0.0 has_podman().() {
27 command -v podman >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1
28 }
29
30 has_buildxscip-shell shell shell-project 0.0.0 has_buildx().() {
31 local docker_cmd
32 docker_cmd="${1}"
33
34 "${docker_cmd}" buildx version >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1
35 }
36
37 get_docker_cmdscip-shell shell shell-project 0.0.0 get_docker_cmd().() {
38 local docker_cmd
39 docker_cmd="${1}"
40
41 if [scip-shell system . . `[`. -n "${docker_cmd}" ]; then
42 echoscip-shell system . . echo. "${docker_cmd}"
43 return
44 fi
45
46 if has_dockerscip-shell shell shell-project 0.0.0 has_docker().; then
47 echoscip-shell system . . echo. "docker"
48 else
49 echoscip-shell system . . echo. "podman"
50 fi
51 }
52
53 perform_regular_buildscip-shell shell shell-project 0.0.0 perform_regular_build().() {
54 local docker_cmd script_dir version
55 docker_cmd="${1}"
56 script_dir="${2}"
57 version="${3}"
58 extra_args=("${@:4}")
59
60 log_infoscip-shell shell shell-project 0.0.0 log_info(). "building for native platform only."
61
62 for t in client exporter coordinator coordinator-statsd; do
63 "${docker_cmd}" build --build-arg VERSION="${version}" \
64 --target labgrid-${t} -t "${IMAGE_PREFIX}${t}:${IMAGE_TAG}" -f "${script_dir}/Dockerfile" \
65 "${extra_args[@]}" .
66 done
67 }
68
69 perform_docker_buildx_buildscip-shell shell shell-project 0.0.0 perform_docker_buildx_build().() {
70 local docker_cmd script_dir version
71 docker_cmd="${1}"
72 script_dir="${2}"
73 version="${3}"
74 extra_args=("${@:4}")
75
76 for t in client exporter coordinator coordinator-statsd; do
77 "${docker_cmd}" buildx build --build-arg VERSION="${version}" \
78 --target labgrid-${t} -t "${IMAGE_PREFIX}${t}:${IMAGE_TAG}" -f "${script_dir}/Dockerfile" \
79 "${extra_args[@]}" .
80 done
81 }
82
83 mainscip-shell shell shell-project 0.0.0 main().() {
84 local script_dir version
85
86 if ! has_dockerscip-shell shell shell-project 0.0.0 has_docker(). && ! has_podmanscip-shell shell shell-project 0.0.0 has_podman().; then
87 diescip-shell shell shell-project 0.0.0 die(). "Neither docker nor podman could be found."
88 fi
89
90 script_dir="$(dirnamescip-shell system . . dirname. "$(realpathscip-shell system . . realpath. "${BASH_SOURCE:-$0}")")"
91 version="$(python -m setuptools_scm)"
92 docker_cmd="$(get_docker_cmdscip-shell shell shell-project 0.0.0 get_docker_cmd(). "${DOCKER}")"
93
94 cd "${script_dir}/.." || diescip-shell shell shell-project 0.0.0 die(). "Could not cd into repo root dir"
95
96 if has_buildxscip-shell shell shell-project 0.0.0 has_buildx(). "${docker_cmd}"; then
97 perform_docker_buildx_buildscip-shell shell shell-project 0.0.0 perform_docker_buildx_build(). "${docker_cmd}" "${script_dir}" "${version}" "${@}"
98 else
99 perform_regular_buildscip-shell shell shell-project 0.0.0 perform_regular_build(). "${docker_cmd}" "${script_dir}" "${version}" "${@}"
100 fi
101 }
102
103 mainscip-shell shell shell-project 0.0.0 main(). "${@}"