|
| 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 | + |
0 commit comments