Skip to content

Commit 4281212

Browse files
committed
Update versions.sh to no longer use Docker to scrape versions
This makes it *way* faster and much more sustainable.
1 parent 9418030 commit 4281212

File tree

1 file changed

+44
-37
lines changed

1 file changed

+44
-37
lines changed

versions.sh

Lines changed: 44 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,59 @@
11
#!/usr/bin/env bash
22
set -Eeuo pipefail
33

4-
# TODO scrape this somehow?
5-
supportedVersions=(
6-
16
7-
15
8-
14
9-
13
10-
12
11-
11
12-
#10
13-
#9.6
14-
#9.5
15-
#9.4
16-
#9.3
17-
#9.2
18-
)
19-
suite='bookworm'
4+
doiCommit="$(git ls-remote https://github.com/docker-library/official-images.git HEAD | cut -d$'\t' -f1)"
5+
doiPostgres="https://github.com/docker-library/official-images/raw/$doiCommit/library/postgres"
6+
versions="$(
7+
bashbrew list "$doiPostgres" | jq -nR '
8+
[
9+
inputs
10+
# filter tags down to just "N-XXX" (capturing "version" and "debian suite")
11+
| capture(":(?<version>[0-9]+)-(?<suite>[a-z].*)$")
12+
| select(.suite | startswith("alpine") | not)
13+
]
14+
'
15+
)"
16+
supportedVersions="$(jq <<<"$versions" -r '[ .[].version | tonumber ] | unique | reverse | map(@sh) | join(" ")')"
17+
eval "supportedVersions=( $supportedVersions )"
2018

2119
json='{}'
2220

2321
for i in "${!supportedVersions[@]}"; do
2422
new="${supportedVersions[$i]}"
25-
echo "# $new"
26-
docker pull "postgres:$new-$suite" > /dev/null
23+
export new
24+
suites="$(jq <<<"$versions" -c '[ .[] | select(.version == env.new).suite ]')"
25+
echo "# $new (possible suites: $suites)"
2726
(( j = i + 1 ))
2827
for old in "${supportedVersions[@]:$j}"; do
29-
dir="$old-to-$new"
30-
echo "- $old -> $new ($dir)"
28+
export old
29+
suite="$(jq <<<"$versions" --argjson suites "$suites" -r '
30+
first(
31+
.[]
32+
| select(
33+
.version == env.old
34+
and (
35+
.suite as $suite
36+
| $suites | index($suite)
37+
)
38+
)
39+
).suite
40+
')"
3141
from="postgres:$new-$suite"
32-
oldVersion="$(
33-
docker run --rm -e OLD="$old" "$from" bash -Eeuo pipefail -c '
34-
sed -i "s/\$/ $OLD/" /etc/apt/sources.list.d/pgdg.list
35-
apt-get update -qq 2>/dev/null
36-
apt-cache policy "postgresql-$OLD" \
37-
| awk "\$1 == \"Candidate:\" { print \$2; exit }"
38-
'
39-
)"
42+
dir="$old-to-$new"
43+
export suite from dir
44+
echo "- $old -> $new ($dir; $suite)"
45+
postgresCommit="$(bashbrew cat --format '{{ .TagEntry.GitCommit }}' "$doiPostgres:$old-$suite")"
46+
versionsURL="https://github.com/docker-library/postgres/raw/$postgresCommit/versions.json"
47+
oldVersion="$(wget -qO- "$versionsURL" | jq -r '.[env.old][env.suite].version // empty')" # TODO arches? (would need to cross-reference $new's arches, but that's fair / not too difficult)
4048
echo " - $oldVersion"
41-
if [ "$oldVersion" = '(none)' ]; then
42-
continue
43-
fi
44-
json="$(jq <<<"$json" -c --arg dir "$dir" --arg version "$oldVersion" --arg from "$from" --arg old "$old" --arg new "$new" '
45-
.[$dir] = {
46-
from: $from,
47-
new: $new,
48-
old: $old,
49-
version: $version,
49+
[ -n "$oldVersion" ]
50+
export oldVersion
51+
json="$(jq <<<"$json" -c '
52+
.[env.dir] = {
53+
from: env.from,
54+
new: env.new,
55+
old: env.old,
56+
version: env.oldVersion,
5057
}
5158
')"
5259
done

0 commit comments

Comments
 (0)