|
15 | 15 | 5. Add WinPE optional components (WMI, NetFX, Scripting, PowerShell, StorageWMI, DismCmdlets) |
16 | 16 | with matching en-us language packs. |
17 | 17 | 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. |
20 | 21 | 8. Copy Start-AzlValidation.ps1 and the config folder into \Tools. |
21 | 22 | 9. Write startnet.cmd into \Windows\System32\startnet.cmd. |
22 | 23 | 10. Set scratch space to 512 MB. |
@@ -115,6 +116,9 @@ param( |
115 | 116 | [Parameter(Mandatory = $false)] |
116 | 117 | [string]$ConfigPath = '', |
117 | 118 |
|
| 119 | + [Parameter(Mandatory = $false)] |
| 120 | + [string]$ModuleCachePath = 'C:\build\modules', |
| 121 | + |
118 | 122 | [Parameter(Mandatory = $false)] |
119 | 123 | [switch]$SkipModuleDownload, |
120 | 124 |
|
@@ -499,23 +503,37 @@ try { |
499 | 503 | Write-Step "PowerShell 7 extracted to $ps7Dest" -Level Success |
500 | 504 | } |
501 | 505 |
|
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)...' |
504 | 508 | $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" |
516 | 520 | } |
517 | 521 | 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 | + } |
519 | 537 | } |
520 | 538 |
|
521 | 539 | # --- Step 8: Copy validation artifacts --- |
|
0 commit comments