forked from docker-library/mysql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
versions.sh
executable file
·194 lines (173 loc) · 5.77 KB
/
versions.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#!/usr/bin/env bash
set -Eeuo pipefail
defaultDebianSuite='bookworm'
declare -A debianSuites=(
#[5.7]='buster'
)
defaultOracleVariant='9-slim'
declare -A oracleVariants=(
#[innovation]='8-slim'
)
# https://repo.mysql.com/yum/mysql-8.0-community/docker/
declare -A bashbrewArchToRpmArch=(
[amd64]='x86_64'
[arm64v8]='aarch64'
)
fetch_rpm_versions() {
local repo="$1"; shift
local arch="$1"; shift
local oracleVersion="$1"; shift
local package="$1"; shift
local baseurl="$repo/$arch"
# *technically*, we should parse "repodata/repomd.xml", look for <data type="primary">, and use the <location href="..."> value out of it, but parsing XML is not trivial with only basic tools, it turns out, so instead we rely on MySQL's use of "*-primary.xml.*" as the filename we're after 👀
local primaryLocation
primaryLocation="$(
# 2>/dev/null in case "$arch" doesn't exist in "$repo" 🙈
curl -fsSL "$baseurl/repodata/repomd.xml" 2>/dev/null \
| grep -oE 'href="[^"]+-primary[.]xml([.]gz)?"' \
| cut -d'"' -f2
)" || return 1
[ -n "$primaryLocation" ] || return 1
local decompressor='cat'
case "$primaryLocation" in
*.gz) decompressor='gunzip' ;;
*.xml) ;;
*) echo >&2 "error: unknown compression (from '$baseurl'): $primaryLocation"; exit 1 ;;
esac
# again, *technically* we should properly parse XML here, but y'know, it's complicated
curl -fsSL "$baseurl/$primaryLocation" \
| "$decompressor" \
| grep -oE '"'"$package"'-[0-9][^"]+[.]el'"$oracleVersion"'[.]'"$arch"'[.]rpm"' \
| sed -r 's/^"'"$package-|[.]$arch[.]rpm"'"$//g' \
| sort -rV
}
cd "$(dirname "$(readlink -f "$BASH_SOURCE")")"
versions=( "$@" )
if [ ${#versions[@]} -eq 0 ]; then
versions=( */ )
json='{}'
else
json="$(< versions.json)"
fi
versions=( "${versions[@]%/}" )
for version in "${versions[@]}"; do
export version
doc='{}'
if [ "$version" = '8.0' ]; then
debianSuite="${debianSuites[$version]:-$defaultDebianSuite}"
debianVersion="$(
curl -fsSL "https://repo.mysql.com/apt/debian/dists/$debianSuite/mysql-$version/binary-amd64/Packages.gz" \
| gunzip \
| awk -F ': ' '
$1 == "Package" {
pkg = $2
next
}
pkg == "mysql-server" && $1 == "Version" {
print $2
}
'
)"
# example 8.0.22-1debian10 => 8.0.22
baseVersion="${debianVersion%-*}"
export baseVersion debianSuite debianVersion
doc="$(
jq <<<"$doc" -c '
. += {
version: env.baseVersion,
debian: {
architectures: [ "amd64" ],
suite: env.debianSuite,
version: env.debianVersion,
},
}
'
)"
fi
oracleVariant="${oracleVariants[$version]:-$defaultOracleVariant}"
oracleVersion="${oracleVariant%%-*}" # "7", etc
rpmRepo="https://repo.mysql.com/yum/mysql-$version-community/docker/el/$oracleVersion"
case "$version" in
8.0) toolsRepo="https://repo.mysql.com/yum/mysql-tools-community/el/$oracleVersion" ;;
*) toolsRepo="https://repo.mysql.com/yum/mysql-tools-$version-community/el/$oracleVersion" ;;
esac
export rpmRepo toolsRepo
rpmVersion=
shellVersion=
doc="$(jq <<<"$doc" -c '. += {
oracle: { architectures: [], repo: env.rpmRepo },
"mysql-shell": { repo: env.toolsRepo },
}')"
for bashbrewArch in $(xargs -n1 <<<"${!bashbrewArchToRpmArch[*]}" | sort | xargs); do
rpmArch="${bashbrewArchToRpmArch[$bashbrewArch]}"
archVersions="$(
fetch_rpm_versions "$rpmRepo" "$rpmArch" "$oracleVersion" 'mysql-community-server-minimal' \
|| :
)"
archVersion="$(head -1 <<<"$archVersions")"
[ -n "$archVersion" ] || continue
if [ -z "$rpmVersion" ]; then
rpmVersion="$archVersion"
elif [ "$rpmVersion" != "$archVersion" ]; then
echo >&2 "error: $version architecture version mismatch! ('$rpmVersion' vs '$archVersion' on '$rpmArch'/'$bashbrewArch')"
exit 1
fi
shellArchVersions="$(fetch_rpm_versions "$toolsRepo" "$rpmArch" "$oracleVersion" 'mysql-shell')"
shellArchVersion="$(head -1 <<<"$shellArchVersions")"
if [ -z "$shellVersion" ]; then
shellVersion="$shellArchVersion"
elif [ "$shellVersion" != "$shellArchVersion" ]; then
echo >&2 "error: shell version mismatch! ('$shellVersion' vs '$shellArchVersion' on '$rpmArch'/'$bashbrewArch')"
exit 1
fi
export bashbrewArch
doc="$(jq <<<"$doc" -c '.oracle.architectures = (.oracle.architectures + [ env.bashbrewArch ] | sort)')"
done
if [ -z "$rpmVersion" ]; then
echo >&2 "error: missing version for '$version'"
exit 1
fi
baseVersion="$(jq <<<"$doc" -r '.version // ""')"
# example 8.0.22-1.el7 => 8.0.22
oracleBaseVersion="${rpmVersion%-*}"
: "${baseVersion:=$oracleBaseVersion}"
if [ "$baseVersion" != "$oracleBaseVersion" ]; then
echo >&2 "error: Oracle and Debian version mismatch! ('$oracleBaseVersion' vs '$baseVersion')"
exit 1
fi
export baseVersion rpmVersion shellVersion oracleVariant
doc="$(jq <<<"$doc" -c '
. += {
version: env.baseVersion,
oracle: (.oracle + {
version: env.rpmVersion,
variant: env.oracleVariant,
}),
"mysql-shell": (.["mysql-shell"] + {
version: env.shellVersion,
}),
}
')"
echo "$version: $baseVersion"
json="$(jq <<<"$json" -c --argjson doc "$doc" '.[env.version] = $doc')"
done
jq <<<"$json" '
# sort entries in descending version order so that it is easier to determine later (in "generate-stackbrew-library.sh") if "innovation" should be included or not, and which entry to give the "latest" alias to (the first one!)
# https://github.com/docker-library/mysql/pull/1046#issuecomment-2087323746
to_entries
| sort_by(
[
(
# very rough "sort by version number"
.value.version
| split(".")
| map(tonumber? // .)
),
# when two versions are equal (8.4.0 copied to "innovation" *and* in "8.4", for example), prefer the LTS/explicit release over "innovation"
.key != "innovation"
# (false sorts above true, but then we reverse)
]
)
| reverse
| from_entries
' > versions.json