-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_docker.sh
executable file
·102 lines (85 loc) · 1.69 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
#!/bin/bash
set -euo pipefail
cd "$(dirname "$0")"
umask 022
export LC_ALL="C"
export TZ="Etc/UTC"
readonly PACKAGE="chronostachyon/roxy"
readonly PLATFORM_LIST=( linux/amd64 linux/arm64v8 )
FULL_VERSION="$(./scripts/next_build_version.sh roxy-docker)"
TAGS=( "$FULL_VERSION" "latest" )
case "$FULL_VERSION" in
(*-r*)
TAGS=( "$FULL_VERSION" "devel" )
;;
esac
run() {
echo "> $*"
"$@" || return $?
}
build_for_platform() {
local platform="$1"
local platform_tag="${platform//\//-}"
local arch="${platform#*/}"
local -i rc=0
declare -a args
run \
docker buildx use "$platform_tag" \
|| rc=$?
if [ $rc -ne 0 ]; then
run \
docker buildx create \
--name="$platform_tag" \
--driver="docker-container" \
--platform="$platform" \
--use
fi
args=( \
docker \
buildx \
build \
--file="Dockerfile" \
--platform="$platform" \
--build-arg=VERSION="$FULL_VERSION" \
--build-arg=ARCH="$arch" \
)
for tag in "${TAGS[@]}"; do
args=( \
"${args[@]}" \
--tag="${PACKAGE}:${platform_tag}-${tag}" \
)
done
args=( \
"${args[@]}" \
--push \
. \
)
run "${args[@]}"
}
for platform in "${PLATFORM_LIST[@]}"; do
build_for_platform "$platform"
done
for tag in "${TAGS[@]}"; do
run \
docker \
manifest \
rm \
"${PACKAGE}:${tag}" \
|| true
args=( \
docker \
manifest \
create \
"${PACKAGE}:${tag}" \
)
for platform in "${PLATFORM_LIST[@]}"; do
platform_tag="${platform//\//-}"
args=( "${args[@]}" "${PACKAGE}:${platform_tag}-${tag}" )
done
run "${args[@]}"
run \
docker \
manifest \
push \
"${PACKAGE}:${tag}"
done