forked from docker-library/docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.architectures-lib
72 lines (59 loc) · 1.78 KB
/
.architectures-lib
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
#!/usr/bin/env bash
_awkArch() {
local version="$1"; shift
local awkExpr="$1"; shift
awk "$@" "/^#|^\$/ { next } $awkExpr" "$version/release-architectures"
}
apkArches() {
local version="$1"; shift
_awkArch "$version" '{ print $2 }'
}
hasBashbrewArch() {
local version="$1"; shift
local bashbrewArch="$1"; shift
_awkArch "$version" 'BEGIN { exitCode = 1 } $1 == bashbrewArch { exitCode = 0 } END { exit exitCode }' -v bashbrewArch="$bashbrewArch"
}
apkToDockerArch() {
local version="$1"; shift
local apkArch="$1"; shift
_awkArch "$version" '$2 == apkArch { print $3; exit }' -v apkArch="$apkArch"
}
_generateParentRepoToArches() {
local repo="$1"; shift
local officialImagesUrl='https://github.com/docker-library/official-images/raw/master/library/'
eval "declare -g -A parentRepoToArches=( $(
find -name 'Dockerfile' -exec awk '
toupper($1) == "FROM" && $2 !~ /^('"$repo"'|scratch|.*\/.*)(:|$)/ {
print "'"$officialImagesUrl"'" $2
}
' '{}' + \
| sort -u \
| xargs bashbrew cat --format '[{{ .RepoName }}:{{ .TagName }}]="{{ join " " .TagEntry.Architectures }}"'
) )"
}
_generateParentRepoToArches 'docker'
parentArches() {
local version="$1"; shift # "17.06", etc
local parent="$(awk 'toupper($1) == "FROM" { print $2 }' "$version/Dockerfile")"
echo "${parentRepoToArches[$parent]:-}"
}
versionArches() {
local version="$1"; shift
local parentArches="$(parentArches "$version")"
local versionArches=()
for arch in $parentArches; do
if hasBashbrewArch "$version" "$arch"; then
versionArches+=( "$arch" )
fi
done
echo "${versionArches[*]}"
}
versionChannel() {
local version="$1"; shift # "17.06", "17.11-rc", etc
local rcVersion="${version%-rc}"
local channel='stable'
if [ "$rcVersion" != "$version" ]; then
channel='test'
fi
echo "$channel"
}