Skip to content

Commit 5ff59ca

Browse files
[macos] use mist-cli for downloading OS distribution when generating anka clean vm (#8141)
1 parent 862df58 commit 5ff59ca

File tree

2 files changed

+5
-12
lines changed

2 files changed

+5
-12
lines changed

images.CI/macos/anka/CreateCleanAnkaTemplate.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ Remove-AnkaVM -VMName $TemplateName
180180

181181
Write-Host "`t[*] Creating Anka VM template with name '$TemplateName' and '$TemplateUsername' user"
182182
Write-Host "`t[*] CPU Count: $CPUCount, RamSize: ${RamSizeGb}G, DiskSizeGb: ${DiskSizeGb}G, InstallerPath: $macOSInstaller, TemplateName: $TemplateName"
183-
New-AnkaVMTemplate -InstallerPath $macOSInstaller `
183+
New-AnkaVMTemplate -InstallerPath "$macOSInstaller" `
184184
-TemplateName $TemplateName `
185185
-TemplateUsername $TemplateUsername `
186186
-TemplatePassword $TemplatePassword `

images.CI/macos/anka/Service.Helpers.psm1

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -180,26 +180,19 @@ function Get-MacOSInstaller {
180180
exit 1
181181
}
182182

183-
$installerPathPattern = "/Applications/Install macOS ${macOSName}*.app"
184-
if (Test-Path $installerPathPattern) {
185-
$previousInstallerPath = Get-Item -Path $installerPathPattern
186-
Write-Host "`t[*] Removing '$previousInstallerPath' installation app before downloading the new one"
187-
sudo rm -rf "$previousInstallerPath"
188-
}
189-
190183
# Clear LastRecommendedMajorOSBundleIdentifier to prevent error during fetching updates
191184
# Install failed with error: Update not found
192185
Update-SoftwareBundle
193186

194187
# Download macOS installer
195188
Write-Host "`t[*] Requested macOS '$MacOSVersion' version installer found, fetching it from Apple Software Update"
196-
$result = Invoke-WithRetry { /usr/sbin/softwareupdate --fetch-full-installer --full-installer-version $MacOSVersion } {$LASTEXITCODE -eq 0} | Out-String
197-
if (-not $result.Contains("Install finished successfully")) {
198-
Write-Host "`t[x] Failed to fetch $MacOSVersion macOS `n$result"
189+
Invoke-WithRetry -Command { sudo /usr/local/bin/mist download installer $MacOSVersion application --force --export installer.json --output-directory /Applications } -BreakCondition { $LASTEXITCODE -eq 0 } | Out-Null
190+
if (-not(Test-Path installer.json -PathType leaf)) {
191+
Write-Host "`t[x] Failed to fetch $MacOSVersion macOS"
199192
exit 1
200193
}
201194

202-
$installerPath = (Get-Item -Path $installerPathPattern).FullName
195+
$installerPath = (Get-Content installer.json | Out-String | ConvertFrom-Json).options.applicationPath
203196
if (-not $installerPath) {
204197
Write-Host "`t[x] Path not found using '$installerPathPattern'"
205198
exit 1

0 commit comments

Comments
 (0)