page_type | languages | products | name | ||||
---|---|---|---|---|---|---|---|
sample |
|
|
Create a Wordpress image for an Azure Virtual Machine image using Azure Image Builder |
Create a Wordpress image for an Azure Virtual Machine image using Azure Image Builder
Azure Image Builder is an Azure service that allows you to create predefined images with the required settings and software that meets your corporate standards, all of this being done in an automated approach that guarantees consistency and allows you to version version your images while managing them as code.
When building images with Azure Image Builder you will start with a Linux or Windows base image on top of which you will add your customizations as-code. The solution is based on HashiCorp Packer but being a managed service in Azure.
This service allows you to provide some contents and scripts to automate the Virtual Machine configuration and will perform all the necessary steps to generate, generalize and publish your virtual machine image.
Once you have an image ready you can publish it in the Azure Shared Image Gallery or use it as a managed image in VHD that you can later use as part of your automation.
Features
The sample provides:
- A script to take care of all of the prerequisites to use Azure image builder:
- Azure provider registrations
- Resource Group creation
- User-assigned identity and permissions.
- Image definition and gallery settings
- A template used to configure the image, this file will:
- Define the base image to use and VM profile, in this case it will use Ubuntu 18.04 on a Standard_D1_v2 VM.
- Include the customization script and the commands to run it. In this sample the script will install Wordpress
- Image Gallery configuration
Getting Started
Prerequisites
Download the image builder script and edit the environment variable section to match your deployment, provide inputs for the variables as follows:
Variable | Description | Example |
---|---|---|
rg_name | Resource group name | image_builder_rg |
location | Main Azure Datacenter location | westeurope |
replicated_location | Additional region to replicate the image to | northeurope |
image_gallery | Azure Compute Image Gallery nameame of the image definition to be created | ib_gallery |
image_def_name | Name of the image definition | ib_imagedef |
image_metadata | Name for the image distribution metadata reference | ib_premium |
subscription_id | Subscription ID of the RG you will use | xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx |
publisher | Name of the company or person that will publish the image | ib_publishing |
sku | Define a SKU for your image | premium |
offer | Image offer | ib_offer |
Installation
Follow these steps to deploy the sample:
- Sign in with Azure CLI
az login
- Run the image builder script
. ./image-builder.sh
Testing
After the script has finished its run, test the image by creating a VM.
az network nsg create -g $rg_name -n wordpressnsg
az network nsg rule create \
--resource-group $rg_name \
--nsg-name wordpressnsg \
--name allow-http \
--protocol tcp \
--priority 100 \
--destination-port-range 80 \
--access Allow
az vm create \
--resource-group $rg_name \
--name wordpressvm \
--admin-username aibuser \
--location $location \
--image "/subscriptions/$subscription_id/resourceGroups/$rg_name/providers/Microsoft.Compute/galleries/$image_gallery/images/$image_def_name/versions/latest" \
--generate-ssh-keys \
--nsg wordpressnsg
Get the public IP address of the VM by running:
az vm list-ip-addresses -n wordpressvm --query [0].virtualMachine.network.publicIpAddresses[0].ipAddress -o tsv
Access the IP address via a web browser and Wordpress should be deployed.