-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
generate-stackbrew-library.sh
executable file
·140 lines (118 loc) · 4.02 KB
/
generate-stackbrew-library.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/usr/bin/env bash
set -Eeuo pipefail
declare -A aliases=(
[8.4]='8 lts'
)
defaultDefaultVariant='oracle'
declare -A defaultVariants=(
#[8.0]='debian'
)
self="$(basename "$BASH_SOURCE")"
cd "$(dirname "$(readlink -f "$BASH_SOURCE")")"
# add the "latest" alias to the "newest" version (LTS vs innovation; see sorting in "versions.sh")
latest="$(jq -r 'keys_unsorted[0]' versions.json)"
aliases["$latest"]+=' latest'
# if "innovation" currently is in line with an LTS, add the "innovation" alias to the LTS release
innovation="$(jq -r 'to_entries | if .[0].value.version == .[1].value.version and .[1].key == "innovation" then .[0].key else "innovation" end' versions.json)"
if [ "$innovation" != 'innovation' ]; then
aliases["$innovation"]+=' innovation'
fi
if [ "$#" -eq 0 ]; then
versions="$(jq -r 'keys | map(@sh) | join(" ")' versions.json)"
eval "set -- $versions"
fi
# sort version numbers with highest first
IFS=$'\n'; set -- $(sort -rV <<<"$*"); unset IFS
# get the most recent commit which modified any of "$@"
fileCommit() {
git log -1 --format='format:%H' HEAD -- "$@"
}
# get the most recent commit which modified "dir/dockerfile" or any file COPY'd from it
dirCommit() {
local dir="$1"; shift
local df="$1"; shift
(
cd "$dir"
local files; files="$(
git show "HEAD:./$df" | awk '
toupper($1) == "COPY" {
for (i = 2; i < NF; i++) {
print $i
}
}
'
)"
fileCommit "$df" $files
)
}
cat <<-EOH
# this file is generated via https://github.com/docker-library/mysql/blob/$(fileCommit "$self")/$self
Maintainers: Tianon Gravi <[email protected]> (@tianon),
Joseph Ferguson <[email protected]> (@yosifkit)
GitRepo: https://github.com/docker-library/mysql.git
EOH
# prints "$2$1$3$1...$N"
join() {
local sep="$1"; shift
local out; printf -v out "${sep//%/%%}%s" "$@"
echo "${out#$sep}"
}
for version; do
export version
if ! fullVersion="$(jq -re '
if env.version == "innovation" and keys_unsorted[0] != env.version then
# https://github.com/docker-library/mysql/pull/1046#issuecomment-2087323746
# if any explicit/LTS release is *newer* than the current innovation release, we should skip innovation
# (because we pre-sorted the full list in "versions.sh", we just need to check whether "innovation" is first 🚀)
false
else
.[env.version].version
end
' versions.json)"; then
continue
fi
versionAliases=()
while [ "$fullVersion" != "$version" -a "${fullVersion%[.-]*}" != "$fullVersion" ]; do
versionAliases+=( $fullVersion )
fullVersion="${fullVersion%[.-]*}"
done
versionAliases+=( $fullVersion )
if [ "$version" != "$fullVersion" ]; then
versionAliases+=( $version )
fi
versionAliases+=( ${aliases[$version]:-} )
defaultVariant="${defaultVariants[$version]:-$defaultDefaultVariant}"
for variant in oracle debian; do
export variant
df="Dockerfile.$variant"
[ -s "$version/$df" ] || continue
commit="$(dirCommit "$version" "$df")"
variantAliases=( "${versionAliases[@]/%/-$variant}" )
variantAliases=( "${variantAliases[@]//latest-/}" )
case "$variant" in
debian)
suite="$(jq -r '.[env.version][env.variant].suite' versions.json)"
variantAliases=( "${versionAliases[@]/%/-$suite}" "${variantAliases[@]}" )
variantAliases=( "${variantAliases[@]//latest-/}" )
;;
oracle)
ol="$(jq -r '.[env.version][env.variant].variant | split("-")[0]' versions.json)"
variantAliases=( "${versionAliases[@]/%/-oraclelinux$ol}" "${variantAliases[@]}" )
variantAliases=( "${variantAliases[@]//latest-/}" )
;;
esac
if [ "$variant" = "$defaultVariant" ]; then
variantAliases=( "${versionAliases[@]}" "${variantAliases[@]}" )
fi
# TODO if the list of architectures supported by MySQL ever is greater than that of the base image it's FROM, this list will need to be filtered
variantArches="$(jq -r '.[env.version][env.variant].architectures | join(", ")' versions.json)"
echo
cat <<-EOE
Tags: $(join ', ' "${variantAliases[@]}")
Architectures: $variantArches
GitCommit: $commit
Directory: $version
File: $df
EOE
done
done