Skip to content

Commit 4bc9377

Browse files
committed
feat: build amis with vars file
A new GitHub Actions workflow that can be used to build a AMI using a packer vars file passed in as a string. This also pins this workflow and the existing GHA workflow for AMI building to use a specific tag of image builder. The version can be changed via input args. Signed-off-by: Richard Case <richard.case@outlook.com>
1 parent e6095d6 commit 4bc9377

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: build-and-publish-ami-with-vars
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
image_builder_version:
7+
description: "Image builder version"
8+
required: true
9+
default: 'v0.1.38'
10+
target:
11+
description: "target os"
12+
required: true
13+
type: choice
14+
options:
15+
- ubuntu-2204
16+
- ubuntu-2404
17+
- flatcar
18+
packer_vars:
19+
description: "Packer vars (json)"
20+
type: string
21+
22+
permissions:
23+
id-token: write
24+
contents: read
25+
26+
jobs:
27+
buildandpublish:
28+
name: Build and publish CAPA AMIs
29+
runs-on: ubuntu-latest
30+
steps:
31+
- name: checkout code
32+
uses: actions/checkout@v4
33+
with:
34+
repository: kubernetes-sigs/image-builder
35+
ref: ${{ inputs.image_builder_version }}
36+
fetch-depth: 0
37+
- name: Create packer vars file
38+
if: inputs.packer_vars != ''
39+
env:
40+
PACKER_VARS: ${{ inputs.packer_vars }}
41+
run: |
42+
echo "$PACKER_VARS" | jq -r > ./images/capi/vars.json
43+
cat ./images/capi/vars.json
44+
- name: Configure AWS credentials
45+
uses: aws-actions/configure-aws-credentials@v4
46+
with:
47+
aws-region: us-east-2
48+
role-to-assume: arn:aws:iam::819546954734:role/gh-image-builder
49+
- name: Install deps
50+
run: make deps-ami
51+
working-directory: ./images/capi
52+
- name: Install Amazon EBS Plugin
53+
working-directory: ./images/capi
54+
run: ./.local/bin/packer plugins install github.com/hashicorp/amazon
55+
- name: Build AMI with vars
56+
if: inputs.packer_vars != ''
57+
working-directory: ./images/capi
58+
run: PACKER_VAR_FILES=vars.json make build-ami-${{ inputs.target }}
59+
- name: Build AMI without vars
60+
if: inputs.packer_vars == ''
61+
working-directory: ./images/capi
62+
run: make build-ami-${{ inputs.target }}
63+

.github/workflows/build-ami.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ name: build-and-publish-ami
33
on:
44
workflow_dispatch:
55
inputs:
6+
image_builder_version:
7+
description: "Image builder version"
8+
required: true
9+
default: 'v0.1.38'
610
regions:
711
description: 'Publication regions'
812
required: true
@@ -47,6 +51,7 @@ jobs:
4751
uses: actions/checkout@v4
4852
with:
4953
repository: kubernetes-sigs/image-builder
54+
ref: ${{ inputs.image_builder_version }}
5055
fetch-depth: 0
5156
- name: Configure AWS credentials
5257
uses: aws-actions/configure-aws-credentials@v4

0 commit comments

Comments
 (0)