forked from docker-library/official-images
-
Notifications
You must be signed in to change notification settings - Fork 2
/
.buildkit-build-contexts.sh
executable file
·55 lines (44 loc) · 1.78 KB
/
.buildkit-build-contexts.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
#!/usr/bin/env bash
set -Eeuo pipefail
# given a list of image references, returns an appropriate list of "ref=docker-image://foo@sha256:xxx" for the current architecture
dir="$(dirname "$BASH_SOURCE")"
[ -n "$BASHBREW_ARCH" ]
archNamespace=
die() {
echo >&2 "error: $*"
exit 1
}
for img; do
lookup=
case "$img" in
*@sha256:*)
lookup="$img"
;;
*/*)
file="$("$dir/.external-pins/file.sh" "$img")" || die "'$img': failed to look up external pin file"
digest="$(< "$file")" || die "'$img': failed to read external pin file ('$file')"
[ -n "$digest" ] || die "'$img': empty external pin file ('$file')"
lookup="${img%@*}@$digest" # img should never have an @ in it here, but just in case
;;
*)
[ -n "$BASHBREW_ARCH_NAMESPACES" ] || die 'missing BASHBREW_ARCH_NAMESPACES'
archNamespace="${archNamespace:-$(bashbrew cat --format '{{ archNamespace arch }}' "$dir/library/hello-world")}"
[ -n "$archNamespace" ] || die "failed to get arch namespace for '$BASHBREW_ARCH'"
lookup="$archNamespace/$img"
;;
esac
[ -n "$lookup" ] || die "'$img': failed to determine what image to query"
json="$(bashbrew remote arches --json "$lookup" || die "'$img': failed lookup ('$lookup')")"
digests="$(jq <<<"$json" -r '.arches[env.BASHBREW_ARCH] // [] | map(.digest | @sh) | join(" ")')"
eval "digests=( $digests )"
if [ "${#digests[@]}" -gt 1 ]; then
echo >&2 "warning: '$lookup' has ${#digests[@]} images for '$BASHBREW_ARCH'; returning only the first"
fi
for digest in "${digests[@]}"; do
echo "$img=docker-image://${lookup%@*}@$digest"
continue 2
done
digest="$(jq <<<"$json" -r '.desc.digest')"
arches="$(jq <<<"$json" -r '.arches | keys | join(" ")')"
die "'$img': no appropriate digest for '$BASHBREW_ARCH' found in '$lookup' ('$digest'; arches '$arches')"
done