-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial script to start removing zombie build instances. (#11088)
* Set up script to remove old instances. * Switch to push for testing. * Debugging. * Authenticate. * Try again. * Set region. * Add JQ. * Add iso check. * Add curr time. Add JQ query. * Correctly set env. * Format command. * Format command. * Should be inverted. * Only get running. * Filter for instance name. * Space instead of comma. * Debug. * Put back running instance filter. * Undo changes. * Test. * Move comment.
- Loading branch information
Showing
2 changed files
with
27 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: Terminate Zombie Build Instances | ||
|
||
on: | ||
push: | ||
schedule: | ||
- cron: "0 */1 * * *" | ||
|
||
jobs: | ||
terminate: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: List Instances Older Than an Hour | ||
env: | ||
AWS_ACCESS_KEY_ID: ${{ secrets.SELF_RUNNER_AWS_ACCESS_KEY_ID }} | ||
AWS_SECRET_ACCESS_KEY: ${{ secrets.SELF_RUNNER_AWS_SECRET_ACCESS_KEY }} | ||
# See https://github.com/aws/aws-cli/issues/5623 | ||
AWS_EC2_METADATA_DISABLED: true | ||
run: | | ||
set -euxo pipefail | ||
aws configure set default.region us-east-2 | ||
# Since the AWS cli returns an ISO HH:MM timestamp, and Jq only accepts Z timestamps, we define a function toZ to convert this. | ||
aws ec2 describe-instances --no-paginate --filters Name=instance-type,Values=c5.2xlarge Name=instance-state-name,Values=running \ | ||
--query 'Reservations[*].Instances[*].{Instance:InstanceId,LaunchTime:LaunchTime}' --output json \ | ||
| jq 'def toZ(str): str | (split("+")[0] + "Z") | fromdate ; | ||
flatten | map( { InstanceId: .Instance, LaunchTime: toZ(.LaunchTime) } ) | map( select ( .LaunchTime < (now - 3600) ) )' |