-
Notifications
You must be signed in to change notification settings - Fork 2
/
build-tools.sh
executable file
·72 lines (60 loc) · 1.61 KB
/
build-tools.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
#!/usr/bin/env bash
set -e
declare SCRIPTPATH="$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
source $SCRIPTPATH/functions.sh
# Do a multistage build
export DOCKER_BUILDKIT=1
export DOCKER_CLI_EXPERIMENTAL=enabled
docker_login
do_it() {
if [ -d "$1" ]; then
for i in $1/Dockerfile*; do
do_it "$i"
done
return
fi
local dockerfile="$1"
local dockerdir="$(dirname "$dockerfile")"
local toolname="$(basename "$dockerdir")"
local VERSION="$(echo "$dockerfile" | cut -f2- -d.)"
local IS_LATEST
local build_env="$dockerdir/build.env"
local cmd
local IMAGE_VERSION
if [ "$dockerfile" == "$VERSION" ]; then
IS_LATEST=" (latest)"
cmd="env $(build_args "$build_env") ./files/tool-downloader.sh --echo-version"
echo $cmd
VERSION="$(eval "$cmd")"
fi
export VERSION
setup_default_platforms
if [ -f "$build_env" ]; then
eval "$(cat "$build_env" | egrep '^PLATFORMS=')"
fi
export PLATFORMS
IMAGE_VERSION="$(echo "$VERSION" | sed -E 's/^v//' | sed -E 's/\+.*$//')"
echo "**** $dockerfile / $IMAGE_VERSION$IS_LATEST ****"
cmd="docker buildx build --push --platform $PLATFORMS --build-arg VERSION=$VERSION $(build_args "$build_env" "--build-arg ") -t boky/$toolname:$IMAGE_VERSION"
if [ -n "$IS_LATEST" ]; then
cmd="$cmd -t boky/$toolname:latest"
fi
cmd="$cmd -f $dockerfile $dockerdir"
echo "$cmd"
eval "$cmd"
# if [ -n "$IS_LATEST" ]; then
# docker tag boky/$toolname:$IMAGE_VERSION boky/$toolname:latest
# fi
}
if [ "$#" -gt 0 ]; then
while [ "$1" != "" ]; do
do_it "$1"
shift
done
else
for i in tools/*; do
if [ -d "$i" ]; then
do_it "$i"
fi
done
fi