Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Runs az and az-devops during warmup #8294

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
247967c
Fixes slow startup of `az` and `az devops`
jessehouwing Sep 14, 2023
6261205
Adds helpers to refresh the `$env:path`
jessehouwing Sep 19, 2023
cd78c1f
Uses environment functions from ImageHelpers
jessehouwing Sep 19, 2023
81b44e8
Copies Invoke-ValidateCommand from the mac helpers
jessehouwing Sep 19, 2023
3f65f32
Uses Invoke-ValidateCommand to configure az-zli and run warmup
jessehouwing Sep 19, 2023
82e0603
Switches '[int]` for `[uint]` on Windows PS5
jessehouwing Sep 19, 2023
d8ff5a1
Suppresses warning about experimental status of `az config`
jessehouwing Sep 20, 2023
c1b3d6b
Do not disable file logging for now.
jessehouwing Sep 20, 2023
0aacdc6
Update Install-AzureCli.ps1
jessehouwing Sep 20, 2023
3dd6743
Properly turns off survey messages
jessehouwing Sep 21, 2023
8d92ec2
Update Install-AzureCli.ps1
jessehouwing Sep 22, 2023
b85a098
Update Install-AzureDevOpsCli.ps1
jessehouwing Sep 22, 2023
6ff129b
Update Install-AzureDevOpsCli.ps1
jessehouwing Sep 22, 2023
10eaf15
fix quotes around dummy
jessehouwing Sep 22, 2023
67b4a8d
Imrpoves comment
jessehouwing Sep 22, 2023
ad59f07
How did that `uint` sneak back in...
jessehouwing Sep 22, 2023
7900076
Update Install-AzureDevOpsCli.ps1
jessehouwing Sep 22, 2023
129a955
Find python from the path of `az`
jessehouwing Sep 22, 2023
a67e883
And lets try ignoring the error to see what happens.
jessehouwing Sep 22, 2023
03dc291
Update Install-AzureDevOpsCli.ps1
jessehouwing Sep 22, 2023
e38336b
Update images/win/scripts/ImageHelpers/PathHelpers.ps1
jessehouwing Sep 29, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions images/win/scripts/ImageHelpers/ImageHelpers.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,22 @@ Export-ModuleMember -Function @(
'Disconnect-Hive'
'Test-MachinePath'
'Get-MachinePath'
'Get-UserPath'
'Get-DefaultPath'
'Set-MachinePath'
'Set-DefaultPath'
'Update-Path'
'Add-MachinePathItem'
'Add-DefaultPathItem'
'Add-DefaultItem'
'Get-SystemVariable'
'Get-UserVariable'
'Get-DefaultVariable'
'Set-SystemVariable'
'Set-DefaultVariable'
'Install-Binary'
'Install-VisualStudio'
'Invoke-ValidateCommand'
'Get-ToolsetContent'
'Get-ToolsetToolFullPath'
'Stop-SvcWithErrHandling'
Expand Down
82 changes: 78 additions & 4 deletions images/win/scripts/ImageHelpers/InstallHelpers.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,43 @@ function Get-GitHubPackageDownloadUrl {
return $downloadUrl
}

function Invoke-ValidateCommand {
param(
[Parameter(Mandatory)]
[string]$Command,
[int] $Timeout = 0
)

if ($Timeout -eq 0)
{
$output = Invoke-Expression -Command $Command
if ($LASTEXITCODE -ne 0) {
throw "Command '$Command' has finished with exit code $LASTEXITCODE"
}
return $output
}
else
{
$job = $command | Start-Job -ScriptBlock {
$output = Invoke-Expression -Command $input
if ($LASTEXITCODE -ne 0) {
throw 'Command failed'
}
return $output
}
$waitObject = $job | Wait-Job -Timeout $Timeout
if(-not $waitObject)
{
throw "Command '$Command' has timed out"
}
if($waitObject.State -eq 'Failed')
{
throw "Command '$Command' has failed"
}
Receive-Job -Job $job
}
}

function Use-ChecksumComparison {
param (
[Parameter(Mandatory=$true)]
Expand Down Expand Up @@ -691,7 +728,7 @@ function Get-HashFromGitHubReleaseBody {
}
}
$body = (Invoke-RestMethod -Uri $releaseUrl).body -replace('`', "") -join "`n"
$matchingLine = $body.Split("`n") | Where-Object { $_ -like "*$FileName*" }
$matchingLine = $body.Split("`n") | Where-Object { $_ -like "*$FileName*" }
if ([string]::IsNullOrEmpty($matchingLine)) {
throw "File name '$FileName' not found in release body."
}
Expand All @@ -708,9 +745,9 @@ function Test-FileSignature {
[Parameter(Mandatory=$true)]
[string]$ExpectedThumbprint
)

$signature = Get-AuthenticodeSignature $FilePath

if ($signature.Status -ne "Valid") {
throw "Signature status is not valid. Status: $($signature.Status)"
}
Expand All @@ -720,4 +757,41 @@ function Test-FileSignature {
}

Write-Output "Signature for $FilePath is valid"
}
}

