Skip to content

Commit 086d869

Browse files
danieljurekazure-sdk
authored andcommitted
Set up vcpkg cache variables in eng/common
1 parent 8b1307d commit 086d869

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
steps:
2+
- pwsh: |
3+
Write-Host "Setting vcpkg cache variables for read only access to vcpkg binary and asset caches"
4+
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'
5+
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'
6+
displayName: Set vcpkg variables
7+
8+
- ${{if eq(variables['System.TeamProject'], 'internal') }}:
9+
- task: AzurePowerShell@5
10+
displayName: Set Vcpkg Write-mode Cache
11+
inputs:
12+
azureSubscription: 'Azure SDK Artifacts'
13+
ScriptType: FilePath
14+
ScriptPath: eng/common/scripts/Set-VcpkgWriteModeCache.ps1
15+
azurePowerShellVersion: LatestVersion
16+
pwsh: true
17+
# This step is idempotent and can be run multiple times in cases of
18+
# failure and partial execution.
19+
retryCountOnTaskFailure: 3
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/bin/env pwsh
2+
param(
3+
[string] $StorageAccountName = 'azuresdkartifacts',
4+
[string] $StorageContainerName = 'public-vcpkg-container'
5+
)
6+
7+
. "$PSScriptRoot/../common/scripts/Helpers/PSModule-Helpers.ps1"
8+
9+
Write-Host "`$env:PSModulePath = $($env:PSModulePath)"
10+
11+
# Work around double backslash
12+
if ($IsWindows) {
13+
$hostedAgentModulePath = $env:SystemDrive + "\\Modules"
14+
$moduleSeperator = ";"
15+
}
16+
else {
17+
$hostedAgentModulePath = "/usr/share"
18+
$moduleSeperator = ":"
19+
}
20+
$modulePaths = $env:PSModulePath -split $moduleSeperator
21+
$modulePaths = $modulePaths.Where({ !$_.StartsWith($hostedAgentModulePath) })
22+
$AzModuleCachePath = (Get-ChildItem "$hostedAgentModulePath/az_*" -Attributes Directory) -join $moduleSeperator
23+
if ($AzModuleCachePath -and $env.PSModulePath -notcontains $AzModuleCachePath) {
24+
$modulePaths += $AzModuleCachePath
25+
}
26+
27+
$env:PSModulePath = $modulePaths -join $moduleSeperator
28+
29+
Install-ModuleIfNotInstalled "Az.Storage" "4.3.0" | Import-Module
30+
31+
$ctx = New-AzStorageContext `
32+
-StorageAccountName $StorageAccountName `
33+
-UseConnectedAccount
34+
35+
$vcpkgBinarySourceSas = New-AzStorageContainerSASToken `
36+
-Name $StorageContainerName `
37+
-Permission "rwcl" `
38+
-Context $ctx `
39+
-ExpiryTime (Get-Date).AddHours(1)
40+
41+
Write-Host "Ensure redaction of SAS tokens in logs"
42+
Write-Host "##vso[task.setvariable variable=VCPKG_BINARY_SAS_TOKEN;issecret=true;]$vcpkgBinarySourceSas"
43+
44+
Write-Host "Setting vcpkg binary cache to read and write"
45+
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"
46+
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"

0 commit comments

Comments
 (0)