Azure Image Builder - 如何指定 VM 映像版本

发布于 2025-01-11 09:23:00 字数 1226 浏览 0 评论 0原文

看来默认的三部分版本是某种时间戳。我希望能够在生成图像版本时指定版本号。我在故障排除指南中只看到版本格式的提及,但没有详细说明如何设置它。

例如 镜像版本名称应遵循Major(int).Minor(int).Patch(int)格式,例如:1.0.0、2018.12.1等。

在此处输入图像描述

我设置了分配器:

  $distributorObjectParameters = @{
    SharedImageDistributor = $true
    GalleryImageId         = $galleryImageId
    ReplicationRegion      = $Location
    ArtifactTag            = $tags
    RunOutputName          = $imageTemplateName
    ExcludeFromLatest      = $false
  }
  $distributorObject = New-AzImageBuilderDistributorObject @distributorObjectParameters

然后创建模板:

  $templateParameters = @{
    ImageTemplateName      = $imageTemplateName
    ResourceGroupName      = $imageResourceGroup
    Source                 = $sourceObject
    Distribute             = $distributorObject
    Customize              = $customizerCollection
    Location               = 'East US 2'
    UserAssignedIdentityId = $identityResourceId
    BuildTimeoutInMinute   = $buildTimeoutInMinute
  }
  New-AzImageBuilderTemplate @templateParameters

是否有一个我在设置版本值时忽略的参数?

It appears the default three part version is some sort of timestamp. I would like to be able to specify the version number when I generate the image versions. I see only a mention of the version format in a troubleshooting guide but no specifics on how to set it.

e.g.
The image version name should follow Major(int).Minor(int).Patch(int) format, for e.g: 1.0.0, 2018.12.1 etc.

enter image description here

I setup the distributor with:

  $distributorObjectParameters = @{
    SharedImageDistributor = $true
    GalleryImageId         = $galleryImageId
    ReplicationRegion      = $Location
    ArtifactTag            = $tags
    RunOutputName          = $imageTemplateName
    ExcludeFromLatest      = $false
  }
  $distributorObject = New-AzImageBuilderDistributorObject @distributorObjectParameters

Then create the template with:

  $templateParameters = @{
    ImageTemplateName      = $imageTemplateName
    ResourceGroupName      = $imageResourceGroup
    Source                 = $sourceObject
    Distribute             = $distributorObject
    Customize              = $customizerCollection
    Location               = 'East US 2'
    UserAssignedIdentityId = $identityResourceId
    BuildTimeoutInMinute   = $buildTimeoutInMinute
  }
  New-AzImageBuilderTemplate @templateParameters

Is there a parameter that I have overlooked for setting the version value?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

未央 2025-01-18 09:23:00

以下答案是来自微软的人在 GitHub 上提供的。
https://github.com/MicrosoftDocs/azure-docs/issues/ 89180#issuecomment-1063218290

发行商的名为 galleryImageId 的参数设置版本。该参数可以指定为以下两种格式之一:

  • 自动版本控制 - 格式为:
    /subscriptions//resourceGroups//providers/Microsoft.Compute/galleries//images/

  • 显式版本控制 - 格式为:
    /subscriptions//resourceGroups//providers/Microsoft.Compute/galleries//images//versions/;

供参考:
https://learn.microsoft.com/en-us/azure/virtual-machines/linux/image-builder-json#distribute-sharedimage" microsoft.com/en-us/azure/virtual-machines/linux/image-builder-json#distribute-sharedimage

为了测试它,我修改了我的分发服务器设置:

  $distributorObjectParameters = @{
    SharedImageDistributor = $true
    GalleryImageId         = "$($galleryImageId)/versions/0.0.1"
    ReplicationRegion      = $Location
    ArtifactTag            = $tags
    RunOutputName          = $imageTemplateName
    ExcludeFromLatest      = $false
  }
  $distributorObject = New-AzImageBuilderDistributorObject @distributorObjectParameter

