Azure Image Builder -以编程方式定位特定映像模板构建的打包程序日志

hmtdttj4  于 2023-01-14  发布在  其他
关注(0)|答案(2)|浏览(100)
    • TL;医生**

我如何以编程方式从Azure Image Builder模板构建的示例向下钻取以查找构建的customization.log文件?

    • 详细版本**

我最近开始使用Azure Image Builder,并且在某种程度上,我已经有了一个CI管道,用于从源存储库中的文件部署和构建图像模板到共享图像库中。
在我的构建过程结束时,我想检索Azure Image Builder生成的packerlogs\<guid>\customization.log文件-我可以通过在门户中单击来找到它(见下面的屏幕截图),但我很难通过任何形式的breadbrumb线索以编程方式定位blob。

也许有一个非常简单的方法可以做到这一点,我正在做一个巨大的Pig耳朵,但这里是我到目前为止得到的:

  • 在生成过程中,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?
xdnvmnnf

xdnvmnnf1#

最后,我现在删除并重新创建图像模板,每次我用它来构建一个新的图像版本。
这会导致临时资源组被删除并重新创建,因此在构建过程结束时,packerlogs容器下只有一个文件夹。
结果是Get-AzStorageBlob -Context $context -Container $packerlogs.Name -Blob "*/customization.log"只返回一个blob,我可以放心地(?)假设这就是我的构建版本的blob。
这看起来像是一种信仰的飞跃,但是我看不到任何其他可靠的方法来将构建示例关联到打包器日志容器下的相关文件夹,所以现在只能这样了...

pcww981p

pcww981p2#

在计算库中已发布版本的映像中,有一个名为“correlationid”的Azure标记。该标记值可用于引用回packerlogs容器下存储帐户中的Blob:打包程序日志$相关ID\自定义. log。

相关问题