I would like to prepare an ubuntu image with preinstalled dependencies (python, go, etc.) so that the pipelines do not waste times installing them each time. I expected to find some kind of Dockerfile-like interface, but I have not been able to find an easy way to accomplish this.
What I understood is that I need to create a new virtual machine scale set with this image and then use it for the agent pool. But how do I create the vhd image?
You can use one of the below tools to build images on Azure.
Both of the above tools can be used to customize base (golden) images available on the Azure marketplace or if you have an existing VM image on-prem, it can be uploaded following documentation here.
If you have multiple subscriptions & you would like to build on one subscription & use them on other subscriptions/other tenants, you would need to use Azure Compute Gallery. This gallery also helps you to version VM images like docker images. In short, it's like a docker registry for VM images.
If you would like to use existing marketplace images (base Ubuntu in your case), you don't need to convert them into VHD. Packer/Azure Image Builder would basically provision a VM out of the base image, install packages (customization of your choice), creates a snapshot of the VM & creates an image out of that.
With
packer, you would be writing a JSON builder like the below. Source code is taken from here.A suggestion from my side::
/usr/sbin/waagent -force -deprovision+usercommand ran at the end is extremely important when building images on the Azure as it cleans up thecloud-init/waagentuser packer provisioned, ssh keys & other things to have a clean start for a customized image.