Skip to content

Commit d0228ea

Browse files
authored
Merge pull request #394 from infosiftr/fix-version-mismatch
Enfoce Windows and Linux versions to stay in sync via community downloads data
2 parents 8269d08 + c312dd5 commit d0228ea

File tree

4 files changed

+164
-77
lines changed

4 files changed

+164
-77
lines changed

.appveyor.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ environment:
1818
- version: 3.6
1919
variant: windowsservercore-ltsc2016
2020
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
21+
- version: 3.6
22+
variant: windowsservercore-1809
23+
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
2124

2225
install:
2326
- ps: |
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
FROM mcr.microsoft.com/windows/servercore:1809
2+
3+
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop';"]
4+
5+
ENV MONGO_VERSION 3.6.17
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
8+
9+
RUN Write-Host ('Downloading {0} ...' -f $env:MONGO_DOWNLOAD_URL); \
10+
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; \
11+
(New-Object System.Net.WebClient).DownloadFile($env:MONGO_DOWNLOAD_URL, 'mongo.msi'); \
12+
\
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+
}; \
19+
}; \
20+
\
21+
Write-Host 'Installing ...'; \
22+
# https://docs.mongodb.com/manual/tutorial/install-mongodb-on-windows/#install-mongodb-community-edition
23+
Start-Process msiexec -Wait \
24+
-ArgumentList @( \
25+
'/i', \
26+
'mongo.msi', \
27+
'/quiet', \
28+
'/qn', \
29+
'INSTALLLOCATION=C:\mongodb', \
30+
'ADDLOCAL=all' \
31+
); \
32+
$env:PATH = 'C:\mongodb\bin;' + $env:PATH; \
33+
[Environment]::SetEnvironmentVariable('PATH', $env:PATH, [EnvironmentVariableTarget]::Machine); \
34+
\
35+
Write-Host 'Verifying install ...'; \
36+
Write-Host ' mongo --version'; mongo --version; \
37+
Write-Host ' mongod --version'; mongod --version; \
38+
\
39+
Write-Host 'Removing ...'; \
40+
Remove-Item C:\mongodb\bin\*.pdb -Force; \
41+
Remove-Item C:\windows\installer\*.msi -Force; \
42+
Remove-Item mongo.msi -Force; \
43+
\
44+
Write-Host 'Complete.';
45+
46+
VOLUME C:\\data\\db C:\\data\\configdb
47+
48+
# TODO docker-entrypoint.ps1 ? (for "docker run <image> --flag --flag --flag")
49+
50+
EXPOSE 27017
51+
CMD ["mongod", "--bind_ip_all"]

4.0/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ ARG MONGO_REPO=repo.mongodb.org
7777
ENV MONGO_PACKAGE=${MONGO_PACKAGE} MONGO_REPO=${MONGO_REPO}
7878

7979
ENV MONGO_MAJOR 4.0
80-
ENV MONGO_VERSION 4.0.17
80+
ENV MONGO_VERSION 4.0.16
8181
# bashbrew-architectures:amd64 arm64v8
8282
RUN echo "deb http://$MONGO_REPO/apt/ubuntu xenial/${MONGO_PACKAGE%-unstable}/$MONGO_MAJOR multiverse" | tee "/etc/apt/sources.list.d/${MONGO_PACKAGE%-unstable}.list"
8383

update.sh

Lines changed: 109 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ declare -A froms=(
1515
[4.0]='ubuntu:xenial'
1616
)
1717

18+
declare -A fromToCommunityVersionsTarget=(
19+
[ubuntu:bionic]='ubuntu1804'
20+
[ubuntu:xenial]='ubuntu1604'
21+
)
22+
1823
declare -A dpkgArchToBashbrew=(
1924
[amd64]='amd64'
2025
[armel]='arm32v5'
@@ -25,14 +30,22 @@ declare -A dpkgArchToBashbrew=(
2530
[s390x]='s390x'
2631
)
2732

33+
# https://github.com/mkevenaar/chocolatey-packages/blob/8c38398f695e86c55793ee9d61f4e541a25ce0be/automatic/mongodb.install/update.ps1#L15-L31
34+
communityVersions="$(
35+
curl -fsSL 'https://www.mongodb.com/download-center/community' \
36+
| grep -oiE '"server-data">window[.]__serverData = {(.+?)}<' \
37+
| cut -d= -f2- | cut -d'<' -f1 \
38+
| jq -c '.community.versions[]'
39+
)"
40+
2841
travisEnv=
2942
appveyorEnv=
3043
for version in "${versions[@]}"; do
3144
rcVersion="${version%-rc}"
3245
major="$rcVersion"
33-
rcGrepV='-v'
46+
rcJqNot='| not'
3447
if [ "$rcVersion" != "$version" ]; then
35-
rcGrepV=
48+
rcJqNot=
3649
major='testing'
3750
fi
3851

