Skip to content

Commit 68bed66

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

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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+
fetch-depth: 0
32+
- name: Create packer vars file
33+
if: inputs.packer_vars != ''
34+
env:
35+
PACKER_VARS: ${{ inputs.packer_vars }}
36+
run: |
37+
echo "$PACKER_VARS" | jq -r > ./images/capi/vars.json
38+
cat ./images/capi/vars.json
39+
- name: Configure AWS credentials
40+
uses: aws-actions/configure-aws-credentials@v4
41+
with:
42+
aws-region: us-east-2
43+
role-to-assume: arn:aws:iam::819546954734:role/gh-image-builder
44+
- name: Install deps
45+
run: make deps-ami
46+
working-directory: ./images/capi
47+
- name: Install Amazon EBS Plugin
48+
working-directory: ./images/capi
49+
run: ./.local/bin/packer plugins install github.com/hashicorp/amazon
50+
- name: Build AMI with vars
51+
if: inputs.packer_vars != ''
52+
working-directory: ./images/capi
53+
run: PACKER_VAR_FILES=vars.json make build-ami-${{ inputs.target }}
54+
- name: Build AMI without vars
55+
if: inputs.packer_vars == ''
56+
working-directory: ./images/capi
57+
run: make build-ami-${{ inputs.target }}
58+

0 commit comments

Comments
 (0)