name: Create AWS Golden AMI
on:
  schedule:
    - cron: "0 0 * * *"
  pull_request:
  push:
    paths:
      - '.github/workflows/packer/build.sh'
      - '.github/workflows/packer/bootstrap.sh'
      - '.github/workflows/packer/ubuntu-os-ami.json'
      - '.github/workflows/packer/ubuntu-os-ami.json.pkr.hcl'
      - '.github/workflows/packer/golden-image-pipeline.yaml'
  workflow_dispatch:
    branches:
      - main

jobs:
  create-golden-ami:
    runs-on: self-hosted
    steps:
    - uses: actions/checkout@v2
    - name: Install Packer
      run: sudo apt-get install -y zip unzip jq
      env:
        AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
        AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
    - name: Download Packer
      run: wget https://releases.hashicorp.com/packer/1.6.2/packer_1.6.2_linux_amd64.zip
      shell: bash
    - name: Create Golden image
      run: packer/build.sh
      shell: bash
