Skip to content

Commit

Permalink
[windows] warmup Azure CLI (actions#8427)
Browse files Browse the repository at this point in the history
* [windows] warmup Azure CLI

Improve Azure CLI first run timing.
Follow up: actions#8294

Co-authored-by: Jesse Houwing <[email protected]>

* expose AZURE_EXTENSION_DIR to image generation

* suppress az warmup output

* refresh PATH before warmup

---------

Co-authored-by: Jesse Houwing <[email protected]>
  • Loading branch information
ilia-shipitsin and jessehouwing authored Oct 5, 2023
1 parent fbaf4c6 commit 0795b9e
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions images/win/scripts/Installers/Install-AzureCli.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,33 @@
## Desc: Install Azure CLI
################################################################################

Write-Host "Install the latest Azure CLI release"
$azCliUrl = "https://aka.ms/installazurecliwindowsx64"
Install-Binary -Url $azCliUrl -Name "azure-cli.msi"
Write-Host 'Install the latest Azure CLI release'

$azureCliConfigPath = 'C:\azureCli'
# Store azure-cli cache outside of the provisioning user's profile
[Environment]::SetEnvironmentVariable('AZURE_CONFIG_DIR', $azureCliConfigPath, [System.EnvironmentVariableTarget]::Machine)
# make variable to be available in the current session
${env:AZURE_CONFIG_DIR} = $azureCliConfigPath

$azCliUrl = 'https://aka.ms/installazurecliwindowsx64'
Install-Binary -Url $azCliUrl -Name 'azure-cli.msi'

$azureCliExtensionPath = Join-Path $Env:CommonProgramFiles 'AzureCliExtensionDirectory'
$null = New-Item -ItemType "Directory" -Path $azureCliExtensionPath
$null = New-Item -ItemType 'Directory' -Path $azureCliExtensionPath

[Environment]::SetEnvironmentVariable('AZURE_EXTENSION_DIR', $azureCliExtensionPath, [System.EnvironmentVariableTarget]::Machine)
# make variable to be available in the current session
${env:AZURE_EXTENSION_DIR} = $azureCliExtensionPath

# Warm-up Azure CLI

Write-Host "Warmup 'az'"

[Environment]::SetEnvironmentVariable("AZURE_EXTENSION_DIR", $azureCliExtensionPath, [System.EnvironmentVariableTarget]::Machine)
$env:PATH = [Environment]::GetEnvironmentVariable('PATH', 'Machine')
az --help | Out-Null
if ($LASTEXITCODE -ne 0)
{
throw "Command 'az --help' failed"
}

Invoke-PesterTests -TestFile "CLI.Tools" -TestName "Azure CLI"
Invoke-PesterTests -TestFile 'CLI.Tools' -TestName 'Azure CLI'

0 comments on commit 0795b9e

Please sign in to comment.