forked from roc-streaming/dockerfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmake.sh
More file actions
executable file
·148 lines (125 loc) · 3.47 KB
/
make.sh
File metadata and controls
executable file
·148 lines (125 loc) · 3.47 KB
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
#!/usr/bin/env bash
set -euo pipefail
run_cmd() {
dry_run="$1"
shift
echo "-- $*"
if [ "$dry_run" = 0 ]; then
"$@" || exit 1
fi
}
help() {
echo "Usage: $0 [OPTIONS...] [IMAGE[:TAG]...]"
echo
echo " -n, --dry-run don't run commands, just print them"
echo " -p, --push push image after building"
echo " -C, --no-cache pass --no-cache to docker build"
echo " -P, --no-pull don't pass --pull to docker build"
echo " -h, --help print this message"
echo
}
dry_run=0
no_cache=0
no_pull=0
enable_push=0
while [ "${1:-}" != "" ]; do
case "$1" in
"-h"|"--help")
help
exit
;;
"-n"|"--dry-run")
dry_run=1
;;
"-p"|"--push")
enable_push=1
;;
"-C"|"--no-cache")
no_cache=1
;;
"-P"|"--no-pull")
no_pull=1
;;
*)
break
;;
esac
shift
done
cd "$(dirname "$0")"
if [ -z "${1:-}" ]; then
ls -1 images | sort
else
for image in "$@"; do
echo "$image"
done
fi | while read image; do
if echo "$image" | grep -qF ":"; then
image_shortname="$(echo "$image" | cut -d: -f1)"
image_tag="$(echo "$image" | cut -d: -f2)"
else
image_shortname="$image"
image_tag=""
fi
image_fullname="rocstreaming/$image_shortname"
image_dir="images/$image_shortname"
pushd "$image_dir" >/dev/null
{ cat images.csv; echo; } | grep '\S' | {
read header
while IFS=";" read -r dockerfile args tag; do
if [ -z "$dockerfile" ]; then
dockerfile="Dockerfile"
fi
if [ -z "$tag" ]; then
tag="$(cut -d "/" -f1 <<< "$dockerfile")"
fi
if [ ! -z "$image_tag" ] && [ "$tag" != "$image_tag" ]; then
continue
fi
context="."
depth="$(awk -F"/" '{print NF-1}' <<< "$dockerfile")"
if [ "$depth" != "0" ]; then
context="$(cut -d "/" -f1 <<< "$dockerfile")"
fi
printf '%s \033[1;35mprocessing image %s\033[0m\n' \
"--" "$image_fullname:$tag"
build_args=()
if [ "$no_pull" = 0 ]; then
build_args+=(
--pull
)
fi
if [ "$no_cache" = 1 ]; then
build_args+=(
--no-cache
)
fi
build_args+=(
-f "$dockerfile"
-t "$image_fullname:$tag"
--output "type=docker"
)
if [ ! -z "${CACHE_FROM:-}" ]; then
build_args+=(
--cache-from "type=local,src=${CACHE_FROM}"
--cache-to "type=local,dest=${CACHE_TO}"
)
fi
IFS="," read -ra args_list <<< "$args"
for arg in "${args_list[@]}"; do
arg="${arg/ /_}"
build_args+=(
--build-arg "$arg"
)
done
build_args+=(
"$context"
)
run_cmd "$dry_run" docker buildx build "${build_args[@]}"
if [[ "$enable_push" = 1 ]]; then
run_cmd "$dry_run" docker push "$image_fullname:$tag"
fi
done
}
popd>/dev/null
done