Skip to content

Commit aeb3d7e

Browse files
authored
Update Python version on Windows (#1382)
1 parent 27aca93 commit aeb3d7e

File tree

4 files changed

+250
-104
lines changed

4 files changed

+250
-104
lines changed

src/nanoserver/1809/helix/amd64/Dockerfile

Lines changed: 64 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,37 +13,73 @@ RUN $apiUrl = 'https://api.github.com/repos/PowerShell/PowerShell/releases/lates
1313

1414
FROM mcr.microsoft.com/windows/nanoserver:1809
1515

16-
SHELL ["cmd", "/S", "/C"]
1716
USER ContainerAdministrator
18-
ENTRYPOINT C:\Windows\System32\cmd.exe
1917

2018
COPY --from=installer [ "C:\\powershell\\", "C:\\Program Files\\PowerShell\\" ]
2119

22-
RUN curl -SL --output %TEMP%\python.zip https://www.nuget.org/api/v2/package/python/3.7.3 `
23-
&& md C:\Python C:\PythonTemp `
24-
&& tar -zxf %TEMP%\python.zip -C C:\PythonTemp `
25-
&& xcopy /s c:\PythonTemp\tools C:\Python `
26-
&& rd /s /q c:\PythonTemp `
27-
&& del /q %TEMP%\python.zip `
28-
&& setx /M PYTHONPATH "C:\Python\Lib;C:\Python\DLLs;"
29-
30-
RUN setx /M PATH "%PATH%;C:\Program Files\PowerShell\;C:\Python;C:\python\scripts"
31-
32-
RUN md c:\\helixtmp && pushd c:\\helixtmp &&`
33-
python -m pip install --upgrade pip==20.2 && `
34-
python -m pip install virtualenv==16.6.0 && `
35-
pip download --no-deps helix-scripts --index-url https://dnceng.pkgs.visualstudio.com/public/_packaging/helix-client-prod/pypi/simple && `
36-
for %f in (.\helix_scripts-*-py3-none-any.whl) do (pip install %f) && `
37-
popd && rd /s /q c:\\helixtmp && `
38-
pwsh -Command `
39-
New-Item -Path 'HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\' -Name 'dotnet.exe' -Force -ErrorAction SilentlyContinue ; `
40-
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\dotnet.exe' -Value 2 -Name DumpType -Force ; `
41-
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\dotnet.exe' -Value 'C:\cores' -Name DumpFolder -Force ; `
42-
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\dotnet.exe' -Value 2 -Name DumpCount -Force ; `
43-
New-Item -Path 'HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\' -Name 'corerun.exe' -Force -ErrorAction SilentlyContinue ; `
44-
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\corerun.exe' -Value 2 -Name DumpType -Force ; `
45-
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\corerun.exe' -Value 'C:\cores' -Name DumpFolder -Force ; `
46-
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\corerun.exe' -Value 2 -Name DumpCount -Force
20+
RUN setx /M VIRTUAL_ENV "C:\Python-env" && `
21+
setx /M PATH "%PATH%;C:\Program Files\PowerShell\;%VIRTUAL_ENV%\Scripts;C:\Python;C:\python\scripts" && `
22+
setx /M PYTHONPATH "C:\Python\Lib;C:\Python\DLLs;"
4723

48-
WORKDIR C:\\Work
24+
# Install latest stable version of Python
25+
RUN pwsh -Command " `
26+
$apiUrl = 'https://api.nuget.org/v3-flatcontainer/python/index.json'; `
27+
$response = Invoke-RestMethod -Uri $apiUrl; `
28+
$versions = $response.versions | Where-Object { $_ -notmatch '-' } | Sort-Object { [version]$_ } -Descending; `
29+
$latestVersion = $versions[0]; `
30+
echo \"Downloading Python $latestVersion\"; `
31+
$pythonZip = \"$env:TEMP\python.zip\"; `
32+
Invoke-WebRequest -Uri https://www.nuget.org/api/v2/package/python/$latestVersion -OutFile $pythonZip; `
33+
$pythonTemp = 'C:\PythonTemp'; `
34+
md $pythonTemp; `
35+
tar -zxf $pythonZip -C $pythonTemp; `
36+
if ($LASTEXITCODE -ne 0) { `
37+
echo 'Failed to extract Python'; `
38+
exit 1; `
39+
} `
40+
xcopy /s /i c:\PythonTemp\tools C:\Python; `
41+
if ($LASTEXITCODE -ne 0) { `
42+
echo 'Failed to copy Python'; `
43+
exit 1; `
44+
} `
45+
Remove-Item -Recurse -Force $pythonTemp; `
46+
Remove-Item -Force $pythonZip;"
47+
48+
# Install Helix
49+
RUN pwsh -Command " `
50+
$helixTemp = 'C:\helixtmp'; `
51+
md $helixTemp; `
52+
pushd $helixTemp; `
53+
python -m venv $env:VIRTUAL_ENV; `
54+
if ($LASTEXITCODE -ne 0) { `
55+
echo \"Failed to create Python virtual environment\"; `
56+
exit 1; `
57+
} `
58+
& pip download --no-deps helix-scripts --index-url https://dnceng.pkgs.visualstudio.com/public/_packaging/helix-client-prod/pypi/simple; `
59+
if ($LASTEXITCODE -ne 0) { `
60+
echo \"Failed to download Helix scripts\"; `
61+
exit 1; `
62+
} `
63+
Get-ChildItem -Path $helixTemp -Filter 'helix_scripts-*-py3-none-any.whl' | `
64+
ForEach-Object { `
65+
& pip install $_.FullName --no-cache-dir; `
66+
if ($LASTEXITCODE -ne 0) { `
67+
echo \"Failed to install Helix script: $($_.Name)\"; `
68+
exit 1; `
69+
} `
70+
}; `
71+
popd; `
72+
Remove-Item -Recurse -Force $helixTemp;"
4973

74+
# Configure crash dumps for dotnet.exe and corerun.exe
75+
RUN pwsh -Command " `
76+
New-Item -Path 'HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\' -Name 'dotnet.exe' -Force -ErrorAction SilentlyContinue; `
77+
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\dotnet.exe' -Value 2 -Name DumpType -Force; `
78+
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\dotnet.exe' -Value 'C:\cores' -Name DumpFolder -Force; `
79+
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\dotnet.exe' -Value 2 -Name DumpCount -Force; `
80+
New-Item -Path 'HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\' -Name 'corerun.exe' -Force -ErrorAction SilentlyContinue; `
81+
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\corerun.exe' -Value 2 -Name DumpType -Force; `
82+
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\corerun.exe' -Value 'C:\cores' -Name DumpFolder -Force; `
83+
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\corerun.exe' -Value 2 -Name DumpCount -Force"
84+
85+
WORKDIR C:\\Work
Lines changed: 62 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,69 @@
11
# escape=`
22
FROM mcr.microsoft.com/windows/servercore:ltsc2019
33

4-
SHELL ["cmd", "/S", "/C"]
5-
USER ContainerAdministrator
4+
RUN setx /M VIRTUAL_ENV "C:\Python-env" && `
5+
setx /M PATH "%PATH%;C:\Program Files\PowerShell\;%VIRTUAL_ENV%\Scripts;C:\Python;C:\python\scripts" && `
6+
setx /M PYTHONPATH "C:\Python\Lib;C:\Python\DLLs;"
67

7-
RUN curl -SL --output %TEMP%\python.zip https://www.nuget.org/api/v2/package/python/3.7.3 `
8-
&& md C:\Python C:\PythonTemp `
9-
&& tar -zxf %TEMP%\python.zip -C C:\PythonTemp `
10-
&& xcopy /s c:\PythonTemp\tools C:\Python `
11-
&& rd /s /q c:\PythonTemp `
12-
&& del /q %TEMP%\python.zip `
13-
&& setx /M PYTHONPATH "C:\Python\Lib;C:\Python\DLLs;"
8+
# Install latest stable version of Python
9+
RUN powershell -Command " `
10+
$apiUrl = 'https://api.nuget.org/v3-flatcontainer/python/index.json'; `
11+
$response = Invoke-RestMethod -Uri $apiUrl; `
12+
$versions = $response.versions | Where-Object { $_ -notmatch '-' } | Sort-Object { [version]$_ } -Descending; `
13+
$latestVersion = $versions[0]; `
14+
echo \"Downloading Python $latestVersion\"; `
15+
$pythonZip = \"$env:TEMP\python.zip\"; `
16+
Invoke-WebRequest -Uri https://www.nuget.org/api/v2/package/python/$latestVersion -OutFile $pythonZip; `
17+
$pythonTemp = 'C:\PythonTemp'; `
18+
md $pythonTemp; `
19+
tar -zxf $pythonZip -C $pythonTemp; `
20+
if ($LASTEXITCODE -ne 0) { `
21+
echo 'Failed to extract Python'; `
22+
exit 1; `
23+
} `
24+
xcopy /s /i c:\PythonTemp\tools C:\Python; `
25+
if ($LASTEXITCODE -ne 0) { `
26+
echo 'Failed to copy Python'; `
27+
exit 1; `
28+
} `
29+
Remove-Item -Recurse -Force $pythonTemp; `
30+
Remove-Item -Force $pythonZip;"
1431

15-
RUN md c:\\helixtmp && pushd c:\\helixtmp &&`
16-
C:\Python\python.exe -m pip install --upgrade pip==20.2 --no-warn-script-location && `
17-
C:\Python\python.exe -m pip install virtualenv==16.6.0 --no-warn-script-location && `
18-
C:\Python\python.exe -m pip download --no-deps helix-scripts --index-url https://dnceng.pkgs.visualstudio.com/public/_packaging/helix-client-prod/pypi/simple && `
19-
for %f in (.\helix_scripts-*-py3-none-any.whl) do (C:\Python\python.exe -m pip install %f --no-warn-script-location) && `
20-
popd && rd /s /q c:\\helixtmp && `
21-
powershell -Command `
22-
New-Item -Path 'HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\' -Name 'dotnet.exe' -Force -ErrorAction SilentlyContinue ; `
23-
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\dotnet.exe' -Value 2 -Name DumpType -Force ; `
24-
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\dotnet.exe' -Value 'C:\cores' -Name DumpFolder -Force ; `
25-
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\dotnet.exe' -Value 2 -Name DumpCount -Force ; `
26-
New-Item -Path 'HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\' -Name 'corerun.exe' -Force -ErrorAction SilentlyContinue ; `
27-
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\corerun.exe' -Value 2 -Name DumpType -Force ; `
28-
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\corerun.exe' -Value 'C:\cores' -Name DumpFolder -Force ; `
29-
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\corerun.exe' -Value 2 -Name DumpCount -Force && `
30-
setx /M PATH "%PATH%;C:\Python;C:\python\scripts"
32+
# Install Helix
33+
RUN powershell -Command " `
34+
$helixTemp = 'C:\helixtmp'; `
35+
md $helixTemp; `
36+
pushd $helixTemp; `
37+
python -m venv $env:VIRTUAL_ENV; `
38+
if ($LASTEXITCODE -ne 0) { `
39+
echo \"Failed to create Python virtual environment\"; `
40+
exit 1; `
41+
} `
42+
& pip download --no-deps helix-scripts --index-url https://dnceng.pkgs.visualstudio.com/public/_packaging/helix-client-prod/pypi/simple; `
43+
if ($LASTEXITCODE -ne 0) { `
44+
echo \"Failed to download Helix scripts\"; `
45+
exit 1; `
46+
} `
47+
Get-ChildItem -Path $helixTemp -Filter 'helix_scripts-*-py3-none-any.whl' | `
48+
ForEach-Object { `
49+
& pip install $_.FullName --no-cache-dir; `
50+
if ($LASTEXITCODE -ne 0) { `
51+
echo \"Failed to install Helix script: $($_.Name)\"; `
52+
exit 1; `
53+
} `
54+
}; `
55+
popd; `
56+
Remove-Item -Recurse -Force $helixTemp;"
3157

32-
WORKDIR C:\\Work
58+
# Configure crash dumps for dotnet.exe and corerun.exe
59+
RUN powershell -Command " `
60+
New-Item -Path 'HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\' -Name 'dotnet.exe' -Force -ErrorAction SilentlyContinue; `
61+
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\dotnet.exe' -Value 2 -Name DumpType -Force; `
62+
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\dotnet.exe' -Value 'C:\cores' -Name DumpFolder -Force; `
63+
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\dotnet.exe' -Value 2 -Name DumpCount -Force; `
64+
New-Item -Path 'HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\' -Name 'corerun.exe' -Force -ErrorAction SilentlyContinue; `
65+
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\corerun.exe' -Value 2 -Name DumpType -Force; `
66+
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\corerun.exe' -Value 'C:\cores' -Name DumpFolder -Force; `
67+
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\corerun.exe' -Value 2 -Name DumpCount -Force"
3368

69+
WORKDIR C:\\Work
Lines changed: 62 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,69 @@
11
# escape=`
22
FROM mcr.microsoft.com/windows/servercore:ltsc2022
33

4-
SHELL ["cmd", "/S", "/C"]
5-
USER ContainerAdministrator
4+
RUN setx /M VIRTUAL_ENV "C:\Python-env" && `
5+
setx /M PATH "%PATH%;C:\Program Files\PowerShell\;%VIRTUAL_ENV%\Scripts;C:\Python;C:\python\scripts" && `
6+
setx /M PYTHONPATH "C:\Python\Lib;C:\Python\DLLs;"
67

7-
RUN curl -SL --output %TEMP%\python.zip https://www.nuget.org/api/v2/package/python/3.7.3 `
8-
&& md C:\Python C:\PythonTemp `
9-
&& tar -zxf %TEMP%\python.zip -C C:\PythonTemp `
10-
&& xcopy /s c:\PythonTemp\tools C:\Python `
11-
&& rd /s /q c:\PythonTemp `
12-
&& del /q %TEMP%\python.zip `
13-
&& setx /M PYTHONPATH "C:\Python\Lib;C:\Python\DLLs;"
8+
# Install latest stable version of Python
9+
RUN powershell -Command " `
10+
$apiUrl = 'https://api.nuget.org/v3-flatcontainer/python/index.json'; `
11+
$response = Invoke-RestMethod -Uri $apiUrl; `
12+
$versions = $response.versions | Where-Object { $_ -notmatch '-' } | Sort-Object { [version]$_ } -Descending; `
13+
$latestVersion = $versions[0]; `
14+
echo \"Downloading Python $latestVersion\"; `
15+
$pythonZip = \"$env:TEMP\python.zip\"; `
16+
Invoke-WebRequest -Uri https://www.nuget.org/api/v2/package/python/$latestVersion -OutFile $pythonZip; `
17+
$pythonTemp = 'C:\PythonTemp'; `
18+
md $pythonTemp; `
19+
tar -zxf $pythonZip -C $pythonTemp; `
20+
if ($LASTEXITCODE -ne 0) { `
21+
echo 'Failed to extract Python'; `
22+
exit 1; `
23+
} `
24+
xcopy /s /i c:\PythonTemp\tools C:\Python; `
25+
if ($LASTEXITCODE -ne 0) { `
26+
echo 'Failed to copy Python'; `
27+
exit 1; `
28+
} `
29+
Remove-Item -Recurse -Force $pythonTemp; `
30+
Remove-Item -Force $pythonZip;"
1431

15-
RUN md c:\\helixtmp && pushd c:\\helixtmp &&`
16-
C:\Python\python.exe -m pip install --upgrade pip==20.2 --no-warn-script-location && `
17-
C:\Python\python.exe -m pip install virtualenv==16.6.0 --no-warn-script-location && `
18-
C:\Python\python.exe -m pip download --no-deps helix-scripts --index-url https://dnceng.pkgs.visualstudio.com/public/_packaging/helix-client-prod/pypi/simple && `
19-
for %f in (.\helix_scripts-*-py3-none-any.whl) do (C:\Python\python.exe -m pip install %f --no-warn-script-location) && `
20-
popd && rd /s /q c:\\helixtmp && `
21-
powershell -Command `
22-
New-Item -Path 'HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\' -Name 'dotnet.exe' -Force -ErrorAction SilentlyContinue ; `
23-
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\dotnet.exe' -Value 2 -Name DumpType -Force ; `
24-
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\dotnet.exe' -Value 'C:\cores' -Name DumpFolder -Force ; `
25-
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\dotnet.exe' -Value 2 -Name DumpCount -Force ; `
26-
New-Item -Path 'HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\' -Name 'corerun.exe' -Force -ErrorAction SilentlyContinue ; `
27-
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\corerun.exe' -Value 2 -Name DumpType -Force ; `
28-
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\corerun.exe' -Value 'C:\cores' -Name DumpFolder -Force ; `
29-
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\corerun.exe' -Value 2 -Name DumpCount -Force && `
30-
setx /M PATH "%PATH%;C:\Python;C:\python\scripts"
32+
# Install Helix
33+
RUN powershell -Command " `
34+
$helixTemp = 'C:\helixtmp'; `
35+
md $helixTemp; `
36+
pushd $helixTemp; `
37+
python -m venv $env:VIRTUAL_ENV; `
38+
if ($LASTEXITCODE -ne 0) { `
39+
echo \"Failed to create Python virtual environment\"; `
40+
exit 1; `
41+
} `
42+
& pip download --no-deps helix-scripts --index-url https://dnceng.pkgs.visualstudio.com/public/_packaging/helix-client-prod/pypi/simple; `
43+
if ($LASTEXITCODE -ne 0) { `
44+
echo \"Failed to download Helix scripts\"; `
45+
exit 1; `
46+
} `
47+
Get-ChildItem -Path $helixTemp -Filter 'helix_scripts-*-py3-none-any.whl' | `
48+
ForEach-Object { `
49+
& pip install $_.FullName --no-cache-dir; `
50+
if ($LASTEXITCODE -ne 0) { `
51+
echo \"Failed to install Helix script: $($_.Name)\"; `
52+
exit 1; `
53+
} `
54+
}; `
55+
popd; `
56+
Remove-Item -Recurse -Force $helixTemp;"
57+
58+
# Configure crash dumps for dotnet.exe and corerun.exe
59+
RUN powershell -Command " `
60+
New-Item -Path 'HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\' -Name 'dotnet.exe' -Force -ErrorAction SilentlyContinue; `
61+
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\dotnet.exe' -Value 2 -Name DumpType -Force; `
62+
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\dotnet.exe' -Value 'C:\cores' -Name DumpFolder -Force; `
63+
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\dotnet.exe' -Value 2 -Name DumpCount -Force; `
64+
New-Item -Path 'HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\' -Name 'corerun.exe' -Force -ErrorAction SilentlyContinue; `
65+
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\corerun.exe' -Value 2 -Name DumpType -Force; `
66+
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\corerun.exe' -Value 'C:\cores' -Name DumpFolder -Force; `
67+
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\corerun.exe' -Value 2 -Name DumpCount -Force"
3168

3269
WORKDIR C:\\Work

0 commit comments

Comments
 (0)