Skip to content

Commit 8916296

Browse files
authored
Adding deprecated quickstarts
Transferring outdated quickstarts from Dan's repo
1 parent 5731942 commit 8916296

File tree

39 files changed

+3889
-0
lines changed

39 files changed

+3889
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
{
2+
"type": "Microsoft.VirtualMachineImages/imageTemplates",
3+
"apiVersion": "2019-05-01-preview",
4+
"location": "<region>",
5+
"dependsOn": [],
6+
"tags": {
7+
"imagebuilderTemplate": "ubuntu1804",
8+
"userIdentity": "enabled"
9+
},
10+
"identity": {
11+
"type": "UserAssigned",
12+
"userAssignedIdentities": {
13+
"<imgBuilderId>": {}
14+
15+
}
16+
},
17+
"properties": {
18+
19+
"buildTimeoutInMinutes" : 80,
20+
21+
"vmProfile":
22+
{
23+
"vmSize": "Standard_D1_v2",
24+
"osDiskSizeGB": 30
25+
},
26+
27+
"source": {
28+
"type": "PlatformImage",
29+
"publisher": "Canonical",
30+
"offer": "UbuntuServer",
31+
"sku": "18.04-LTS",
32+
"version": "latest"
33+
34+
},
35+
"customize": [
36+
{
37+
"type": "Shell",
38+
"name": "RunScriptFromSource",
39+
"scriptUri": "https://raw.githubusercontent.com/danielsollondon/azvmimagebuilder/master/quickquickstarts/customizeScript.sh"
40+
},
41+
42+
{
43+
"type": "Shell",
44+
"name": "CheckSumCompareShellScript",
45+
"scriptUri": "https://raw.githubusercontent.com/danielsollondon/azvmimagebuilder/master/quickquickstarts/customizeScript2.sh",
46+
"sha256Checksum": "ade4c5214c3c675e92c66e2d067a870c5b81b9844b3de3cc72c49ff36425fc93"
47+
},
48+
49+
{
50+
"type": "File",
51+
"name": "downloadBuildArtifacts",
52+
"sourceUri": "https://raw.githubusercontent.com/danielsollondon/azvmimagebuilder/master/quickquickstarts/exampleArtifacts/buildArtifacts/index.html",
53+
"destination":"/tmp/index.html"
54+
},
55+
56+
{
57+
"type": "Shell",
58+
"name": "setupBuildPath",
59+
"inline": [
60+
"sudo mkdir /buildArtifacts",
61+
"sudo cp /tmp/index.html /buildArtifacts/index.html"
62+
]
63+
},
64+
65+
{
66+
"type": "Shell",
67+
"name": "InstallUpgrades",
68+
"inline": [
69+
"sudo apt install unattended-upgrades"
70+
]
71+
}
72+
73+
],
74+
"distribute":
75+
[
76+
{ "type":"ManagedImage",
77+
"imageId": "/subscriptions/<subscriptionID>/resourceGroups/<rgName>/providers/Microsoft.Compute/images/<imageName>",
78+
"location": "<region>",
79+
"runOutputName": "<runOutputName>",
80+
"artifactTags": {
81+
"source": "azVmImageBuilder",
82+
"baseosimg": "ubuntu1804"
83+
}
84+
}
85+
]
86+
}
87+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
# Create a Custom Managed Image from an Azure Platform Vanilla OS Image
2+
3+
> **MAY 2020 SERVICE ALERT** - Existing users, please ensure you are compliant this [Service Alert by 26th May!!!](https://github.com/danielsollondon/azvmimagebuilder#service-update-may-2020-action-needed-by-26th-may---please-review)
4+
5+
This article is to show you how you can create a basic customized image using the Azure VM Image Builder, and distribute to a region. This covers using mutliple customizations to illustrate some high level functionality:
6+
7+
This covers using mutliple customizations to illustrate some high level functionality:
8+
* Shell (ScriptUri) - Downloading a bash script and executing it
9+
* Shell (inline) - Execute an array of commands
10+
* File - Copy a html file from github to a specified, pre-created directory
11+
* buildTimeoutInMinutes - Increase a build time to allow for longer running builds
12+
* vmProfile - specifying a vmSize and Network properties
13+
* osDiskSizeGB - you can increase the size of image
14+
15+
To use this Quick Quickstarts, this can all be done using the Azure [Cloudshell from the Portal](https://azure.microsoft.com/en-us/features/cloud-shell/). Simply copy and paste the code from here, at a miniumum, just update the **subscriptionID** variable below.
16+
17+
## Step 1 : Enable Prereqs
18+
19+
Happy Image Building!!!
20+
21+
### Register for Image Builder / VM / Storage Features
22+
```bash
23+
az feature register --namespace Microsoft.VirtualMachineImages --name VirtualMachineTemplatePreview
24+
25+
az feature show --namespace Microsoft.VirtualMachineImages --name VirtualMachineTemplatePreview | grep state
26+
27+
az feature show --namespace Microsoft.KeyVault --name VirtualMachineTemplatePreview | grep state
28+
29+
# wait until it says registered
30+
31+
# check you are registered for the providers
32+
33+
az provider show -n Microsoft.VirtualMachineImages | grep registrationState
34+
az provider show -n Microsoft.Storage | grep registrationState
35+
az provider show -n Microsoft.Compute | grep registrationState
36+
az provider show -n Microsoft.KeyVault | grep registrationState
37+
```
38+
39+
If they do not show registered, run the commented out code below.
40+
41+
```bash
42+
## az provider register -n Microsoft.VirtualMachineImages
43+
## az provider register -n Microsoft.Storage
44+
## az provider register -n Microsoft.Compute
45+
## az provider register -n Microsoft.KeyVault
46+
47+
```
48+
49+
## Set Permissions & Create Resource Group for Image Builder Images
50+
51+
```bash
52+
# set your environment variables here!!!!
53+
54+
# destination image resource group
55+
imageResourceGroup=aibmdi001
56+
57+
# location (see possible locations in main docs)
58+
location=WestUS2
59+
60+
# your subscription
61+
# get the current subID : 'az account show | grep id'
62+
subscriptionID=$(az account show | grep id | tr -d '",' | cut -c7-)
63+
64+
# name of the image to be created
65+
imageName=aibCustomLinuxImg01
66+
67+
# image distribution metadata reference name
68+
runOutputName=aibCustLinManImg01ro
69+
70+
# create resource group
71+
az group create -n $imageResourceGroup -l $location
72+
```
73+
74+
## Create a user identify and assign permissions for the resource group where the image will be created
75+
76+
### Create User-Assigned Managed Identity and Grant Permissions
77+
For more information on User-Assigned Managed Identity, see [here](https://docs.microsoft.com/en-us/azure/active-directory/managed-identities-azure-resources/qs-configure-cli-windows-vm#user-assigned-managed-identity).
78+
79+
```bash
80+
# create user assigned identity for image builder to access the storage account where the script is located
81+
idenityName=aibBuiUserId$(date +'%s')
82+
az identity create -g $imageResourceGroup -n $idenityName
83+
84+
# get identity id
85+
imgBuilderCliId=$(az identity show -g $imageResourceGroup -n $idenityName | grep "clientId" | cut -c16- | tr -d '",')
86+
87+
# get the user identity URI, needed for the template
88+
imgBuilderId=/subscriptions/$subscriptionID/resourcegroups/$imageResourceGroup/providers/Microsoft.ManagedIdentity/userAssignedIdentities/$idenityName
89+
90+
# download preconfigured role definition example
91+
curl https://raw.githubusercontent.com/danielsollondon/azvmimagebuilder/master/solutions/12_Creating_AIB_Security_Roles/aibRoleImageCreation.json -o aibRoleImageCreation.json
92+
93+
imageRoleDefName="Azure Image Builder Image Def"$(date +'%s')
94+
95+
# update the definition
96+
sed -i -e "s/<subscriptionID>/$subscriptionID/g" aibRoleImageCreation.json
97+
sed -i -e "s/<rgName>/$imageResourceGroup/g" aibRoleImageCreation.json
98+
sed -i -e "s/Azure Image Builder Service Image Creation Role/$imageRoleDefName/g" aibRoleImageCreation.json
99+
100+
# create role definitions
101+
az role definition create --role-definition ./aibRoleImageCreation.json
102+
103+
# grant role definition to the user assigned identity
104+
az role assignment create \
105+
--assignee $imgBuilderCliId \
106+
--role $imageRoleDefName \
107+
--scope /subscriptions/$subscriptionID/resourceGroups/$imageResourceGroup
108+
```
109+
110+
## Step 2 : Modify HelloImage Example
111+
112+
```bash
113+
# download the example and configure it with your vars
114+
115+
curl https://raw.githubusercontent.com/danielsollondon/azvmimagebuilder/master/quickquickstarts/0_Creating_a_Custom_Linux_Managed_Image/helloImageTemplateLinux.json -o helloImageTemplateLinux.json
116+
117+
sed -i -e "s/<subscriptionID>/$subscriptionID/g" helloImageTemplateLinux.json
118+
sed -i -e "s/<rgName>/$imageResourceGroup/g" helloImageTemplateLinux.json
119+
sed -i -e "s/<region>/$location/g" helloImageTemplateLinux.json
120+
sed -i -e "s/<imageName>/$imageName/g" helloImageTemplateLinux.json
121+
sed -i -e "s/<runOutputName>/$runOutputName/g" helloImageTemplateLinux.json
122+
123+
sed -i -e "s%<imgBuilderId>%$imgBuilderId%g" helloImageTemplateLinux.json
124+
125+
```
126+
127+
## Step 3 : Create the Image
128+
129+
```bash
130+
# submit the image confiuration to the VM Image Builder Service
131+
132+
az resource create \
133+
--resource-group $imageResourceGroup \
134+
--properties @helloImageTemplateLinux.json \
135+
--is-full-object \
136+
--resource-type Microsoft.VirtualMachineImages/imageTemplates \
137+
-n helloImageTemplateLinux01
138+
139+
# wait approx 1-3mins, depending on external links
140+
141+
# start the image build
142+
143+
az resource invoke-action \
144+
--resource-group $imageResourceGroup \
145+
--resource-type Microsoft.VirtualMachineImages/imageTemplates \
146+
-n helloImageTemplateLinux01 \
147+
--action Run
148+
149+
# wait approx 15mins
150+
151+
```
152+
153+
154+
## Step 4 : Create the VM
155+
156+
```bash
157+
az vm create \
158+
--resource-group $imageResourceGroup \
159+
--name aibImgVm0001 \
160+
--admin-username aibuser \
161+
--image $imageName \
162+
--location $location \
163+
--generate-ssh-keys
164+
165+
# and login...
166+
167+
ssh aibuser@<pubIp>
168+
169+
You should see the image was customized with a Message of the Day as soon as your SSH connection is established!
170+
171+
*******************************************************
172+
** This VM was built from the: **
173+
...
174+
175+
```
176+
177+
## Clean Up
178+
```bash
179+
az resource delete \
180+
--resource-group $imageResourceGroup \
181+
--resource-type Microsoft.VirtualMachineImages/imageTemplates \
182+
-n helloImageTemplateLinux01
183+
184+
# delete permissions asssignments, roles and identity
185+
az role assignment delete \
186+
--assignee $imgBuilderCliId \
187+
--role "$imageRoleDefName" \
188+
--scope /subscriptions/$subscriptionID/resourceGroups/$imageResourceGroup
189+
190+
az role definition delete --name "$imageRoleDefName"
191+
192+
az identity delete --ids $imgBuilderId
193+
194+
195+
az group delete -n $imageResourceGroup
196+
197+
```
198+
199+
## Next Steps
200+
If you loved or hated Image Builder, please go to next steps to leave feedback, contact dev team, more documentation, or try more examples [here](../quickquickstarts/nextSteps.md)]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
{
2+
"type": "Microsoft.VirtualMachineImages/imageTemplates",
3+
"apiVersion": "2019-05-01-preview",
4+
"location": "<region>",
5+
"dependsOn": [],
6+
"tags": {
7+
"imagebuilderTemplate": "windows2019",
8+
"userIdentity": "enabled"
9+
},
10+
"identity": {
11+
"type": "UserAssigned",
12+
"userAssignedIdentities": {
13+
"<imgBuilderId>": {}
14+
15+
}
16+
},
17+
"properties": {
18+
19+
"buildTimeoutInMinutes" : 100,
20+
21+
"vmProfile":
22+
{
23+
"vmSize": "Standard_D2_v2",
24+
"osDiskSizeGB": 127
25+
},
26+
27+
"source": {
28+
"type": "PlatformImage",
29+
"publisher": "MicrosoftWindowsServer",
30+
"offer": "WindowsServer",
31+
"sku": "2019-Datacenter",
32+
"version": "latest"
33+
34+
},
35+
"customize": [
36+
{
37+
"type": "PowerShell",
38+
"name": "CreateBuildPath",
39+
"runElevated": false,
40+
"scriptUri": "https://raw.githubusercontent.com/danielsollondon/azvmimagebuilder/master/testPsScript.ps1"
41+
},
42+
{
43+
"type": "WindowsRestart",
44+
"restartCheckCommand": "echo Azure-Image-Builder-Restarted-the-VM > c:\\buildArtifacts\\azureImageBuilderRestart.txt",
45+
"restartTimeout": "5m"
46+
},
47+
{
48+
"type": "File",
49+
"name": "downloadBuildArtifacts",
50+
"sourceUri": "https://raw.githubusercontent.com/danielsollondon/azvmimagebuilder/master/quickquickstarts/exampleArtifacts/buildArtifacts/index.html",
51+
"destination":"c:\\buildArtifacts\\index.html"
52+
},
53+
54+
{
55+
"type": "PowerShell",
56+
"name": "settingUpMgmtAgtPath",
57+
"runElevated": false,
58+
"inline": [
59+
"mkdir c:\\buildActions",
60+
"echo Azure-Image-Builder-Was-Here > c:\\buildActions\\buildActionsOutput.txt"
61+
]
62+
},
63+
{
64+
"type": "WindowsUpdate",
65+
"searchCriteria": "IsInstalled=0",
66+
"filters": [
67+
"exclude:$_.Title -like '*Preview*'",
68+
"include:$true"
69+
],
70+
"updateLimit": 20
71+
}
72+
],
73+
"distribute":
74+
[
75+
{ "type":"ManagedImage",
76+
"imageId": "/subscriptions/<subscriptionID>/resourceGroups/<rgName>/providers/Microsoft.Compute/images/<imageName>",
77+
"location": "<region>",
78+
"runOutputName": "<runOutputName>",
79+
"artifactTags": {
80+
"source": "azVmImageBuilder",
81+
"baseosimg": "windows2019"
82+
}
83+
}
84+
]
85+
}
86+
}
87+

0 commit comments

Comments
 (0)