Repository navigation
Expand file tree
/
Copy pathDockerfile-windows.template
More file actions
107 lines (101 loc) · 3.68 KB
/
Copy pathDockerfile-windows.template
File metadata and controls
107 lines (101 loc) · 3.68 KB
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
102
103
104
105
106
107
{{
def rcVersion:
env.version | rtrimstr("-rc")
;
def extension:
.checksums.windows.url | split(".")[-1]
;
def is_windows_zip:
extension == "zip"
-}}
FROM mcr.microsoft.com/windows/{{ env.windowsVariant }}:{{ env.windowsRelease }}
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
{{ if rcVersion | IN("3.11", "3.12", "3.13", "3.14", "3.15") then ( -}}
{{ # only set PYTHONIOENCODING on versions less than 3.16 -}}
# https://github.com/docker-library/python/pull/557
ENV PYTHONIOENCODING UTF-8
{{ # reproducer: docker run --rm python:{{ env.version }}-windowsservercore-{{ env.windowsRelease }} python -c 'print(chr(0x4e2d))' -}}
{{ # https://github.com/docker-library/python/pull/1144#pullrequestreview-5634536246 -}}
{{ ) else "" end -}}
{{
# installer sets path for older python, but needs to be set for the zip download
if is_windows_zip then (
-}}
# PATH isn't actually set in the Docker image, so we have to set it from within the container
RUN $newPath = ('C:\Python;C:\Python\Scripts;{0}' -f $env:PATH); \
Write-Host ('Updating PATH: {0}' -f $newPath); \
[Environment]::SetEnvironmentVariable('PATH', $newPath, [EnvironmentVariableTarget]::Machine); \
Write-Host 'Complete.'
# doing this first to share cache across versions more aggressively
{{ ) else "" end -}}
ENV PYTHON_VERSION {{ .version }}
{{ if .checksums.windows.sha256 then ( -}}
ENV PYTHON_SHA256 {{ .checksums.windows.sha256 }}
{{ ) else "" end -}}
RUN $url = '{{ .checksums.windows.url | gsub("'"; "''") }}'; \
Write-Host ('Downloading {0} ...' -f $url); \
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; \
Invoke-WebRequest -Uri $url -OutFile 'python.{{ extension }}'; \
{{ if .checksums.windows.sha256 then ( -}}
\
Write-Host ('Verifying sha256 ({0}) ...' -f $env:PYTHON_SHA256); \
if ((Get-FileHash python.{{ extension }} -Algorithm sha256).Hash -ne $env:PYTHON_SHA256) { \
Write-Host 'FAILED!'; \
exit 1; \
}; \
{{ ) else "" end -}}
\
{{ if is_windows_zip then ( -}}
Write-Host 'Expanding ...'; \
Expand-Archive python.zip -DestinationPath C:\Python\; \
\
Write-Host 'Removing ...'; \
Remove-Item python.zip -Force; \
{{ ) else ( -}}
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=1', \
'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 'Removing ...'; \
Remove-Item python.exe -Force; \
Remove-Item $env:TEMP/Python*.log -Force; \
{{ ) end -}}
\
Write-Host 'Verifying install ("python --version") ...'; \
python --version; \
\
$env:PYTHONDONTWRITEBYTECODE = '1'; \
\
{{ if is_windows_zip then ( -}}
Write-Host 'Re-Installing pip ...'; \
# remove zip-provided pip so that we can reinstall and get the exe in c:\Python\Scripts
Remove-Item -Recurse C:\Python\Lib\site-packages\pip; \
Remove-Item -Recurse C:\Python\Lib\site-packages\pip-*; \
# install pip again
python -m ensurepip --default-pip; \
\
{{ ) else "" end -}}
Write-Host 'Verifying pip install ...'; \
pip --version; \
\
Write-Host 'Complete.'
CMD ["python"]