Skip to content

Commit

Permalink
Add tagging, update README
Browse files Browse the repository at this point in the history
  • Loading branch information
shub-kris committed Jan 29, 2024
1 parent 6e1791b commit 4e0de2a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
20 changes: 16 additions & 4 deletions .github/workflows/build-ami.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ on:
paths:
- 'aws-ami-creation/**'
workflow_dispatch:
inputs:
tag:
description: 'Tag to use for the AMI'
schedule:
# Schedule the workflow to run every second day at midnight UTC
- cron: '0 0 */2 * *'
Expand All @@ -15,13 +18,20 @@ jobs:
build-ami:
defaults:
run:
working-directory: aws-ami-creation
working-directory: infrastructure/ami
runs-on: ubuntu-latest
steps:

- uses: actions/checkout@v3
- uses: hashicorp/setup-packer@main


- name: Determine tag
id: determine-tag
run: echo "::set-output name=TAG::${{ github.event.inputs.tag || github.ref }}"

- name: Use specific tag
run: echo "Building tag ${{ steps.determine-tag.outputs.TAG }}"

- name: configure aws credentials
uses: aws-actions/configure-aws-credentials@v1
with:
Expand All @@ -41,10 +51,12 @@ jobs:

- name: Packer Validate
id: validate
run: packer validate hcl2
run: packer validate hcl2-files
continue-on-error: true

- name: Packer Build
id: build
run: packer build hcl2
run: |
SOURCE_AMI=ami-077399be2d0ae7e0c
packer build -var "source_ami=$SOURCE_AMI" -var "tag_name=${{ steps.determine-tag.outputs.TAG }}" hcl2-files
7 changes: 6 additions & 1 deletion infrastructure/ami/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,9 @@ packer build ./hcl2-files
You can also override variables using `-var` flag. For example, to override `region` variable:
```bash
packer build -var 'region=us-west-2' ./hcl2-files
```
```

To trigger a github action workflow manually, you can use GitHub CLI:
```bash
gh workflow run build-ami.yml -f tag=<tag>
```
6 changes: 6 additions & 0 deletions infrastructure/ami/hcl2-files/variables.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,10 @@ variable "ssh_username" {
default = "ubuntu"
description = "Username to connect to SSH with"
type = string
}

variable "tag_name" {
default = "develop"
description = "Name tag for AMI"
type = string
}

0 comments on commit 4e0de2a

Please sign in to comment.