并得到以下内容 结果:
输入图片此处描述

The following answer was provided by someone from Microsoft on GitHub.
https://github.com/MicrosoftDocs/azure-docs/issues/89180#issuecomment-1063218290

The parameter named galleryImageId for the distributor sets the version. The parameter can be specified as one of two formats:

  • Automatic versioning - The format is:
    /subscriptions/<subscriptionId>/resourceGroups/<resourceGroupName>/providers/Microsoft.Compute/galleries/<sharedImageGalleryName>/images/<imageGalleryName>

  • Explicit versioning - The format is:
    /subscriptions/<subscriptionId>/resourceGroups/<resourceGroupName>/providers/Microsoft.Compute/galleries/<sharedImageGalleryName>/images/<imageGalleryName>/versions/<version - for example: 1.1.1>

For reference:
https://learn.microsoft.com/en-us/azure/virtual-machines/linux/image-builder-json#distribute-sharedimage

To test it out, I modified my distributor setup with:

  $distributorObjectParameters = @{
    SharedImageDistributor = $true
    GalleryImageId         = "$($galleryImageId)/versions/0.0.1"
    ReplicationRegion      = $Location
    ArtifactTag            = $tags
    RunOutputName          = $imageTemplateName
    ExcludeFromLatest      = $false
  }
  $distributorObject = New-AzImageBuilderDistributorObject @distributorObjectParameter

and got the following result:
enter image description here

若无相欠,怎会相见 2025-01-18 09:23:00

我不认为你可以从 Azure 获得这个选项。在我们的项目中,我们使用 bash 和 az-cli 自行计算版本。

IMAGE_VERSIONS=$(az sig image-version list --gallery-image-definition "${image_definition_name}" --gallery-name "${image_gallery_name}" -g "${ARM_RESOURCE_GROUP}")
if [[ "${IMAGE_VERSIONS}" == "[]" ]]; then
    DESTINATION_IMAGE_VERSION="1.0.0"
else
    DESTINATION_IMAGE_VERSION=$(echo "${IMAGE_VERSIONS}" | grep -i "versions/" | tail -n 1 | rev | cut -d '/' -f1 | cut -d '"' -f2 | rev)
fi
DESTINATION_IMAGE_VERSION=$(echo "${DESTINATION_IMAGE_VERSION}" | awk -F. -v OFS=. 'NF==1{print ++$NF}; NF>1{if(length($NF+1)>length($NF))$(NF-1)++; $NF=sprintf("%0*d", length($NF), ($NF+1)%(10^length($NF))); print}')
echo $DESTINATION_IMAGE_VERSION

我们将初始版本实例化为1.0.0(第一次)&一旦设置,我们只需在下一次构建迭代中增加..

I don't think you can have that option from Azure. In our projects, we compute versions ourselves with bash and az-cli.

IMAGE_VERSIONS=$(az sig image-version list --gallery-image-definition "${image_definition_name}" --gallery-name "${image_gallery_name}" -g "${ARM_RESOURCE_GROUP}")
if [[ "${IMAGE_VERSIONS}" == "[]" ]]; then
    DESTINATION_IMAGE_VERSION="1.0.0"
else
    DESTINATION_IMAGE_VERSION=$(echo "${IMAGE_VERSIONS}" | grep -i "versions/" | tail -n 1 | rev | cut -d '/' -f1 | cut -d '"' -f2 | rev)
fi
DESTINATION_IMAGE_VERSION=$(echo "${DESTINATION_IMAGE_VERSION}" | awk -F. -v OFS=. 'NF==1{print ++$NF}; NF>1{if(length($NF+1)>length($NF))$(NF-1)++; $NF=sprintf("%0*d", length($NF), ($NF+1)%(10^length($NF))); print}')
echo $DESTINATION_IMAGE_VERSION

We instantiate the initial version to 1.0.0 (for the first time) & once set, we just increment in next build iterations..

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文