From 10a3f996fa1b55a124ec0f839031994930d26cf9 Mon Sep 17 00:00:00 2001 From: Richard Case Date: Mon, 14 Oct 2024 10:13:13 +0100 Subject: [PATCH] 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 --- .github/workflows/build-ami-varsfile.yml | 59 ++++++++++++++++++++++++ .github/workflows/build-ami.yml | 1 + 2 files changed, 60 insertions(+) create mode 100644 .github/workflows/build-ami-varsfile.yml diff --git a/.github/workflows/build-ami-varsfile.yml b/.github/workflows/build-ami-varsfile.yml new file mode 100644 index 0000000000..6ed5c1423f --- /dev/null +++ b/.github/workflows/build-ami-varsfile.yml @@ -0,0 +1,59 @@ +name: build-and-publish-ami-with-vars + +on: + workflow_dispatch: + inputs: + target: + description: "target os" + required: true + type: choice + options: + - ubuntu-2204 + - ubuntu-2404 + - flatcar + packer_vars: + description: "Packer vars (json)" + type: string + +permissions: + id-token: write + contents: read + +jobs: + buildandpublish: + name: Build and publish CAPA AMIs + runs-on: ubuntu-latest + steps: + - name: checkout code + uses: actions/checkout@v4 + with: + repository: kubernetes-sigs/image-builder + ref: v0.1.37 + fetch-depth: 0 + - name: Create packer vars file + if: inputs.packer_vars != '' + env: + PACKER_VARS: ${{ inputs.packer_vars }} + run: | + echo "$PACKER_VARS" | jq -r > ./images/capi/vars.json + cat ./images/capi/vars.json + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v4 + with: + aws-region: us-east-2 + role-to-assume: arn:aws:iam::819546954734:role/gh-image-builder + - name: Install deps + run: make deps-ami + working-directory: ./images/capi + - name: Install Amazon EBS Plugin + working-directory: ./images/capi + run: ./.local/bin/packer plugins install github.com/hashicorp/amazon + - name: Build AMI with vars + if: inputs.packer_vars != '' + working-directory: ./images/capi + run: PACKER_VAR_FILES=vars.json make build-ami-${{ inputs.target }} + - name: Build AMI without vars + if: inputs.packer_vars == '' + working-directory: ./images/capi + run: make build-ami-${{ inputs.target }} + diff --git a/.github/workflows/build-ami.yml b/.github/workflows/build-ami.yml index 8eeff72ac6..a4a4a2876d 100644 --- a/.github/workflows/build-ami.yml +++ b/.github/workflows/build-ami.yml @@ -47,6 +47,7 @@ jobs: uses: actions/checkout@v4 with: repository: kubernetes-sigs/image-builder + ref: v0.1.37 fetch-depth: 0 - name: Configure AWS credentials uses: aws-actions/configure-aws-credentials@v4