-
-
Notifications
You must be signed in to change notification settings - Fork 24
125 lines (109 loc) · 3.99 KB
/
packer--azure.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
name: Packer -- Azure
on:
workflow_dispatch:
inputs:
region:
description: 'the region to build the image in'
required: true
default: 'eastus'
type: choice
options:
- 'eastus'
- 'westus'
- 'centralus'
ubuntu-flavor:
description: 'the Ubuntu flavor to build the image in'
required: true
default: 'ubuntu-20.04'
type: choice
options:
- 'ubuntu-22.04'
- 'ubuntu-20.04'
- 'ubuntu-18.04'
child_image:
description: 'the child image to build'
required: true
default: 'none'
type: choice
options:
- 'none'
- 'nginx'
- 'nomad'
jobs:
build-images:
name: Build Images
runs-on: ubuntu-latest
env:
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
AZURE_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }}
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
outputs:
output-build-ubuntu-image:
${{ steps.build-ubuntu-image.outputs.ubuntu_artifact_name }}
steps:
- name: Checkout source code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
# Packer's official GitHub Actions are unstable & outdated, use a community action instead
- name: Use latest Packer
uses: hashicorp-contrib/setup-packer@792b061950558f07fd3f2de9a194ddc4441f8ddf # v3
- name: Check Version
run: |
echo "Packer version: $(packer version)"
- name: Check formating
run: |
terraform fmt -check -recursive -diff \
./packer/azure
- name: Build Ubuntu Image
id: build-ubuntu-image
run: |
IMAGE_OFFER='0001-com-ubuntu-server-focal'
IMAGE_SKU='22_04-LTS-gen2'
case "${{ inputs.ubuntu-flavor }}" in
ubuntu-22.04)
IMAGE_OFFER='0001-com-ubuntu-server-jammy'
IMAGE_SKU='22_04-LTS-gen2'
;;
ubuntu-20.04)
IMAGE_OFFER='0001-com-ubuntu-server-focal'
IMAGE_SKU='20_04-LTS-gen2'
;;
ubuntu-18.04)
IMAGE_OFFER='0001-com-ubuntu-server-bionic'
IMAGE_SKU='18_04-LTS-gen2'
;;
esac
packer init \
-var location=${{ inputs.region }} \
-var image_offer=${IMAGE_OFFER} \
-var image_sku=${IMAGE_SKU} \
./packer/azure/ubuntu.pkr.hcl
packer validate \
-var image_offer=${IMAGE_OFFER} \
-var image_sku=${IMAGE_SKU} \
-var location=${{ inputs.region }} \
./packer/azure/ubuntu.pkr.hcl
packer build \
-var location=${{ inputs.region }} \
-var image_offer=${IMAGE_OFFER} \
-var image_sku=${IMAGE_SKU} \
./packer/azure/ubuntu.pkr.hcl
UBUNTU_ARTIFACT_NAME=$(cat manifest.json | jq '.builds[].artifact_id' | sed -r 's|.*/(.*)"$|\1|')
echo Building the next image with: $UBUNTU_ARTIFACT_NAME
echo "::set-output name=ubuntu_artifact_name::$UBUNTU_ARTIFACT_NAME"
- name: Build Child Image
if: ${{ inputs.child_image != 'none' }}
id: build-child-image
run: |
packer init \
-var location=${{ inputs.region }} \
-var custom_managed_image_name=${{ steps.build-ubuntu-image.outputs.ubuntu_artifact_name }} \
./packer/azure/${{ inputs.child_image }}.pkr.hcl
packer validate \
-var location=${{ inputs.region }} \
-var custom_managed_image_name=${{ steps.build-ubuntu-image.outputs.ubuntu_artifact_name }} \
./packer/azure/${{ inputs.child_image }}.pkr.hcl
packer build \
-var location=${{ inputs.region }} \
-var custom_managed_image_name=${{ steps.build-ubuntu-image.outputs.ubuntu_artifact_name }} \
./packer/azure/${{ inputs.child_image }}.pkr.hcl