@@ -41,47 +54,86 @@ for version in "${versions[@]}"; do
4154
suite="${from#$distro:}" # "jessie-slim", "xenial"
4255
suite="${suite%-slim}" # "jessie", "xenial"
4356

57+
downloads="$(
58+
jq -c --arg rcVersion "$rcVersion" '
59+
select(
60+
(.version | startswith($rcVersion + "."))
61+
and (.version | contains("-rc") '"$rcJqNot"')
62+
)
63+
| .version as $version
64+
| .downloads[]
65+
| select(.arch == "x86_64")
66+
| .version = $version
67+
' <<<"$communityVersions"
68+
)"
69+
versions="$(
70+
jq -r --arg target "${fromToCommunityVersionsTarget[$from]}" '
71+
select(.edition == "targeted" and .target // "" == $target)
72+
| .version
73+
' <<<"$downloads"
74+
)"
75+
windowsDownloads="$(
76+
jq -c '
77+
select(
78+
.edition == "base"
79+
and (.target // "" | test("^windows(_x86_64-(2008plus-ssl|2012plus))?$"))
80+
)
81+
' <<<"$downloads"
82+
)"
83+
windowsVersions="$(
84+
jq -r '.version' <<<"$windowsDownloads"
85+
)"
86+
commonVersions="$(
87+
comm -12 \
88+
<(sort -u <<<"$versions") \
89+
<(sort -u <<<"$windowsVersions")
90+
)"
91+
fullVersion="$(sort -V <<< "$commonVersions" | tail -1)"
92+
93+
if [ -z "$fullVersion" ]; then
94+
echo >&2 "error: failed to find full version for $version"
95+
exit 1
96+
fi
97+
98+
echo "$version: $fullVersion"
99+
44100
component='multiverse'
45101
if [ "$distro" = 'debian' ]; then
46102
component='main'
47103
fi
48-
49104
repoUrlBase="https://repo.mongodb.org/apt/$distro/dists/$suite/mongodb-org/$major/$component"
50105

