Skip to content

Commit 69770ce

Browse files
committed
Use Python installer from the https://www.python.org/
To avoid always writing the Python installation files to this folder, we can just download the installer, check the SHA1 checksum and install Python. This way, on the next Python version iteration, we can just change the SHA1 checksum dictionary and the build can be done. Signed-off-by: Adrian Vladu <avladu@cloudbasesolutions.com>
1 parent 1bd29db commit 69770ce

1 file changed

Lines changed: 56 additions & 2 deletions

File tree

BuildAutomation/BuildCloudbaseInitSetup.ps1

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
Param(
22
[string]$platform = "x64",
3-
[string]$pythonversion = "3.11_9",
3+
[string]$pythonversion = "3.12.3",
4+
[string]$pythonversionPrelease = "",
45
[string]$SignX509Thumbprint = $null,
56
[string]$release = $null,
67
# Cloudbase-Init repo details
@@ -12,12 +13,18 @@ Param(
1213
[string]$VSRedistDir = "${ENV:ProgramFiles(x86)}\Common Files\Merge Modules",
1314
[string]$SignTimestampUrl = "http://timestamp.digicert.com?alg=sha256"
1415
)
15-
1616
$ErrorActionPreference = "Stop"
1717

1818
$scriptPath = split-path -parent $MyInvocation.MyCommand.Definition
1919
. "$scriptPath\BuildUtils.ps1"
2020

21+
$PythonInstallerSha1Hash = @{
22+
"python-installer-3.12.3-x64.exe" = "B1207FBA545A75841E2DBCA2AD4F17B26414E0C1";
23+
"python-installer-3.12.3-x86.exe" = "FF180F8EA0B126E5A0FAF0A22EC50E96E5B9C5AB";
24+
"python-installer-3.13.0b1-x64.exe" = "46ADF56A03D91D39EA4E8B6F5FFB080C824BDFDA";
25+
"python-installer-3.13.0b1-x86.exe" = "62E6FE0D5C9267275ABDD36302F327EB4E68C794";
26+
}
27+
2128
$platformVCVarsRequired = "x86_amd64"
2229
# On Visual Studio 2019, the mixed x86_amd64 VC variables
2330
# make compilation for x86 use the x64 functions
@@ -76,6 +83,53 @@ try
7683

7784
$python_template_dir = join-path $cloudbaseInitInstallerDir "Python$($pythonversion.replace('.', ''))_${platform}_Template"
7885

86+
ExecRetry -maxRetryCount 3 {
87+
$pythonVersionInstaller = $pythonversion.Replace("-",".").Replace("_",".").Trim()
88+
$pythonVersionInstallerSuffix = $pythonVersionInstaller
89+
if ($pythonversionPrelease) {
90+
$pythonVersionInstallerSuffix = $pythonversionPrelease
91+
}
92+
$pythonArchInstaller = ""
93+
if ($platform -eq "x64") {
94+
$pythonArchInstaller = "-amd64"
95+
}
96+
$pythonInstallerName = "python-installer-${pythonVersionInstallerSuffix}-${platform}.exe"
97+
$pythonInstallerPath = (Join-Path $pwd $pythonInstallerName)
98+
$PythonInstallerUrl = "https://www.python.org/ftp/python/${pythonVersionInstaller}/python-${pythonVersionInstallerSuffix}${pythonArchInstaller}.exe"
99+
DownloadFile $PythonInstallerUrl $pythonInstallerPath
100+
$expectedSha1Hash = $PythonInstallerSha1Hash[$pythonInstallerName]
101+
if (!$expectedSha1Hash) {
102+
throw "expected Sha1 Hash for ${pythonInstallerPath} is not configured"
103+
}
104+
$sha1Hash = (Get-FileHash -Algorithm SHA1 $pythonInstallerPath).Hash
105+
if ($sha1Hash -ne $expectedSha1Hash) {
106+
throw "$pythonInstallerPath SHA1 hash is: ${sha1Hash}. Expected hash: ${expectedSha1Hash}"
107+
}
108+
109+
try {
110+
Write-Host "Trying to uninstall Python ${pythonVersionInstaller} to ${python_template_dir}"
111+
$installProcess = Start-Process -PassThru -Wait $pythonInstallerPath `
112+
-ArgumentList "/silent /uninstall"
113+
$installProcess.WaitForExit()
114+
if ($installProcess.ExitCode -ne 0) {
115+
throw "Failed to uninstall ${pythonVersionInstaller} from ${python_template_dir}. Exit code: $($installProcess.ExitCode)"
116+
}
117+
Write-Host "Uninstalled Python ${pythonVersionInstaller} from ${python_template_dir}"
118+
if ($python_template_dir -and (Test-Path $python_template_dir)) {
119+
Remove-Item -Force -Recurse "${python_template_dir}"
120+
}
121+
} catch {Write-Host $_}
122+
123+
Write-Host "Trying to install Python ${pythonVersionInstaller} to ${python_template_dir}"
124+
$installProcess = Start-Process -PassThru -Wait $pythonInstallerPath `
125+
-ArgumentList "/silent TargetDir=${python_template_dir} Include_test=0 Include_tcltk=0 Include_launcher=0 Include_doc=0"
126+
$installProcess.WaitForExit()
127+
if ($installProcess.ExitCode -ne 0) {
128+
throw "Failed to install ${pythonVersionInstaller} to ${python_template_dir}. Exit code: $($installProcess.ExitCode)"
129+
}
130+
Write-Host "Installed Python ${pythonVersionInstaller} to ${python_template_dir}"
131+
}
132+
79133
CheckCopyDir $python_template_dir $python_dir
80134

81135
# Make sure that we don't have temp files from a previous build

0 commit comments

Comments
 (0)