Skip to content

Commit 87d605f

Browse files
fix(beacon): pre-stage AzStackHci.EnvironmentChecker from local cache — mandatory for Cat 5
Module now copies from -ModuleCachePath (default C:\build\modules) first. Falls back to PSGallery with 5-min timeout. Fails the build if unavailable. beacon-build.ps1 updated to pre-download module before build starts. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013AZySkzowyq4Ne2hrSRRAL
1 parent 6db3ae3 commit 87d605f

1 file changed

Lines changed: 34 additions & 16 deletions

File tree

src/Build-WinPEImage.ps1

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
5. Add WinPE optional components (WMI, NetFX, Scripting, PowerShell, StorageWMI, DismCmdlets)
1616
with matching en-us language packs.
1717
6. Extract PowerShell 7 into \Tools\PowerShell7 inside the mounted image.
18-
7. Save AzStackHci.EnvironmentChecker module offline into \Tools\Modules (skipped if
19-
-SkipModuleDownload is set or if the gallery is unreachable -- warning only).
18+
7. Stage AzStackHci.EnvironmentChecker module into \Tools\Modules. Copies from local
19+
-ModuleCachePath (default C:\build\modules) if present; otherwise downloads from
20+
PSGallery with a 5-minute timeout and caches locally. FAILS the build if unavailable.
2021
8. Copy Start-AzlValidation.ps1 and the config folder into \Tools.
2122
9. Write startnet.cmd into \Windows\System32\startnet.cmd.
2223
10. Set scratch space to 512 MB.
@@ -115,6 +116,9 @@ param(
115116
[Parameter(Mandatory = $false)]
116117
[string]$ConfigPath = '',
117118

119+
[Parameter(Mandatory = $false)]
120+
[string]$ModuleCachePath = 'C:\build\modules',
121+
118122
[Parameter(Mandatory = $false)]
119123
[switch]$SkipModuleDownload,
120124

@@ -499,23 +503,37 @@ try {
499503
Write-Step "PowerShell 7 extracted to $ps7Dest" -Level Success
500504
}
501505

502-
# --- Step 7: Save offline module ---
503-
Write-Step 'Step 7: Saving AzStackHci.EnvironmentChecker module...'
506+
# --- Step 7: Stage AzStackHci.EnvironmentChecker module ---
507+
Write-Step 'Step 7: Staging AzStackHci.EnvironmentChecker module (mandatory)...'
504508
$moduleDest = Join-Path $MOUNT_PATH "$TOOLS_DIR\Modules"
505-
if (-not $SkipModuleDownload) {
506-
New-Item -ItemType Directory -Path $moduleDest -Force | Out-Null
507-
try {
508-
Save-Module -Name $PS_GALLERY_MODULE -Path $moduleDest -Force -ErrorAction Stop
509-
Write-Step "$PS_GALLERY_MODULE saved successfully." -Level Success
510-
}
511-
catch {
512-
Write-Warning "Save-Module failed for '$PS_GALLERY_MODULE': $_"
513-
Write-Warning 'The module will NOT be present in the image. The image will still boot.'
514-
Write-Warning "Pre-stage it manually at $moduleDest and rebuild, or use -SkipModuleDownload."
515-
}
509+
New-Item -ItemType Directory -Path $moduleDest -Force | Out-Null
510+
511+
$cacheModule = Join-Path $ModuleCachePath $PS_GALLERY_MODULE
512+
if (Test-Path $cacheModule) {
513+
Write-Step "Module found in local cache ($ModuleCachePath) — copying into image..."
514+
Copy-Item -Path $cacheModule -Destination $moduleDest -Recurse -Force
515+
Write-Step "$PS_GALLERY_MODULE staged from cache." -Level Success
516+
}
517+
elseif ($SkipModuleDownload) {
518+
throw "Module '$PS_GALLERY_MODULE' not found in cache '$ModuleCachePath' and -SkipModuleDownload is set. " +
519+
"Pre-stage the module by running: Save-Module -Name $PS_GALLERY_MODULE -Path '$ModuleCachePath' -Force"
516520
}
517521
else {
518-
Write-Step "Module download skipped (-SkipModuleDownload). Pre-stage at: $moduleDest" -Level Warning
522+
Write-Step "Cache miss — downloading from PSGallery (5-min timeout)..."
523+
$job = Start-Job {
524+
Save-Module -Name $using:PS_GALLERY_MODULE -Path $using:ModuleCachePath -Force -ErrorAction Stop
525+
}
526+
$completed = $job | Wait-Job -Timeout 300
527+
if ($completed -and $job.State -eq 'Completed') {
528+
$job | Remove-Job -Force
529+
Copy-Item -Path $cacheModule -Destination $moduleDest -Recurse -Force
530+
Write-Step "$PS_GALLERY_MODULE downloaded and staged." -Level Success
531+
}
532+
else {
533+
$job | Stop-Job -PassThru | Remove-Job -Force
534+
throw "Save-Module timed out after 300s — PSGallery unreachable. " +
535+
"Pre-stage the module: Save-Module -Name $PS_GALLERY_MODULE -Path '$ModuleCachePath' -Force"
536+
}
519537
}
520538

521539
# --- Step 8: Copy validation artifacts ---

0 commit comments

Comments
 (0)