JavaScript Github Action to clean up AWS running instances (in a specified AWS region) without a Github Runner linked to them.
To identify the instances are used two tags:
- Key:
Name
, Value:<REPO_NAME> Github Runner
(insert the name of your repo). - Key:
Runner
, Value:<Name of the runner linked to the instance>
(it's the value used to understand if its linked runner is online, it must be unique!).
It works perfectly with the runners deployed using ephemeral-github-runner (see also the related github action).
- You have a repository where you use self-hosted runners.
- You have an AWS account.
- You have added secrets to your repository that are later used to set environment variables. More information on secrets: How to set up secrets.
Everything below is required.
repo-name
: The name of the repository for which you want to clean up offline runners.repo-owner
: The owner of the repository for which you want to clean up offline runners.aws-region
: AWS region where the instances are located, eg. eu-west-2.
APP_ID
: GitHub App ID.APP_PRIVATE_KEY
: GitHub App Private Key.AWS_ACCESS_KEY_ID
: Your access key id received when account was created.AWS_SECRET_ACCESS_KEY
: Your secret access key received when account was created.
name: clean-up-instances
on: <event on which the action has to start>
jobs:
manage-runners:
runs-on: ubuntu-latest
steps:
- uses: LorenzoDrudi/clean-up-cloud-rogue-instances@<version to use>
env:
APP_ID: ${{ secrets.APP_ID }}
APP_PRIVATE_KEY: ${{ secrets.APP_PRIVATE_KEY }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
with:
repo-name: <name of the repository for which you want to clean up offline runners>
repo-owner: <owner of the repository for which you want to clean up offline runners>
aws-region: <AWS region where the instances are located>
All the personal inputs are passed by github secret. See the docs.
A github action workflow automatically creates a Tag and a Release every push on the main branch.
That's only a good DevOps practice, furthermore the main branch is protected and changes can come only over PR.
The idea is to work on develop/features branches and when it's done merge to the main branch, so the workflow starts.
The default behaviour is to create a minor
tag/release (e.g. 1.*.0), the schema is <major_version>.<minor_version>.<patch_version>
.
It's possible also to create major or patch tags/releases adding a tag at the end of the commit message:
#major
-> e.g. *.0.0#patch
-> e.g. 1.1.*
For more info see the references.
- Generated from: JavaScript-Action
- To learn how to create a simple action, start here: Hello-World-JavaScript-Action
- Recommended documentation: Creating a JavaScript Action
- Github action used to create a new tag: github-tag-action
- Github Action used for the release: action-gh-release