From 823a747afd02fb4340b597f3f7f4c20113291fcf Mon Sep 17 00:00:00 2001 From: Daniel Jurek Date: Wed, 1 Oct 2025 18:35:13 +0000 Subject: [PATCH 1/4] Set up vcpkg cache variables in eng/common --- .../templates/steps/set-vcpkg-cache-vars.yml | 19 ++++++++ .../scripts/Set-VcpkgWriteModeCache.ps1 | 46 +++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 eng/common/pipelines/templates/steps/set-vcpkg-cache-vars.yml create mode 100755 eng/common/scripts/Set-VcpkgWriteModeCache.ps1 diff --git a/eng/common/pipelines/templates/steps/set-vcpkg-cache-vars.yml b/eng/common/pipelines/templates/steps/set-vcpkg-cache-vars.yml new file mode 100644 index 000000000000..7ba4d9018875 --- /dev/null +++ b/eng/common/pipelines/templates/steps/set-vcpkg-cache-vars.yml @@ -0,0 +1,19 @@ +steps: + - pwsh: | + Write-Host "Setting vcpkg cache variables for read only access to vcpkg binary and asset caches" + Write-Host '##vso[task.setvariable variable=VCPKG_BINARY_SOURCES_SECRET;issecret=true;]clear;x-azcopy,https://azuresdkartifacts.blob.core.windows.net/public-vcpkg-container,read' + Write-Host '##vso[task.setvariable variable=X_VCPKG_ASSET_SOURCES_SECRET;issecret=true;]clear;x-azurl,https://azuresdkartifacts.blob.core.windows.net/public-vcpkg-container,,read' + displayName: Set vcpkg variables + + - ${{if eq(variables['System.TeamProject'], 'internal') }}: + - task: AzurePowerShell@5 + displayName: Set Vcpkg Write-mode Cache + inputs: + azureSubscription: 'Azure SDK Artifacts' + ScriptType: FilePath + ScriptPath: eng/common/scripts/Set-VcpkgWriteModeCache.ps1 + azurePowerShellVersion: LatestVersion + pwsh: true + # This step is idempotent and can be run multiple times in cases of + # failure and partial execution. + retryCountOnTaskFailure: 3 diff --git a/eng/common/scripts/Set-VcpkgWriteModeCache.ps1 b/eng/common/scripts/Set-VcpkgWriteModeCache.ps1 new file mode 100755 index 000000000000..5c35eb12b053 --- /dev/null +++ b/eng/common/scripts/Set-VcpkgWriteModeCache.ps1 @@ -0,0 +1,46 @@ +#!/bin/env pwsh +param( + [string] $StorageAccountName = 'azuresdkartifacts', + [string] $StorageContainerName = 'public-vcpkg-container' +) + +. "$PSScriptRoot/../common/scripts/Helpers/PSModule-Helpers.ps1" + +Write-Host "`$env:PSModulePath = $($env:PSModulePath)" + +# Work around double backslash +if ($IsWindows) { + $hostedAgentModulePath = $env:SystemDrive + "\\Modules" + $moduleSeperator = ";" +} +else { + $hostedAgentModulePath = "/usr/share" + $moduleSeperator = ":" +} +$modulePaths = $env:PSModulePath -split $moduleSeperator +$modulePaths = $modulePaths.Where({ !$_.StartsWith($hostedAgentModulePath) }) +$AzModuleCachePath = (Get-ChildItem "$hostedAgentModulePath/az_*" -Attributes Directory) -join $moduleSeperator +if ($AzModuleCachePath -and $env.PSModulePath -notcontains $AzModuleCachePath) { + $modulePaths += $AzModuleCachePath +} + +$env:PSModulePath = $modulePaths -join $moduleSeperator + +Install-ModuleIfNotInstalled "Az.Storage" "4.3.0" | Import-Module + +$ctx = New-AzStorageContext ` + -StorageAccountName $StorageAccountName ` + -UseConnectedAccount + +$vcpkgBinarySourceSas = New-AzStorageContainerSASToken ` + -Name $StorageContainerName ` + -Permission "rwcl" ` + -Context $ctx ` + -ExpiryTime (Get-Date).AddHours(1) + +Write-Host "Ensure redaction of SAS tokens in logs" +Write-Host "##vso[task.setvariable variable=VCPKG_BINARY_SAS_TOKEN;issecret=true;]$vcpkgBinarySourceSas" + +Write-Host "Setting vcpkg binary cache to read and write" +Write-Host "##vso[task.setvariable variable=VCPKG_BINARY_SOURCES_SECRET;issecret=true;]clear;x-azcopy-sas,https://$StorageAccountName.blob.core.windows.net/$StorageContainerName,$vcpkgBinarySourceSas,readwrite" +Write-Host "##vso[task.setvariable variable=X_VCPKG_ASSET_SOURCES_SECRET;issecret=true;]clear;x-azurl,https://$StorageAccountName.blob.core.windows.net/$StorageContainerName,$vcpkgBinarySourceSas,readwrite" From 71d1dc0c25d1445e16c5528e8b1803a76abfe007 Mon Sep 17 00:00:00 2001 From: Daniel Jurek Date: Wed, 1 Oct 2025 18:46:12 +0000 Subject: [PATCH 2/4] Paths --- eng/common/scripts/Set-VcpkgWriteModeCache.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/eng/common/scripts/Set-VcpkgWriteModeCache.ps1 b/eng/common/scripts/Set-VcpkgWriteModeCache.ps1 index 5c35eb12b053..a0781edab941 100755 --- a/eng/common/scripts/Set-VcpkgWriteModeCache.ps1 +++ b/eng/common/scripts/Set-VcpkgWriteModeCache.ps1 @@ -4,7 +4,7 @@ param( [string] $StorageContainerName = 'public-vcpkg-container' ) -. "$PSScriptRoot/../common/scripts/Helpers/PSModule-Helpers.ps1" +. "$PSScriptRoot/Helpers/PSModule-Helpers.ps1" Write-Host "`$env:PSModulePath = $($env:PSModulePath)" @@ -20,7 +20,7 @@ else { $modulePaths = $env:PSModulePath -split $moduleSeperator $modulePaths = $modulePaths.Where({ !$_.StartsWith($hostedAgentModulePath) }) $AzModuleCachePath = (Get-ChildItem "$hostedAgentModulePath/az_*" -Attributes Directory) -join $moduleSeperator -if ($AzModuleCachePath -and $env.PSModulePath -notcontains $AzModuleCachePath) { +if ($AzModuleCachePath -and $env:PSModulePath -notcontains $AzModuleCachePath) { $modulePaths += $AzModuleCachePath } From 230ba802ee26da60db0ea529c8626dfdf819335a Mon Sep 17 00:00:00 2001 From: Daniel Jurek Date: Wed, 1 Oct 2025 23:07:19 +0000 Subject: [PATCH 3/4] Remove module code, it's not necessary anymore --- .../scripts/Set-VcpkgWriteModeCache.ps1 | 24 ------------------- 1 file changed, 24 deletions(-) diff --git a/eng/common/scripts/Set-VcpkgWriteModeCache.ps1 b/eng/common/scripts/Set-VcpkgWriteModeCache.ps1 index a0781edab941..a8810b88a510 100755 --- a/eng/common/scripts/Set-VcpkgWriteModeCache.ps1 +++ b/eng/common/scripts/Set-VcpkgWriteModeCache.ps1 @@ -4,30 +4,6 @@ param( [string] $StorageContainerName = 'public-vcpkg-container' ) -. "$PSScriptRoot/Helpers/PSModule-Helpers.ps1" - -Write-Host "`$env:PSModulePath = $($env:PSModulePath)" - -# Work around double backslash -if ($IsWindows) { - $hostedAgentModulePath = $env:SystemDrive + "\\Modules" - $moduleSeperator = ";" -} -else { - $hostedAgentModulePath = "/usr/share" - $moduleSeperator = ":" -} -$modulePaths = $env:PSModulePath -split $moduleSeperator -$modulePaths = $modulePaths.Where({ !$_.StartsWith($hostedAgentModulePath) }) -$AzModuleCachePath = (Get-ChildItem "$hostedAgentModulePath/az_*" -Attributes Directory) -join $moduleSeperator -if ($AzModuleCachePath -and $env:PSModulePath -notcontains $AzModuleCachePath) { - $modulePaths += $AzModuleCachePath -} - -$env:PSModulePath = $modulePaths -join $moduleSeperator - -Install-ModuleIfNotInstalled "Az.Storage" "4.3.0" | Import-Module - $ctx = New-AzStorageContext ` -StorageAccountName $StorageAccountName ` -UseConnectedAccount From d3d67770b6f2f4d420f62b4775a0d5dfaddda15e Mon Sep 17 00:00:00 2001 From: Daniel Jurek Date: Wed, 1 Oct 2025 23:12:13 +0000 Subject: [PATCH 4/4] Review feedback: Write-Host -> # --- eng/common/scripts/Set-VcpkgWriteModeCache.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/common/scripts/Set-VcpkgWriteModeCache.ps1 b/eng/common/scripts/Set-VcpkgWriteModeCache.ps1 index a8810b88a510..51bfab05c22a 100755 --- a/eng/common/scripts/Set-VcpkgWriteModeCache.ps1 +++ b/eng/common/scripts/Set-VcpkgWriteModeCache.ps1 @@ -14,7 +14,7 @@ $vcpkgBinarySourceSas = New-AzStorageContainerSASToken ` -Context $ctx ` -ExpiryTime (Get-Date).AddHours(1) -Write-Host "Ensure redaction of SAS tokens in logs" +# Ensure redaction of SAS tokens in logs Write-Host "##vso[task.setvariable variable=VCPKG_BINARY_SAS_TOKEN;issecret=true;]$vcpkgBinarySourceSas" Write-Host "Setting vcpkg binary cache to read and write"