-
Notifications
You must be signed in to change notification settings - Fork 0
70 lines (61 loc) · 2.28 KB
/
packer-build-if-vm.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
name: Build Image Factory VM
on:
push:
paths:
- ".github/workflows/packer-build-if-vm.yml"
- "images/packer/image-factory-vm"
workflow_dispatch:
jobs:
packer-build:
runs-on: ubuntu-latest
env:
AZURE_LOCATION: ${{ vars.AZURE_LOCATION }}
AZURE_RESOURCE_GROUP: ${{ vars.AZURE_RESOURCE_GROUP }}
AZURE_ACG: ${{ vars.AZURE_ACG }}
AZURE_CREDENTIALS: |
{
"clientId": "${{ secrets.AZURE_CLIENT_ID }}",
"clientSecret": "${{ secrets.AZURE_CLIENT_SECRET }}",
"subscriptionId": "${{ secrets.AZURE_SUBSCRIPTION_ID }}",
"tenantId": "${{ secrets.AZURE_TENANT_ID }}"
}
IMAGE_NAME: "image-factory-vm"
IMAGE_PUBLISHER: "Canonical"
IMAGE_OFFER: "0001-com-ubuntu-server-jammy"
IMAGE_SKU: "22_04-lts-gen2"
IMAGE_OS_TYPE: "linux"
steps:
- name: Checkout Repository
uses: actions/checkout@v4
# - name: Template packer vars file
# uses: cuchi/[email protected]
# with:
# template: images/packer/image-factory-vm/values.auto.pkrvars.hcl.j2
# output_file: images/packer/image-factory-vm/values.auto.pkrvars.hcl
- name: Azure Login
uses: azure/login@v2
with:
creds: ${{ env.AZURE_CREDENTIALS }}
- name: Create Image Definition
uses: azure/cli@v2
with:
azcliversion: 2.64.0
inlineScript: |
image_definition_exists=$(az sig image-definition show \
--resource-group "$AZURE_RESOURCE_GROUP" \
--gallery-name "$AZURE_ACG" \
--gallery-image-definition "$IMAGE_NAME" \
--query "name" -o tsv 2>/dev/null)
if [ -z "$image_definition_exists" ]; then
echo "Image definition does not exist. Creating it..."
az sig image-definition create \
--resource-group "$AZURE_RESOURCE_GROUP" \
--gallery-name "$AZURE_ACG" \
--gallery-image-definition "$IMAGE_NAME" \
--publisher "$IMAGE_PUBLISHER" \
--offer "$IMAGE_OFFER" \
--sku "$IMAGE_SKU" \
--os-type "$IMAGE_OS_TYPE"
else
echo "Image definition '$IMAGE_NAME' already exists."
fi