If you have AVD Host Pools in multiple regions and you are using App Attach you will want to replicate your packages to a Azure Storage account in the same region. Here’s a script that will copy your MSIX App Attach files from your Primary/Source Storage Account to other Storage Accounts.
This uses AZCopy, KeyVault and can be used with GitHub Actions to automatically run.
#Add Check for Available Space
#Todo: If less than 10GB, add space.
# Download and extract AzCopy for Linux. You can change this to Windows AZCopy if you want.
$azCopyDownloadURL = "https://aka.ms/downloadazcopy-v10-linux"
$downloadLocation = "$env:RUNNER_TEMP/AzCopy.tar.gz"
$extractLocation = "$env:RUNNER_TEMP/AzCopy"
$azCopyPath = "${extractLocation}/azcopy_linux_amd64_10.19.0/azcopy"
# Check if AzCopy exists
if (-not (Test-Path $azCopyPath)) {
Write-Output "AzCopy not found at $azCopyPath. Downloading and extracting..."
# Download AzCopy
Invoke-WebRequest -Uri $azCopyDownloadURL -OutFile $downloadLocation
# Ensure the extraction directory exists
New-Item -ItemType Directory -Force -Path $extractLocation
# Extract AzCopy
Invoke-Expression "tar -xzvf $downloadLocation -C $extractLocation"
# Make AzCopy executable
Invoke-Expression "chmod +x $azCopyPath"
if (-not (Test-Path $azCopyPath)) {
Write-Output "Failed to download or extract AzCopy. Exiting."
Exit
}
}
#Gets SAS from KeyVault.
try {
$cmsixsas = Get-AzKeyVaultSecret -VaultName "KEYVAULT" -Name "cmsixsas" -AsPlainText
$wmsixsas = Get-AzKeyVaultSecret -VaultName "KEYVAULT" -Name "wmsixsas" -AsPlainText
$emsixsas = Get-AzKeyVaultSecret -VaultName "KEYVAULT" -Name "emsixsas" -AsPlainText
$w2msixsas = Get-AzKeyVaultSecret -VaultName "KEYVAULT" -Name "w2msixsas" -AsPlainText
}
catch {
Write-Error "Error retrieving secrets from KeyVault: $_"
exit 1
}
# Define the source and destinations
$sourceShare = "https://source.file.core.windows.net/apps"
$destinations = @(
"https://dest1.file.core.windows.net/apps",
"https://dest2.file.core.windows.net/apps",
"https://dest3.file.core.windows.net/apps"
)
# For demonstration, we assume the source SAS token is the one for 'w2msix' since the URL matches.
$sourceSASToken = $w2msixsas
foreach ($destination in $destinations) {
# Find the corresponding SAS token for the destination
switch -regex ($destination) {
"cmsix" { $destSASToken = $cmsixsas }
"emsix" { $destSASToken = $emsixsas }
"wmsix" { $destSASToken = $wmsixsas }
}
# Construct the source and destination URLs with their respective SAS tokens
$sourceURL = "${sourceShare}${sourceSASToken}"
$destinationURL = "${destination}${destSASToken}"
Write-Output "Copying from $sourceURL to $destinationURL"
# Use AzCopy to copy with overwrite
& $azCopyPath copy $sourceURL $destinationURL --recursive=true --overwrite=false
# Check the exit code of AzCopy
if ($LASTEXITCODE -ne 0) {
Write-Error "AzCopy failed for source $sourceURL to destination $destinationURL"
exit 1
}
}
Write-Output "Copy operations completed."