Skip to content

Commit 3ad9e30

Browse files
authored
Merge pull request #705 from infosiftr/versions-filter-targets
Update `versions.sh` to filter targets correctly for pre-releases
2 parents 290c08f + bcb585e commit 3ad9e30

File tree

3 files changed

+39
-31
lines changed

3 files changed

+39
-31
lines changed

Dockerfile-linux.template

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,10 @@ ENV MONGO_PACKAGE=${MONGO_PACKAGE} MONGO_REPO=${MONGO_REPO}
8080

8181
ENV MONGO_MAJOR {{ if env.version != env.rcVersion then "testing" else env.version end }}
8282
RUN echo "deb [ signed-by=/etc/apt/keyrings/mongodb.asc ] http://$MONGO_REPO/apt/{{ target.image | gsub(":.*$"; "") }} {{ target.suite }}/${MONGO_PACKAGE%-unstable}/$MONGO_MAJOR {{ if target.image | test("^debian") then "main" else "multiverse" end }}" | tee "/etc/apt/sources.list.d/${MONGO_PACKAGE%-unstable}.list"
83-
{{ if env.version != env.rcVersion and (env.rcVersion | tonumber >= 5) then ( -}}
84-
{{ if .version | ltrimstr(env.rcVersion) | startswith(".0-") then ( -}}
83+
{{ if env.version != env.rcVersion then ( -}}
84+
{{ if .dockerNeedsVersion then ( -}}
8585
# {{ env.rcVersion }} is not GA, so we need the previous release for mongodb-mongosh and mongodb-database-tools
86-
RUN echo "deb [ signed-by=/etc/apt/keyrings/mongodb.asc ] http://$MONGO_REPO/apt/{{ target.image | gsub(":.*$"; "") }} {{ target.suite }}/${MONGO_PACKAGE%-unstable}/{{ env.rcVersion | split(".") | .[0] |= (tonumber - 1 | tostring) | join(".") }} {{ if target.image | test("^debian") then "main" else "multiverse" end }}" | tee "/etc/apt/sources.list.d/mongodb-previous.list"
86+
RUN echo "deb [ signed-by=/etc/apt/keyrings/mongodb.asc ] http://$MONGO_REPO/apt/{{ target.image | gsub(":.*$"; "") }} {{ target.suite }}/${MONGO_PACKAGE%-unstable}/{{ .dockerNeedsVersion }} {{ if target.image | test("^debian") then "main" else "multiverse" end }}" | tee "/etc/apt/sources.list.d/mongodb-previous.list"
8787
{{ ) else ( -}}
8888
# add GA repo for mongodb-mongosh and mongodb-database-tools
8989
RUN echo "deb [ signed-by=/etc/apt/keyrings/mongodb.asc ] http://$MONGO_REPO/apt/{{ target.image | gsub(":.*$"; "") }} {{ target.suite }}/${MONGO_PACKAGE%-unstable}/{{ env.rcVersion }} {{ if target.image | test("^debian") then "main" else "multiverse" end }}" | tee "/etc/apt/sources.list.d/mongodb-{{ env.rcVersion }}.list"

versions.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@
197197
"8.0-rc": {
198198
"changes": "https://jira.mongodb.org/issues/?jql=project%20%3D%20SERVER%20AND%20fixVersion%20%3D%20%228.0.0-rc13%22%20ORDER%20BY%20status%20DESC%2C%20priority%20DESC",
199199
"date": "07/11/2024",
200+
"dockerNeedsVersion": "7.0",
200201
"githash": "b5271455825d4af9af540e3dd05ae19963355efb",
201202
"linux": "ubuntu2204",
202203
"notes": "https://docs.mongodb.org/master/release-notes/8.0/",

versions.sh

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ shell="$(
5252
"3.6", # April 2021
5353
"4.0", # April 2022
5454
"4.2", # April 2023
55-
null # ... so we can have a trailing comma above, making diffs nicer :trollface:
55+
empty
5656
] | index($v) | not)
5757
5858
# filter out so-called "rapid releases": https://docs.mongodb.com/upcoming/reference/versioning/
@@ -62,8 +62,21 @@ shell="$(
6262
| ($splitVersion[0] | tonumber) >= 5 and ($splitVersion[1] | tonumber) > 0
6363
| not
6464
)
65+
66+
# if a given pre-release version has not had a GA release yet, we need the previous release for mongodb-mongosh and mongodb-database-tools
67+
| (.version | rtrimstr("-rc")) as $rcVersion
68+
| if .version != $rcVersion and (.meta.version | ltrimstr($rcVersion) | startswith(".0-")) then
69+
.meta.dockerNeedsVersion = ($rcVersion | split(".") | .[0] |= (tonumber -1 | tostring) | join("."))
70+
else . end
6571
]
6672
73+
# filter the list of "downloads" (targets) down to the set of targets of (M-1).0 if we need that previous version (see "dockerNeedsVersion" above)
74+
| (map({ key: .version, value: [ .meta.downloads[].target ] }) | from_entries) as $targets
75+
| map(if .meta | has("dockerNeedsVersion") then
76+
.meta.dockerNeedsVersion as $needsVersion
77+
| .meta.downloads |= map(select(.target as $target | $targets[$needsVersion] | index($target)))
78+
else . end)
79+
6780
# now convert all that data to a basic shell list + map so we can loop over/use it appropriately
6881
| "allVersions=( " + (
6982
map(.version | ., if endswith("-rc") then empty else . + "-rc" end)
@@ -112,44 +125,38 @@ for version in "${versions[@]}"; do
112125
msiSha256="${msiSha256%% *}"
113126
export msiUrl msiSha256
114127

115-
export pgpKeyVersion="${version%-rc}"
116-
pgp='[]'
117-
if [ "$pgpKeyVersion" != "$version" ]; then
118-
# the "testing" repository (used for RCs) has a dedicated PGP key (but still needs the "release" key for the release line)
119-
pgp="$(jq -c --argjson pgp "$pgp" '$pgp + [ .dev // error("missing PGP key for dev") ]' pgp-keys.json)"
120-
121-
# if {{ env.rcVersion }} is not GA, so we need the previous release for mongodb-mongosh and mongodb-database-tools
122-
isDotZeroPrerelease="$(_jq -r '.version | ltrimstr(env.pgpKeyVersion) | startswith(".0-")')"
123-
if [ "$isDotZeroPrerelease" = 'true' ]; then
124-
pgp="$(
125-
jq -c --argjson pgp "$pgp" '
126-
(env.pgpKeyVersion | split(".") | .[0] |= (tonumber - 1 | tostring) | join(".")) as $previousVersion
127-
| $pgp + [ .[$previousVersion] // error("missing PGP key for \($previousVersion)") ]
128-
' pgp-keys.json
129-
)"
130-
fi
131-
fi
132-
minor="${pgpKeyVersion#*.}" # "4.3" -> "3"
133-
if [ "$(( minor % 2 ))" = 1 ]; then
134-
pgpKeyVersion="${version%.*}.$(( minor + 1 ))"
135-
fi
136-
pgp="$(jq -c --argjson pgp "$pgp" '$pgp + [ .[env.pgpKeyVersion] // error("missing PGP key for \(env.pgpKeyVersion)") ]' pgp-keys.json)"
137-
138128
json="$(
139129
{
140130
jq <<<"$json" -c .
141-
_jq --argjson pgp "$pgp" '{ (env.version): (
142-
with_entries(select(.key as $key | [
131+
_jq --slurpfile pgpKeys pgp-keys.json '{ (env.version): (
132+
$pgpKeys[0] as $pgp
133+
| (env.version | rtrimstr("-rc")) as $rcVersion
134+
| with_entries(select(.key as $key | [
143135
# interesting bits of raw upstream metadata
144136
"changes",
145137
"date",
146138
"githash",
147139
"notes",
148140
"version",
149-
null # ... trailing comma hack
141+
"dockerNeedsVersion",
142+
empty
150143
] | index($key)))
151144
+ {
152-
pgp: $pgp,
145+
pgp: [
146+
if env.version != $rcVersion then
147+
# the "testing" repository (used for RCs) has a dedicated PGP key (but still needs the "release" key for the release line)
148+
$pgp.dev
149+
else empty end,
150+
151+
if .dockerNeedsVersion then
152+
# see "dockerNeedsVersion" notes above
153+
$pgp[.dockerNeedsVersion]
154+
else empty end,
155+
156+
$pgp[$rcVersion],
157+
158+
empty
159+
],
153160
targets: (
154161
reduce (
155162
.downloads[]

0 commit comments

Comments
 (0)