forked from lekpamartin/uptimerobot_exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·89 lines (75 loc) · 1.78 KB
/
build.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
#!/usr/bin/env bash
usage() {
echo "Usage: $0 [cron]"
}
array_join() {
local IFS="$1"
shift
echo "$*"
}
get_available_architectures() {
local image="$1"
local tag="${2:-latest}"
docker buildx imagetools inspect --raw "${image}:${tag}" | \
jq -r '.manifests[].platform | .os + "/" + .architecture + "/" + .variant' | \
sed 's#/$##' | sort
}
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]
then
set -ex
cd "$(readlink -f "$(dirname "$0")")" || exit 9
# Defaults
DOCKERFILE="${DOCKERFILE:-Dockerfile}"
IMAGE_NAME="${IMAGE_NAME:-lekpamartin/uptimerobot_exporter}"
TAG="${TAG:-latest}"
case "$1" in
latest)
DOCKERFILE=Dockerfile
TAG=latest
shift
;;
help|h|--help|-h)
usage
exit 0
;;
esac
EXTRA_BUILD_ARGS=()
case "$1" in
push|p|--push|-p)
EXTRA_BUILD_ARGS+=("--push")
;;
*)
EXTRA_BUILD_ARGS+=("--load")
;;
esac
# NOTE: Ookla doesn't provide binaries for ppcle64 or s390x
# read -r base_image base_tag <<< \
# "$(sed -nr 's/^FROM\s+([^:]+):?((\w+).*)\s*$/\1 \3/p' "$DOCKERFILE" | head -1)"
# shellcheck disable=2207
# platforms=($(get_available_architectures "$base_image" "$base_tag"))
platforms=(
linux/amd64
linux/arm/v6
linux/arm/v7
linux/arm64/v8
)
BUILD_TYPE=manual
if [[ "$TRAVIS" == "true" ]]
then
BUILD_TYPE=travis
EXTRA_BUILD_ARGS+=("--no-cache")
elif [[ "$GITHUB_ACTIONS" == "true" ]]
then
BUILD_TYPE=github
EXTRA_BUILD_ARGS+=("--no-cache")
fi
docker buildx build \
--file "$DOCKERFILE" \
--platform "$(array_join "," "${platforms[@]}")" \
--label=built-by=billimek \
--label=build-type="$BUILD_TYPE" \
--label=built-on="$HOSTNAME" \
--tag "${IMAGE_NAME}:${TAG}" \
"${EXTRA_BUILD_ARGS[@]}" \
.
fi