From ac2b2ca72bc931d9a8192941b9dafeeaf507e848 Mon Sep 17 00:00:00 2001 From: Joey Freeland Date: Tue, 26 May 2026 11:42:05 -0400 Subject: [PATCH 1/2] chore(ci): clean up stale ec2 instances --- .github/workflows/cleanup-stale-ec2.yml | 52 +++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 .github/workflows/cleanup-stale-ec2.yml diff --git a/.github/workflows/cleanup-stale-ec2.yml b/.github/workflows/cleanup-stale-ec2.yml new file mode 100644 index 000000000..260f59a55 --- /dev/null +++ b/.github/workflows/cleanup-stale-ec2.yml @@ -0,0 +1,52 @@ +name: Cleanup Stale EC2 Instances + +on: + schedule: + # Run daily at 06:00 UTC + - cron: "0 6 * * *" + workflow_dispatch: + +jobs: + cleanup: + name: Delete stale supadevci EC2 instances + runs-on: ubuntu-latest + strategy: + matrix: + region: [ap-southeast-1, us-east-1] + + permissions: + id-token: write + contents: read + + steps: + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v4 + with: + role-to-assume: ${{ secrets.SUPADEV_AWS_ROLE }} + aws-region: ${{ matrix.region }} + + - name: Find and terminate stale instances + env: + AWS_MAX_ATTEMPTS: 6 + run: | + cutoff=$(date -u -d '24 hours ago' '+%Y-%m-%dT%H:%M:%SZ') + + echo "Looking for running packer builder instances launched before ${cutoff}..." + + instance_ids=$(aws ec2 describe-instances \ + --filters \ + "Name=tag:appType,Values=postgres" \ + "Name=tag:creator,Values=packer" \ + "Name=instance-state-name,Values=running" \ + --query "Reservations[].Instances[?LaunchTime<'${cutoff}'][].InstanceId" \ + --output text) + + if [ -z "$instance_ids" ]; then + echo "No stale instances found." + exit 0 + fi + + read -r -a instance_id_arr <<< "$instance_ids" + echo "Terminating instances: ${instance_id_arr[*]}" + aws ec2 terminate-instances --instance-ids "${instance_id_arr[@]}" + echo "Done." From 8600799fec4b9f6cd43fa4bf02c6dc9c52151acb Mon Sep 17 00:00:00 2001 From: Joey Freeland Date: Tue, 26 May 2026 11:45:20 -0400 Subject: [PATCH 2/2] fix: packer --- .github/workflows/cleanup-stale-ec2.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cleanup-stale-ec2.yml b/.github/workflows/cleanup-stale-ec2.yml index 260f59a55..dfc39e419 100644 --- a/.github/workflows/cleanup-stale-ec2.yml +++ b/.github/workflows/cleanup-stale-ec2.yml @@ -8,7 +8,7 @@ on: jobs: cleanup: - name: Delete stale supadevci EC2 instances + name: Delete stale packer EC2 instances runs-on: ubuntu-latest strategy: matrix: