Skip to content

Commit 4f5f64b

Browse files
committed
Scrape Windows versions via official download center
This is the same source/method chocolatey uses: https://github.com/mkevenaar/chocolatey-packages/blob/8c38398f695e86c55793ee9d61f4e541a25ce0be/automatic/mongodb.install/update.ps1#L15-L31
1 parent dc88ff8 commit 4f5f64b

File tree

7 files changed

+73
-50
lines changed

7 files changed

+73
-50
lines changed

3.6/windows/windowsservercore-ltsc2016/Dockerfile

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,19 @@ FROM mcr.microsoft.com/windows/servercore:ltsc2016
33
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop';"]
44

55
ENV MONGO_VERSION 3.6.17
6-
ENV MONGO_DOWNLOAD_URL https://downloads.mongodb.org/win32/mongodb-win32-x86_64-2008plus-ssl-3.6.17-signed.msi
7-
ENV MONGO_DOWNLOAD_SHA256 b20b72d5366a7a00cb85245ebedd01b665bbac4f918dd5fac7a7c5eb68477c26
6+
ENV MONGO_DOWNLOAD_URL https://fastdl.mongodb.org/win32/mongodb-win32-x86_64-2008plus-ssl-3.6.17-signed.msi
7+
ENV MONGO_DOWNLOAD_SHA256=b20b72d5366a7a00cb85245ebedd01b665bbac4f918dd5fac7a7c5eb68477c26
88

99
RUN Write-Host ('Downloading {0} ...' -f $env:MONGO_DOWNLOAD_URL); \
1010
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; \
1111
(New-Object System.Net.WebClient).DownloadFile($env:MONGO_DOWNLOAD_URL, 'mongo.msi'); \
1212
\
13-
Write-Host ('Verifying sha256 ({0}) ...' -f $env:MONGO_DOWNLOAD_SHA256); \
14-
if ((Get-FileHash mongo.msi -Algorithm sha256).Hash -ne $env:MONGO_DOWNLOAD_SHA256) { \
15-
Write-Host 'FAILED!'; \
16-
exit 1; \
13+
if ($env:MONGO_DOWNLOAD_SHA256) { \
14+
Write-Host ('Verifying sha256 ({0}) ...' -f $env:MONGO_DOWNLOAD_SHA256); \
15+
if ((Get-FileHash mongo.msi -Algorithm sha256).Hash -ne $env:MONGO_DOWNLOAD_SHA256) { \
16+
Write-Host 'FAILED!'; \
17+
exit 1; \
18+
}; \
1719
}; \
1820
\
1921
Write-Host 'Installing ...'; \

4.0/windows/windowsservercore-1809/Dockerfile

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,19 @@ FROM mcr.microsoft.com/windows/servercore:1809
33
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop';"]
44

55
ENV MONGO_VERSION 4.0.16
6-
ENV MONGO_DOWNLOAD_URL https://downloads.mongodb.org/win32/mongodb-win32-x86_64-2008plus-ssl-4.0.16-signed.msi
7-
ENV MONGO_DOWNLOAD_SHA256 d871d52110ed3c6600273d44e557ab63fc4104aa84b6115ad4dc0b68f90c062d
6+
ENV MONGO_DOWNLOAD_URL https://fastdl.mongodb.org/win32/mongodb-win32-x86_64-2008plus-ssl-4.0.16-signed.msi
7+
ENV MONGO_DOWNLOAD_SHA256=d871d52110ed3c6600273d44e557ab63fc4104aa84b6115ad4dc0b68f90c062d
88

99
RUN Write-Host ('Downloading {0} ...' -f $env:MONGO_DOWNLOAD_URL); \
1010
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; \
1111
(New-Object System.Net.WebClient).DownloadFile($env:MONGO_DOWNLOAD_URL, 'mongo.msi'); \
1212
\
13-
Write-Host ('Verifying sha256 ({0}) ...' -f $env:MONGO_DOWNLOAD_SHA256); \
14-
if ((Get-FileHash mongo.msi -Algorithm sha256).Hash -ne $env:MONGO_DOWNLOAD_SHA256) { \
15-
Write-Host 'FAILED!'; \
16-
exit 1; \
13+
if ($env:MONGO_DOWNLOAD_SHA256) { \
14+
Write-Host ('Verifying sha256 ({0}) ...' -f $env:MONGO_DOWNLOAD_SHA256); \
15+
if ((Get-FileHash mongo.msi -Algorithm sha256).Hash -ne $env:MONGO_DOWNLOAD_SHA256) { \
16+
Write-Host 'FAILED!'; \
17+
exit 1; \
18+
}; \
1719
}; \
1820
\
1921
Write-Host 'Installing ...'; \

4.0/windows/windowsservercore-ltsc2016/Dockerfile

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,19 @@ FROM mcr.microsoft.com/windows/servercore:ltsc2016
33
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop';"]
44

55
ENV MONGO_VERSION 4.0.16
6-
ENV MONGO_DOWNLOAD_URL https://downloads.mongodb.org/win32/mongodb-win32-x86_64-2008plus-ssl-4.0.16-signed.msi
7-
ENV MONGO_DOWNLOAD_SHA256 d871d52110ed3c6600273d44e557ab63fc4104aa84b6115ad4dc0b68f90c062d
6+
ENV MONGO_DOWNLOAD_URL https://fastdl.mongodb.org/win32/mongodb-win32-x86_64-2008plus-ssl-4.0.16-signed.msi
7+
ENV MONGO_DOWNLOAD_SHA256=d871d52110ed3c6600273d44e557ab63fc4104aa84b6115ad4dc0b68f90c062d
88

99
RUN Write-Host ('Downloading {0} ...' -f $env:MONGO_DOWNLOAD_URL); \
1010
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; \
1111
(New-Object System.Net.WebClient).DownloadFile($env:MONGO_DOWNLOAD_URL, 'mongo.msi'); \
1212
\
13-
Write-Host ('Verifying sha256 ({0}) ...' -f $env:MONGO_DOWNLOAD_SHA256); \
14-
if ((Get-FileHash mongo.msi -Algorithm sha256).Hash -ne $env:MONGO_DOWNLOAD_SHA256) { \
15-
Write-Host 'FAILED!'; \
16-
exit 1; \
13+
if ($env:MONGO_DOWNLOAD_SHA256) { \
14+
Write-Host ('Verifying sha256 ({0}) ...' -f $env:MONGO_DOWNLOAD_SHA256); \
15+
if ((Get-FileHash mongo.msi -Algorithm sha256).Hash -ne $env:MONGO_DOWNLOAD_SHA256) { \
16+
Write-Host 'FAILED!'; \
17+
exit 1; \
18+
}; \
1719
}; \
1820
\
1921
Write-Host 'Installing ...'; \

4.2/windows/windowsservercore-1809/Dockerfile

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,20 @@ FROM mcr.microsoft.com/windows/servercore:1809
22

33
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop';"]
44

5-
ENV MONGO_VERSION 4.2.4
6-
ENV MONGO_DOWNLOAD_URL https://downloads.mongodb.org/win32/mongodb-win32-x86_64-2012plus-4.2.4-signed.msi
7-
ENV MONGO_DOWNLOAD_SHA256 ca8d3cb9472275858f867a67dfea0ae107d8a20464dc415afc9d3abcefd5fbe9
5+
ENV MONGO_VERSION 4.2.3
6+
ENV MONGO_DOWNLOAD_URL https://fastdl.mongodb.org/win32/mongodb-win32-x86_64-2012plus-4.2.3-signed.msi
7+
ENV MONGO_DOWNLOAD_SHA256=234f6abf9c4947df94428f6ce648905dbf6b1269f48cc3239ebd4990bde1ca2a
88

99
RUN Write-Host ('Downloading {0} ...' -f $env:MONGO_DOWNLOAD_URL); \
1010
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; \
1111
(New-Object System.Net.WebClient).DownloadFile($env:MONGO_DOWNLOAD_URL, 'mongo.msi'); \
1212
\
13-
Write-Host ('Verifying sha256 ({0}) ...' -f $env:MONGO_DOWNLOAD_SHA256); \
14-
if ((Get-FileHash mongo.msi -Algorithm sha256).Hash -ne $env:MONGO_DOWNLOAD_SHA256) { \
15-
Write-Host 'FAILED!'; \
16-
exit 1; \
13+
if ($env:MONGO_DOWNLOAD_SHA256) { \
14+
Write-Host ('Verifying sha256 ({0}) ...' -f $env:MONGO_DOWNLOAD_SHA256); \
15+
if ((Get-FileHash mongo.msi -Algorithm sha256).Hash -ne $env:MONGO_DOWNLOAD_SHA256) { \
16+
Write-Host 'FAILED!'; \
17+
exit 1; \
18+
}; \
1719
}; \
1820
\
1921
Write-Host 'Installing ...'; \

4.2/windows/windowsservercore-ltsc2016/Dockerfile

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,20 @@ FROM mcr.microsoft.com/windows/servercore:ltsc2016
22

33
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop';"]
44

5-
ENV MONGO_VERSION 4.2.4
6-
ENV MONGO_DOWNLOAD_URL https://downloads.mongodb.org/win32/mongodb-win32-x86_64-2012plus-4.2.4-signed.msi
7-
ENV MONGO_DOWNLOAD_SHA256 ca8d3cb9472275858f867a67dfea0ae107d8a20464dc415afc9d3abcefd5fbe9
5+
ENV MONGO_VERSION 4.2.3
6+
ENV MONGO_DOWNLOAD_URL https://fastdl.mongodb.org/win32/mongodb-win32-x86_64-2012plus-4.2.3-signed.msi
7+
ENV MONGO_DOWNLOAD_SHA256=234f6abf9c4947df94428f6ce648905dbf6b1269f48cc3239ebd4990bde1ca2a
88

99
RUN Write-Host ('Downloading {0} ...' -f $env:MONGO_DOWNLOAD_URL); \
1010
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; \
1111
(New-Object System.Net.WebClient).DownloadFile($env:MONGO_DOWNLOAD_URL, 'mongo.msi'); \
1212
\
13-
Write-Host ('Verifying sha256 ({0}) ...' -f $env:MONGO_DOWNLOAD_SHA256); \
14-
if ((Get-FileHash mongo.msi -Algorithm sha256).Hash -ne $env:MONGO_DOWNLOAD_SHA256) { \
15-
Write-Host 'FAILED!'; \
16-
exit 1; \
13+
if ($env:MONGO_DOWNLOAD_SHA256) { \
14+
Write-Host ('Verifying sha256 ({0}) ...' -f $env:MONGO_DOWNLOAD_SHA256); \
15+
if ((Get-FileHash mongo.msi -Algorithm sha256).Hash -ne $env:MONGO_DOWNLOAD_SHA256) { \
16+
Write-Host 'FAILED!'; \
17+
exit 1; \
18+
}; \
1719
}; \
1820
\
1921
Write-Host 'Installing ...'; \

Dockerfile-windows.template

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,18 @@ SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop';"]
44

55
ENV MONGO_VERSION placeholder
66
ENV MONGO_DOWNLOAD_URL placeholder
7-
ENV MONGO_DOWNLOAD_SHA256 placeholder
7+
ENV MONGO_DOWNLOAD_SHA256=placeholder
88

99
RUN Write-Host ('Downloading {0} ...' -f $env:MONGO_DOWNLOAD_URL); \
1010
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; \
1111
(New-Object System.Net.WebClient).DownloadFile($env:MONGO_DOWNLOAD_URL, 'mongo.msi'); \
1212
\
13-
Write-Host ('Verifying sha256 ({0}) ...' -f $env:MONGO_DOWNLOAD_SHA256); \
14-
if ((Get-FileHash mongo.msi -Algorithm sha256).Hash -ne $env:MONGO_DOWNLOAD_SHA256) { \
15-
Write-Host 'FAILED!'; \
16-
exit 1; \
13+
if ($env:MONGO_DOWNLOAD_SHA256) { \
14+
Write-Host ('Verifying sha256 ({0}) ...' -f $env:MONGO_DOWNLOAD_SHA256); \
15+
if ((Get-FileHash mongo.msi -Algorithm sha256).Hash -ne $env:MONGO_DOWNLOAD_SHA256) { \
16+
Write-Host 'FAILED!'; \
17+
exit 1; \
18+
}; \
1719
}; \
1820
\
1921
Write-Host 'Installing ...'; \

update.sh

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ for version in "${versions[@]}"; do
5757
pkg ~ /^mongodb-(org(-unstable)?|10gen)$/ && $1 == "Version" { print $2 "=" pkg }
5858
' \
5959
| grep "^$rcVersion\." \
60-
| grep -v '~pre~$' \
60+
| grep -vE '~pre~$' \
6161
| sort -V \
6262
| tac|tac
6363
}
@@ -112,18 +112,29 @@ for version in "${versions[@]}"; do
112112
cp -a docker-entrypoint.sh "$version/"
113113

114114
if [ -d "$version/windows" ]; then
115-
windowsVersions="$(
116-
curl -fsSL 'https://www.mongodb.org/dl/win32/x86_64' \
117-
| grep --extended-regexp --only-matching '"https?://[^"]+/win32/mongodb-win32-x86_64-(2008plus-ssl|2012plus)-'"${rcVersion//./\\.}"'\.[^"]+-signed.msi"' \
118-
| sed \
119-
-e 's!^"!!' \
120-
-e 's!"$!!' \
121-
-e 's!http://downloads.mongodb.org/!https://downloads.mongodb.org/!' \
122-
| grep $rcGrepV -E -- '-rc[0-9]'
115+
# https://github.com/mkevenaar/chocolatey-packages/blob/8c38398f695e86c55793ee9d61f4e541a25ce0be/automatic/mongodb.install/update.ps1#L15-L31
116+
windowsDownloads="$(
117+
curl -fsSL 'https://www.mongodb.com/download-center/community' \
118+
| grep -oiE '"server-data">window[.]__serverData = {(.+?)}<' \
119+
| cut -d= -f2- | cut -d'<' -f1 \
120+
| jq -r --arg rcVersion "$rcVersion" '
121+
.community.versions[]
122+
| select(.version | startswith($rcVersion + "."))
123+
| .downloads[]
124+
| select(
125+
.edition == "base"
126+
and .arch == "x86_64"
127+
and (.target // "" | test("^windows(_x86_64-(2008plus-ssl|2012plus))?$"))
128+
)
129+
| .msi
130+
' \
131+
| grep -vE -- '-rc'
123132
)"
124-
windowsLatest="$(echo "$windowsVersions" | head -1)"
125-
windowsSha256="$(curl -fsSL "$windowsLatest.sha256" | cut -d' ' -f1)"
126-
windowsVersion="$(echo "$windowsLatest" | sed -r -e "s!^https?://.+(${rcVersion//./\\.}\.[^\"]+)-signed.msi\$!\1!")"
133+
windowsLatest="$(head -1 <<<"$windowsDownloads")"
134+
windowsVersion="$(sed -r -e "s!^https?://.+-(${rcVersion//./\\.}\.[^\"]+)-signed.msi\$!\1!" <<<"$windowsLatest")"
135+
136+
# 4.3 doesn't seem to have a sha256 file (403 forbidden), so this has to be optional :(
137+
windowsSha256="$(curl -fsSL "$windowsLatest.sha256" | cut -d' ' -f1 || :)"
127138

128139
echo "$version: $windowsVersion (windows)"
129140

@@ -135,7 +146,7 @@ for version in "${versions[@]}"; do
135146
sed -r \
136147
-e 's/^(ENV MONGO_VERSION) .*/\1 '"$windowsVersion"'/' \
137148
-e 's!^(ENV MONGO_DOWNLOAD_URL) .*!\1 '"$windowsLatest"'!' \
138-
-e 's/^(ENV MONGO_DOWNLOAD_SHA256) .*/\1 '"$windowsSha256"'/' \
149+
-e 's/^(ENV MONGO_DOWNLOAD_SHA256)=.*/\1='"$windowsSha256"'/' \
139150
-e 's!^(FROM .+):.+!\1:'"${winVariant#*-}"'!' \
140151
Dockerfile-windows.template \
141152
> "$version/windows/$winVariant/Dockerfile"

0 commit comments

Comments
 (0)