Skip to content

Commit 10a3f99

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. Signed-off-by: Richard Case <[email protected]>
1 parent e6095d6 commit 10a3f99

File tree

2 files changed

+60
-0
lines changed

2 files changed

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

.github/workflows/build-ami.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ jobs:
4747
uses: actions/checkout@v4
4848
with:
4949
repository: kubernetes-sigs/image-builder
50+
ref: v0.1.37
5051
fetch-depth: 0
5152
- name: Configure AWS credentials
5253
uses: aws-actions/configure-aws-credentials@v4

0 commit comments

Comments
 (0)