51-
_arch_versions() {
106+
_arch_has_version() {
52107
local arch="$1"; shift
108+
local version="$1"; shift
53109
curl -fsSL "$repoUrlBase/binary-$arch/Packages.gz" 2>/dev/null \
54110
| gunzip 2>/dev/null \
55-
| awk -F ': ' '
111+
| awk -F ': ' -v version="$version" '
112+
BEGIN { ret = 1 }
56113
$1 == "Package" { pkg = $2 }
57-
pkg ~ /^mongodb-(org(-unstable)?|10gen)$/ && $1 == "Version" { print $2 "=" pkg }
58-
' \
59-
| grep "^$rcVersion\." \
60-
| grep -vE '~pre~$' \
61-
| sort -V \
62-
| tac|tac
114+
pkg ~ /^mongodb-(org(-unstable)?|10gen)$/ && $1 == "Version" && $2 == version { print pkg; ret = 0; last }
115+
END { exit(ret) }
116+
'
63117
}
64118

65-
fullVersion="$(_arch_versions 'amd64' | tail -1)"
66-
packageName="${fullVersion#*=}"
67-
fullVersion="${fullVersion%=$packageName}"
68-
if [ -z "$fullVersion" ]; then
69-
echo >&2 "error: failed to get full version for '$version' (from '$repoUrlBase')"
70-
exit 1
71-
fi
72-
73119
arches=()
120+
packageName=
74121
for dpkgArch in "${!dpkgArchToBashbrew[@]}"; do
75122
bashbrewArch="${dpkgArchToBashbrew[$dpkgArch]}"
76-
if \
77-
[ "$bashbrewArch" = 'amd64' ] \
78-
|| grep -qx "$fullVersion=$packageName" <(_arch_versions "$dpkgArch") \
79-
; then
123+
if archPackageName="$(_arch_has_version "$dpkgArch" "$fullVersion")"; then
124+
if [ -z "$packageName" ]; then
125+
packageName="$archPackageName"
126+
elif [ "$archPackageName" != "$packageName" ]; then
127+
echo >&2 "error: package name for $dpkgArch ($archPackageName) does not match other arches ($packageName)"
128+
exit 1
129+
fi
80130
arches+=( "$bashbrewArch" )
81131
fi
82132
done
83133
sortedArches="$(xargs -n1 <<<"${arches[*]}" | sort | xargs)"
84134

135+
echo "- $sortedArches"
136+
85137
if [ "$major" != 'testing' ]; then
86138
gpgKeyVersion="$rcVersion"
87139
minor="${rcVersion#*.}" # "4.3" -> "3"
@@ -94,8 +146,6 @@ for version in "${versions[@]}"; do
94146
gpgKeys="$(grep -E '^[0-9.]+:' gpg-keys.txt | cut -d: -f2 | xargs)"
95147
fi
96148

97-
echo "$version: $fullVersion (linux; $sortedArches)"
98-
99149
sed -r \
100150
-e 's/^(ENV MONGO_MAJOR) .*/\1 '"$major"'/' \
101151
-e 's/^(ENV MONGO_VERSION) .*/\1 '"$fullVersion"'/' \
@@ -111,57 +161,40 @@ for version in "${versions[@]}"; do
111161

112162
cp -a docker-entrypoint.sh "$version/"
113163

114-
if [ -d "$version/windows" ]; then
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'
132-
)"
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 || :)"
138-
139-
echo "$version: $windowsVersion (windows)"
140-
141-
for winVariant in \
142-
windowsservercore-{1809,ltsc2016} \
143-
; do
144-
[ -d "$version/windows/$winVariant" ] || continue
145-
146-
sed -r \
147-
-e 's/^(ENV MONGO_VERSION) .*/\1 '"$windowsVersion"'/' \
148-
-e 's!^(ENV MONGO_DOWNLOAD_URL) .*!\1 '"$windowsLatest"'!' \
149-
-e 's/^(ENV MONGO_DOWNLOAD_SHA256)=.*/\1='"$windowsSha256"'/' \
150-
-e 's!^(FROM .+):.+!\1:'"${winVariant#*-}"'!' \
151-
Dockerfile-windows.template \
152-
> "$version/windows/$winVariant/Dockerfile"
153-
154-
case "$winVariant" in
155-
# https://www.appveyor.com/docs/windows-images-software/
156-
*-1809)
157-
appveyorEnv='\n - version: '"$version"'\n variant: '"$winVariant"'\n APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019'"$appveyorEnv"
158-
;;
159-
*-ltsc2016)
160-
appveyorEnv='\n - version: '"$version"'\n variant: '"$winVariant"'\n APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017'"$appveyorEnv"
161-
;;
162-
esac
163-
done
164-
fi
164+
windowsMsi="$(
165+
jq -r --arg version "$fullVersion" '
166+
select(.version == $version)
167+
| .msi
168+
' <<<"$windowsDownloads" | head -1
169+
)"
170+
[ -n "$windowsMsi" ]
171+
172+
# 4.3 doesn't seem to have a sha256 file (403 forbidden), so this has to be optional :(
173+
windowsSha256="$(curl -fsSL "$windowsMsi.sha256" | cut -d' ' -f1 || :)"
174+
175+
for winVariant in \
176+
windowsservercore-{1809,ltsc2016} \
177+
; do
178+
mkdir -p "$version/windows/$winVariant"
179+
180+
sed -r \
181+
-e 's/^(ENV MONGO_VERSION) .*/\1 '"$fullVersion"'/' \
182+
-e 's!^(ENV MONGO_DOWNLOAD_URL) .*!\1 '"$windowsMsi"'!' \
183+
-e 's/^(ENV MONGO_DOWNLOAD_SHA256)=.*/\1='"$windowsSha256"'/' \
184+
-e 's!^(FROM .+):.+!\1:'"${winVariant#*-}"'!' \
185+
Dockerfile-windows.template \
186+
> "$version/windows/$winVariant/Dockerfile"
187+
188+
case "$winVariant" in
189+
# https://www.appveyor.com/docs/windows-images-software/
190+
*-1809)
191+
appveyorEnv='\n - version: '"$version"'\n variant: '"$winVariant"'\n APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019'"$appveyorEnv"
192+
;;
193+
*-ltsc2016)
194+
appveyorEnv='\n - version: '"$version"'\n variant: '"$winVariant"'\n APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017'"$appveyorEnv"
195+
;;
196+
esac
197+
done
165198

166199
travisEnv='\n - os: linux\n env: VERSION='"$version$travisEnv"
167200
done

0 commit comments

Comments
 (0)