From b30417da1ffc324c910e68dceba6a37585c3fb7c Mon Sep 17 00:00:00 2001 From: clover caruso Date: Tue, 17 Nov 2026 00:00:01 -0800 Subject: [PATCH] Prepare a separate Windows development image Install the C++ build tools and Windows SDK, Rust, Node/pnpm, Python and Git from official installers. Keep actual component versions and source hashes in the guest manifest. Assisted-by: gpt-6.1-sol --- guest/windows-development.ps1 | 89 +++++++++++++++++++++++++++++++++++ tools/vm-ai.py | 4 +- 2 files changed, 91 insertions(+), 2 deletions(-) create mode 100644 guest/windows-development.ps1 diff --git a/guest/windows-development.ps1 b/guest/windows-development.ps1 new file mode 100644 index 0000000000000000000000000000000000000000..8dc0490d95a596ecaaba4db9e53a1af04b7bc2c3 --- /dev/null +++ b/guest/windows-development.ps1 @@ -0,0 +1,89 @@ +$ErrorActionPreference = 'Stop' +$ProgressPreference = 'SilentlyContinue' +$identity = [Security.Principal.WindowsIdentity]::GetCurrent() +try { + $principal = New-Object Security.Principal.WindowsPrincipal($identity) + if ($identity.IsSystem -or !$principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) { throw 'Run this recipe from the elevated desktop account.' } +} finally { $identity.Dispose() } +$root = 'C:\Snowglobe' +$tools = 'C:\ProgramData\SnowglobeDevelopment' +$downloads = Join-Path $tools 'installers' +$sources = @() +New-Item $downloads -ItemType Directory -Force | Out-Null + +function Get-Installer([string]$uri, [string]$name, [switch]$Unsigned) { + $path = Join-Path $downloads $name + Invoke-WebRequest $uri -OutFile $path -UseBasicParsing + $signature = Get-AuthenticodeSignature $path + if (!$Unsigned -and $signature.Status -ne 'Valid') { throw "The installer signature is invalid: $name" } + $script:sources += @{ url = $uri; sha256 = (Get-FileHash $path -Algorithm SHA256).Hash } + return $path +} + +function Install-Program([string]$path, [string[]]$arguments) { + Add-Content "$root\development.log" ((Get-Date -Format o) + ' installing ' + [IO.Path]::GetFileName($path)) + $process = Start-Process $path -ArgumentList $arguments -PassThru + if (!$process.WaitForExit(1800000)) { throw 'The installer exceeded 30 minutes. Inspect it before retrying.' } + if ($process.ExitCode -notin @(0, 3010)) { throw "Installer exited with $($process.ExitCode): $path" } +} + +try { + $buildTools = Get-Installer 'https://aka.ms/vs/17/release/vs_BuildTools.exe' 'vs-build-tools.exe' + Install-Program $buildTools @('--quiet', '--wait', '--norestart', '--installPath', 'C:\BuildTools', + '--add', 'Microsoft.VisualStudio.Workload.VCTools', '--includeRecommended') + $node = Get-Installer 'https://nodejs.org/dist/v24.22.3/node-v24.22.3-x64.msi' 'node.msi' + Install-Program 'msiexec.exe' @('/i', $node, '/qn', '/norestart') + $pythonVersion = '3.14.10' + $pythonRoot = Join-Path $tools 'Python' + $series = ([Version]$pythonVersion).ToString(2) + $existingPython = (Get-ItemProperty "HKLM:\SOFTWARE\Python\PythonCore\$series\InstallPath" -ErrorAction SilentlyContinue).ExecutablePath + if ($existingPython -and (Test-Path $existingPython) -and (& $existingPython --version) -eq "Python $pythonVersion") { $pythonRoot = Split-Path $existingPython } + $python = Get-Installer "https://www.python.org/ftp/python/$pythonVersion/python-$pythonVersion-amd64.exe" 'python.exe' + if (!(Test-Path "$pythonRoot\python.exe") -or (& "$pythonRoot\python.exe" --version) -ne "Python $pythonVersion") { + Install-Program $python @('/quiet', 'InstallAllUsers=1', "TargetDir=$pythonRoot", + 'PrependPath=1', 'Include_test=0', 'InstallLauncherAllUsers=1') + } + $git = Get-Installer 'https://github.com/git-for-windows/git/releases/download/v2.56.1.windows.1/Git-2.56.1-64-bit.exe' 'git-installer.exe' + Install-Program $git @('/VERYSILENT', '/NORESTART', '/NOCANCEL', '/SP-', '/o:PathOption=Cmd') + + $env:CARGO_HOME = Join-Path $tools 'Cargo' + $env:RUSTUP_HOME = Join-Path $tools 'Rustup' + [Environment]::SetEnvironmentVariable('CARGO_HOME', $env:CARGO_HOME, 'Machine') + [Environment]::SetEnvironmentVariable('RUSTUP_HOME', $env:RUSTUP_HOME, 'Machine') + $rustUri = 'https://static.rust-lang.org/rustup/dist/x86_64-pc-windows-msvc/rustup-init.exe' + $rust = Get-Installer $rustUri 'rustup-init.exe' -Unsigned + Invoke-WebRequest ($rustUri + '.sha256') -OutFile ($rust + '.sha256') -UseBasicParsing + $expected = ([IO.File]::ReadAllText($rust + '.sha256') -split '\s+')[0] + if ((Get-FileHash $rust -Algorithm SHA256).Hash -ine $expected) { throw 'The Rust installer checksum differs.' } + Install-Program $rust @('-y', '--default-toolchain', '1.100.0', '--profile', 'minimal', '--no-modify-path') + + $paths = ([Environment]::GetEnvironmentVariable('Path', 'Machine') -split ';') + @($pythonRoot, "$pythonRoot\Scripts", "$env:CARGO_HOME\bin", "$tools\npm") + $env:Path = ($paths | Where-Object { $_ } | Select-Object -Unique) -join ';' + [Environment]::SetEnvironmentVariable('Path', $env:Path, 'Machine') + Install-Program 'C:\Program Files\nodejs\npm.cmd' @('install', '--global', '--prefix', "$tools\npm", 'pnpm@12.21.0', '--no-audit', '--no-fund') + & icacls.exe $tools /grant '*S-1-5-32-545:(OI)(CI)M' | Out-Null + if ($LASTEXITCODE -ne 0) { throw 'The development tool directory is inaccessible.' } + + $visualStudio = & 'C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe' -products '*' -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -format json | ConvertFrom-Json + if (!$visualStudio) { throw 'The C++ build tools are unavailable.' } + $manifest = @{ + createdAt = (Get-Date).ToUniversalTime().ToString('o') + recipeSha256 = (Get-FileHash $PSCommandPath -Algorithm SHA256).Hash + sources = $sources + windows = (Get-CimInstance Win32_OperatingSystem | Select-Object Caption, Version, BuildNumber) + visualStudio = @($visualStudio | Select-Object installationVersion, installationPath, isComplete, isRebootRequired) + windowsSdk = @(Get-ChildItem 'C:\Program Files (x86)\Windows Kits\10\Include' -Directory | ForEach-Object { $_.Name }) + rust = (& "$env:CARGO_HOME\bin\rustc.exe" --version) + cargo = (& "$env:CARGO_HOME\bin\cargo.exe" --version) + node = (& 'C:\Program Files\nodejs\node.exe' --version) + pnpm = (& "$tools\npm\pnpm.cmd" --version) + python = (& "$pythonRoot\python.exe" --version) + git = (Get-Item 'C:\Program Files\Git\cmd\git.exe').VersionInfo.ProductVersion + } + $manifest | ConvertTo-Json -Depth 8 | Set-Content "$root\development.json" -Encoding UTF8 + Remove-Item $downloads -Recurse -Force + Add-Content "$root\development.log" ((Get-Date -Format o) + ' ready') +} catch { + Add-Content "$root\development.log" ((Get-Date -Format o) + ' failed: ' + $_.Exception.Message) + throw +} diff --git a/tools/vm-ai.py b/tools/vm-ai.py index a023438bc72f2bb7f8cc201b2e29f33a6d5278a4..b062a5e8ca43dfc7bc7e0c1781709d9c7e283f65 100644 --- a/tools/vm-ai.py +++ b/tools/vm-ai.py @@ -84,8 +84,8 @@ def create(request): def manage(request): if request.get("action") == "presets" and set(request) == {"action", "owner"}: - return {"presets": [{"id": p["id"], "os": p["os"], "platform": p["platform"], - "arch": p["arch"], "disk_bytes": p["capacity"]} for p in presets()], "limits": LIMITS} + return {"presets": [{"id": p["id"], "os": p["os"], "description": p.get("description", ""), "platform": p["platform"], + "arch": p["arch"], "disk_bytes": p["capacity"], "recommended": p.get("recommended")} for p in presets()], "limits": LIMITS} if request.get("action") == "create": return create(request) if set(request) != {"action", "name", "owner", "seconds"} or request["action"] not in {"extend", "delete"}: -- 2.54.1