function Invoke-ValidateCommand {
param(
[Parameter(Mandatory)]
[string]$Command,
[int] $Timeout = 0
)

if ($Timeout -eq 0)
{
$output = Invoke-Expression -Command $Command
if ($LASTEXITCODE -ne 0) {
throw "Command '$Command' has finished with exit code $LASTEXITCODE"
}
return $output
}
else
{
$job = $command | Start-Job -ScriptBlock {
$output = Invoke-Expression -Command $input
if ($LASTEXITCODE -ne 0) {
throw 'Command failed'
}
return $output
}
$waitObject = $job | Wait-Job -Timeout $Timeout
if(-not $waitObject)
{
throw "Command '$Command' has timed out"
}
if($waitObject.State -eq 'Failed')
{
throw "Command '$Command' has failed"
}
Receive-Job -Job $job
}
}
16 changes: 16 additions & 0 deletions images/win/scripts/ImageHelpers/PathHelpers.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ function Disconnect-Hive {
}
}

function Get-UserVariable {
param(
[string]$UserVariable
)

[System.Environment]::GetEnvironmentVariable($UserVariable, "User")
}

function Get-SystemVariable {
param(
[string]$SystemVariable
Expand Down Expand Up @@ -80,10 +88,18 @@ function Set-DefaultVariable {
[System.GC]::Collect()
}

function Update-Path {
$env:Path = (Get-MachinePath) + ";" + (Get-UserPath)
}

function Get-MachinePath {
Get-SystemVariable PATH
}

function Get-UserPath {
Get-UserVariable PATH
}

function Get-DefaultPath {
Get-DefaultVariable Path
}
Expand Down
28 changes: 26 additions & 2 deletions images/win/scripts/Installers/Install-AzureCli.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,34 @@
Write-Host "Install the latest Azure CLI release"
$azCliUrl = "https://aka.ms/installazurecliwindowsx64"
Install-Binary -Url $azCliUrl -Name "azure-cli.msi"
Update-Path

# Store cli extensions outside of the provisioning user's profile
$azureCliExtensionPath = Join-Path $Env:CommonProgramFiles 'AzureCliExtensionDirectory'
$null = New-Item -ItemType "Directory" -Path $azureCliExtensionPath
$env:AZURE_EXTENSION_DIR = Set-SystemVariable -SystemVariable "AZURE_EXTENSION_DIR" -value $azureCliExtensionPath

[Environment]::SetEnvironmentVariable("AZURE_EXTENSION_DIR", $azureCliExtensionPath, [System.EnvironmentVariableTarget]::Machine)
# Store cli config outside of the provisioning user's profile
$azureCliConfigPath = Join-Path $Env:CommonProgramFiles 'AzureCliDirectory'
$null = New-Item -ItemType "Directory" -Path $azureCliConfigPath
$env:AZURE_CONFIG_DIR = Set-SystemVariable -SystemVariable "AZURE_CONFIG_DIR" -value $azureCliConfigPath

Invoke-PesterTests -TestFile "CLI.Tools" -TestName "Azure CLI"
# Turn use automation recommended settings to speed up first-call on the hosted runner images.
# See: https://techcommunity.microsoft.com/t5/azure-tools-blog/streamline-configuring-azure-cli-with-az-init/ba-p/3051810

Write-Host "Setting automation defaults for 'az'"
Invoke-ValidateCommand -Command "az config set auto-upgrade.enable=false --only-show-errors"
Invoke-ValidateCommand -Command "az config set core.error_recommendation=off --only-show-errors"
Invoke-ValidateCommand -Command "az config set core.disable_progress_bar=true --only-show-errors"
Invoke-ValidateCommand -Command "az config set core.no_color=true --only-show-errors"
Invoke-ValidateCommand -Command "az config set core.survey_message=false --only-show-errors"

# Though recommended by az init, this may be a breaking change.
# Invoke-ValidateCommand -Command "az config set logging.enable_log_file=no --only-show-errors"


jessehouwing marked this conversation as resolved.
Show resolved Hide resolved
# Warm-up Azure CLI
Write-Host "Warmup 'az'"
Invoke-ValidateCommand -Command "az --help"

Invoke-PesterTests -TestFile "CLI.Tools" -TestName "Azure CLI"
25 changes: 23 additions & 2 deletions images/win/scripts/Installers/Install-AzureDevOpsCli.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,27 @@
## Desc: Install Azure DevOps CLI
################################################################################

az extension add -n azure-devops
# Store azure-devops-cli cache outside of the provisioning user's profile
$azureDevOpsCliConfigPath = Join-Path $Env:CommonProgramFiles 'AzureDevOpsCliConfigDirectory'
$null = New-Item -ItemType "Directory" -Path $azureDevOpsCliConfigPath
$env:AZURE_DEVOPS_EXT_CONFIG_DIR = Set-SystemVariable -SystemVariable "AZURE_DEVOPS_EXT_CONFIG_DIR" -value $azureDevOpsCliConfigPath

Invoke-PesterTests -TestFile "CLI.Tools" -TestName "Azure DevOps CLI"
$azureDevOpsCliCachePath = Join-Path $azureDevOpsCliConfigPath "cache"
$null = New-Item -ItemType "Directory" -Path $azureDevOpsCliCachePath
$env:AZURE_DEVOPS_CACHE_DIR = Set-SystemVariable -SystemVariable "AZURE_DEVOPS_CACHE_DIR" -value $azureDevOpsCliCachePath

Invoke-ValidateCommand -Command "az extension add -n azure-devops"

# Warm-up Azure DevOps CLI

Write-Host "Warmup 'az-devops'"
@("devops", "pipelines", "boards", "repos", "artifacts") | ForEach-Object {
Invoke-ValidateCommand -Command "az $_ --help"
}

# calling az devops login to force it to install `keyring`. Login will actually fail, redirecting error to null
echo "dummy" | az devops login | out-null
# calling az devops logout to be sure no credentials remain.
az devops logout | out-null

Invoke-PesterTests -TestFile "CLI.Tools" -TestName "Azure DevOps CLI"
3 changes: 1 addition & 2 deletions images/win/scripts/Installers/Warmup-User.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,4 @@ reg.exe load HKLM\DEFAULT c:\users\default\ntuser.dat
reg.exe copy HKCU\Software\Microsoft\VisualStudio HKLM\DEFAULT\Software\Microsoft\VisualStudio /s
reg.exe unload HKLM\DEFAULT


Write-Host "Warmup-User.ps1 - completed"
Write-Host "Warmup-User.ps1 - completed"