-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile-windows.template
81 lines (74 loc) · 2.9 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
FROM mcr.microsoft.com/windows/{{ env.windowsVariant }}:{{ env.windowsRelease }}
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
# https://github.com/docker-library/python/pull/557
ENV PYTHONIOENCODING UTF-8
ENV PYTHON_VERSION {{ .version }}
RUN $url = ('https://www.python.org/ftp/python/{0}/python-{1}-amd64.exe' -f ($env:PYTHON_VERSION -replace '[a-z]+[0-9]*$', ''), $env:PYTHON_VERSION); \
Write-Host ('Downloading {0} ...' -f $url); \
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; \
Invoke-WebRequest -Uri $url -OutFile 'python.exe'; \
\
Write-Host 'Installing ...'; \
# https://docs.python.org/3/using/windows.html#installing-without-ui
$exitCode = (Start-Process python.exe -Wait -NoNewWindow -PassThru \
-ArgumentList @( \
'/quiet', \
'InstallAllUsers=1', \
'TargetDir=C:\Python', \
'PrependPath=1', \
'Shortcuts=0', \
'Include_doc=0', \
'Include_pip=0', \
'Include_test=0' \
) \
).ExitCode; \
if ($exitCode -ne 0) { \
Write-Host ('Running python installer failed with exit code: {0}' -f $exitCode); \
Get-ChildItem $env:TEMP | Sort-Object -Descending -Property LastWriteTime | Select-Object -First 1 | Get-Content; \
exit $exitCode; \
} \
\
# the installer updated PATH, so we should refresh our local value
$env:PATH = [Environment]::GetEnvironmentVariable('PATH', [EnvironmentVariableTarget]::Machine); \
\
Write-Host 'Verifying install ...'; \
Write-Host ' python --version'; python --version; \
\
Write-Host 'Removing ...'; \
Remove-Item python.exe -Force; \
Remove-Item $env:TEMP/Python*.log -Force; \
\
Write-Host 'Complete.'
# if this is called "PIP_VERSION", pip explodes with "ValueError: invalid truth value '<VERSION>'"
ENV PYTHON_PIP_VERSION {{ .pip.version }}
# https://github.com/docker-library/python/issues/365
ENV PYTHON_SETUPTOOLS_VERSION {{ .setuptools.version }}
# https://github.com/pypa/get-pip
ENV PYTHON_GET_PIP_URL {{ .pip.url }}
ENV PYTHON_GET_PIP_SHA256 {{ .pip.sha256 }}
RUN Write-Host ('Downloading get-pip.py ({0}) ...' -f $env:PYTHON_GET_PIP_URL); \
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; \
Invoke-WebRequest -Uri $env:PYTHON_GET_PIP_URL -OutFile 'get-pip.py'; \
Write-Host ('Verifying sha256 ({0}) ...' -f $env:PYTHON_GET_PIP_SHA256); \
if ((Get-FileHash 'get-pip.py' -Algorithm sha256).Hash -ne $env:PYTHON_GET_PIP_SHA256) { \
Write-Host 'FAILED!'; \
exit 1; \
}; \
\
$env:PYTHONDONTWRITEBYTECODE = '1'; \
\
Write-Host ('Installing pip=={0} ...' -f $env:PYTHON_PIP_VERSION); \
python get-pip.py \
--disable-pip-version-check \
--no-cache-dir \
--no-compile \
('pip=={0}' -f $env:PYTHON_PIP_VERSION) \
('setuptools=={0}' -f $env:PYTHON_SETUPTOOLS_VERSION) \
; \
Remove-Item get-pip.py -Force; \
\
Write-Host 'Verifying pip install ...'; \
pip --version; \
\
Write-Host 'Complete.'
CMD ["python"]