tl;博士
如何以编程方式从 Azure Image Builder 模板构建实例向下钻取以查找构建customization.log
文件?
长版
我最近开始使用 Azure Image Builder,经过一段时间后,我有了一个 CI 管道,可以将源存储库中的文件中的图像模板部署和构建到共享图像库中。
在我的构建过程结束时,我想检索packerlogs\<guid>\customization.log
由 Azure Image Builder 生成的文件 - 我可以通过在门户中单击来找到它(见下面的屏幕截图),但我正在努力遵循任何类型的面包屑线索以编程方式定位 blob。
也许有一个非常简单的方法可以做到这一点,我正在制作一个巨大的猪耳朵,但这是我到目前为止所得到的:
在生成过程中,Azure Image Builder 会创建一个名为的临时资源组
IT_<gallery-resource-group-name>_<image-template-name>_<guid>
,用于存储自定义日志。这还具有以下标签,可用于查找正确的资源组:"createdBy" = "AzureVMImageBuilder"
"imageTemplateResourceGroupName" = "<shared image gallery resource group name>"
"imageTemplateName" = "<image template name>"
在临时资源组中,有一个具有 24 个字符随机名称的存储帐户 - 例如
abc123def456ghi789j01234
在存储帐户中有一个名为
packerlogs
在存储帐户容器中,一些 blob 以
<guid>\customization.log
.到目前为止,我不知道
<guid>
使用哪个来过滤特定构建实例的结果。我可以使用时间戳来读取最新的时间戳,但我怎么知道这对于任何给定的图像模板构建都是正确的。例如,哪个<guid>
属于我的图像模板的图像版本 1.0.55 的构建过程?
这是我到目前为止的代码:
# this is my starting point - I've got an image template that I've built using Start-AzImageBuilderTemplate
# and it's successfully created a new image version in a shared image gallery
$myImageGallery = ...
$myImageDefinition = ...
$myImageTemplate = ...
$myImageVersion = ...
# find the temporary resource group with the appropriate tags for the image template
$temporaryResourceGroup = Get-AzResourceGroup -Tag @{ "createdBy" = "AzureVMImageBuilder" } `
| where-object {
($_.Tags.imageTemplateResourceGroupName -eq $myImageGallery.ResourceGroupName) -and
($_.Tags.imageTemplateName -eq $myImageTemplate.Name)
};
# get a reference to the single storage account in the resource group
$storageAccount = Get-AzResource -ResourceGroupName $temporaryResourceGroup.ResourceGroupName `
-ResourceType "Microsoft.Storage/storageAccounts";
# find the "packerlogs" container
$storageKey = ($storageAccount | Get-AzStorageAccountKey)[0].Value
$context = New-AzStorageContext -StorageAccountName $storageAccount.Name -StorageAccountKey $storageKey
$packerlogs = Get-AzStorageContainer -Context $context -Name "packerlogs";
# get the list of blobs that represent the customization logs from each of the individual template builds
$blobs = Get-AzStorageBlob -Context $context -Container $packerlogs.Name -Blob "*/customization.log";
# but which blob do I want for $myImageVersion?