-
Notifications
You must be signed in to change notification settings - Fork 620
/
Dockerfile-windows.template
101 lines (90 loc) · 3.42 KB
/
Dockerfile-windows.template
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
{{
def has_client:
.targets.windows.features | index("Client")
-}}
FROM mcr.microsoft.com/windows/{{ env.windowsVariant }}:{{ env.windowsRelease }}
{{ if env.windowsVariant == "servercore" then ( -}}
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop';"]
{{ if .notes then ( -}}
# {{ .notes }}
{{ ) else "" end -}}
ENV MONGO_VERSION {{ .version }}
{{ if .date or .githash then ( -}}
# {{ [ .date // empty, "https://github.com/mongodb/mongo/tree/" + .githash // empty ] | join(", ") }}
{{ ) else "" end -}}
ENV MONGO_DOWNLOAD_URL {{ .targets.windows.msi }}
ENV MONGO_DOWNLOAD_SHA256={{ .targets.windows.sha256 }}
RUN Write-Host ('Downloading {0} ...' -f $env:MONGO_DOWNLOAD_URL); \
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; \
(New-Object System.Net.WebClient).DownloadFile($env:MONGO_DOWNLOAD_URL, 'mongo.msi'); \
\
if ($env:MONGO_DOWNLOAD_SHA256) { \
Write-Host ('Verifying sha256 ({0}) ...' -f $env:MONGO_DOWNLOAD_SHA256); \
if ((Get-FileHash mongo.msi -Algorithm sha256).Hash -ne $env:MONGO_DOWNLOAD_SHA256) { \
Write-Host 'FAILED!'; \
exit 1; \
}; \
}; \
\
Write-Host 'Installing ...'; \
# https://docs.mongodb.com/manual/tutorial/install-mongodb-on-windows/#install-mongodb-community-edition
Start-Process msiexec -Wait \
-ArgumentList @( \
'/i', \
'mongo.msi', \
'/quiet', \
'/qn', \
'/l*v', 'install.log', \
# https://docs.mongodb.com/manual/tutorial/install-mongodb-on-windows-unattended/#run-the-windows-installer-from-the-windows-command-interpreter
'INSTALLLOCATION=C:\mongodb', \
'ADDLOCAL={{ .targets.windows.features | join(",") }}' \
); \
if (-Not (Test-Path C:\mongodb\bin\mongod.exe -PathType Leaf)) { \
Write-Host 'Installer failed!'; \
Get-Content install.log; \
exit 1; \
}; \
Remove-Item install.log; \
\
$env:PATH = 'C:\mongodb\bin;' + $env:PATH; \
[Environment]::SetEnvironmentVariable('PATH', $env:PATH, [EnvironmentVariableTarget]::Machine); \
\
Write-Host 'Verifying install ...'; \
{{ if has_client then ( -}}
Write-Host ' mongo --version'; mongo --version; \
{{ ) else "" end -}}
Write-Host ' mongod --version'; mongod --version; \
\
Write-Host 'Removing ...'; \
Remove-Item C:\windows\installer\*.msi -Force; \
Remove-Item mongo.msi -Force; \
\
Write-Host 'Complete.';
# TODO docker-entrypoint.ps1 ? (for "docker run <image> --flag --flag --flag")
{{ ) else ( -}}
SHELL ["cmd", "/S", "/C"]
# PATH isn't actually set in the Docker image, so we have to set it from within the container
USER ContainerAdministrator
RUN setx /m PATH "C:\mongodb\bin;%PATH%"
USER ContainerUser
# doing this first to share cache across versions more aggressively
{{ def copy_from: "mongo:" + .version + "-windowsservercore-" + env.windowsRelease -}}
COPY --from={{ copy_from }} \
C:\\Windows\\System32\\msvcp140.dll \
C:\\Windows\\System32\\msvcp140_1.dll \
C:\\Windows\\System32\\vcruntime140.dll \
C:\\Windows\\System32\\vcruntime140_1.dll \
C:\\Windows\\System32\\
{{ if .notes then ( -}}
# {{ .notes }}
{{ ) else "" end -}}
ENV MONGO_VERSION {{ .version }}
{{ if .date or .githash then ( -}}
# {{ [ .date // empty, "https://github.com/mongodb/mongo/tree/" + .githash // empty ] | join(", ") }}
{{ ) else "" end -}}
COPY --from={{ copy_from }} C:\\mongodb C:\\mongodb
RUN {{ if has_client then ( }}mongo --version && {{ ) else "" end }}mongod --version
{{ ) end -}}
VOLUME C:\\data\\db C:\\data\\configdb
EXPOSE 27017
CMD ["mongod", "--bind_ip_all"]