创建Azure linux VHD以在管道中使用



我想准备一个预安装依赖项(python、go等(的ubuntu映像,这样管道就不会浪费每次安装它们的时间。我希望能找到某种类似Dockerfile的接口,但我一直没能找到一种简单的方法来实现这一点。

我所理解的是,我需要用这个映像创建一个新的虚拟机规模集,然后将其用于代理池。但是我该如何创建vhd映像呢?

您可以使用以下工具之一在Azure上构建映像。

  1. packer-更多跨云的行业标准(如Hashicorp的Terraform(
  2. Azure Image Builder-仅适用于Azure(来自Microsoft(

以上两个工具都可以用于自定义Azure市场上可用的基本(金色(映像,或者如果您在prem上有现有的VM映像,可以在此处上传以下文档。

如果您有多个订阅&你想建立在一个订阅&在其他订阅/其他租户上使用它们,则需要使用Azure计算库。此库还可以帮助您对VM映像(如docker映像(进行版本设置。简而言之,它就像VM映像的docker注册表。

如果你想使用现有的市场镜像(在你的情况下是基于Ubuntu(,你不需要将它们转换成VHD。Packer/Azure Image Builder基本上会从基本映像中提供一个VM,安装包(根据您的选择进行定制(,创建VM的快照;由此创建一个图像。

使用packer,您将编写如下所示的JSON构建器。源代码取自此处。

{
"builders": [{
"type": "azure-arm",
"client_id": "f5b6a5cf-fbdf-4a9f-b3b8-3c2cd00225a4",
"client_secret": "0e760437-bf34-4aad-9f8d-870be799c55d",
"tenant_id": "72f988bf-86f1-41af-91ab-2d7cd011db47",
"subscription_id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx",
"managed_image_resource_group_name": "myResourceGroup",
"managed_image_name": "myPackerImage",
"os_type": "Linux",
"image_publisher": "Canonical",
"image_offer": "UbuntuServer",
"image_sku": "16.04-LTS",
"azure_tags": {
"env": "dev",
"task": "Image deployment with packer on Azure is fun!"
},
"location": "East US",
"vm_size": "Standard_DS2_v2"
}],
"provisioners": [{
"execute_command": "chmod +x {{ .Path }}; {{ .Vars }} sudo -E sh '{{ .Path }}'",
"inline": [
"apt-get update",
"apt-get upgrade -y",
"apt-get -y install nginx",
"/usr/sbin/waagent -force -deprovision+user && export HISTSIZE=0 && sync"
],
"inline_shebang": "/bin/sh -x",
"type": "shell"
}]
}

我的一个建议是:在Azure上构建映像时,在最后运行的/usr/sbin/waagent -force -deprovision+user命令非常重要,因为它会清理cloud-init/waagent用户打包器,ssh密钥&为自定义图像提供一个干净的开始。

最新更新