This is a demo of how to create a virtual machine image to publish it in the Azure Marketplace, or in your Image Gallery. It demonstrates how to automate the creation of your image as a GitHub Workflow using GitHub Actions, and uses the Azure Image Builder service to make the image creation easier.
Before running the Workflow we need to do some preparation:
- Create a service principal for our workflow
- Prepare the Azure Subscription for Image Builder, it requires a managed identity with specific permissions to create the VM images.
I have created these two scripts that you need to run inside an cli with the az tool installed. The easiest way of running it is through the cloud shell, just clone this repo and run the two scripts found in the scripts folder.
- The script 01-run-in-az-cli-github-credentials.sh will run the first requirement and provide you with a secret that you will use in GitHub
- The second one, 02-run-in-az-prepare-environment.sh, it will generate the resource group, identity and assign the needed roles to the identity, and will provide you with the name of the created identity.
It is recommended to create an environment in GitHub for storing these secrets.
//TODO: step by step and screenshots
The provided workflow will create a very simple machine that serves a web page from an Nginx containerized image. The installation script that will be run by the Image Builder service can be found in this same repo in the vmcode folder. And executes something like this:
curl -fsSL https://get.docker.com -o get-docker.sh
sh get-docker.sh
apt-get install -y docker-compose
docker-compose up -d
...