Skip to content
This repository has been archived by the owner on Jan 3, 2023. It is now read-only.

Commit

Permalink
Merge pull request #1 from trussworks/cht-implement-functionality
Browse files Browse the repository at this point in the history
Merge full functionality
  • Loading branch information
chtakahashi authored Aug 18, 2021
2 parents 2ba027f + 106b4b6 commit ae55e00
Show file tree
Hide file tree
Showing 14 changed files with 48,843 additions and 1 deletion.
18 changes: 18 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"env": {
"commonjs": true,
"es6": true,
"node": true,
"jest": true
},
"extends": "eslint:recommended",
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parserOptions": {
"ecmaVersion": 2018
},
"rules": {
}
}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules/

12 changes: 12 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
repos:
- repo: git://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
hooks:
- id: check-merge-conflict
- id: detect-private-key
- id: trailing-whitespace

- repo: git://github.com/igorshubovych/markdownlint-cli
rev: v0.28.1
hooks:
- id: markdownlint
53 changes: 52 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,52 @@
# ecs-scaledown
# ecs-scaledown

The purpose of this repository is to provide a GitHub Action to
scale down an ECS service's desired count to zero.

This action leverages the
aws-actions/configure-aws-credentials action.
Since GitHub Actions currently does not allow
composite actions to call other actions,
we chose to integrate the JavaScript code from existing aws-actions into this repository.

## What it does

1. Configure AWS credentials. Uses existing action:
[aws-actions/configure-aws-credentials](https://github.com/aws-actions/configure-aws-credentials)
2. Uses the AWS SDK for JavaScript to decrement the
specified ECS Service's `desired count` attribute to 0.

## Modifications made to existing AWS actions

No modifications made. the `index.js` and `cleanup.js` files from
the configure-aws-credentials action were copied into
`src/main/configAwsCreds.js` and `src/cleanup/configAwsCreds.js`.

## Use Case and Usage

This action was developed as a way to scale down
an ECS Service after the tasks no longer need to be run.
Specifically, this is designed to work following a workflow using
Self-Hosted GitHub Runners that are stood up by
the [trussworks/ecs-scaleup](https://github.com/trussworks/ecs-scaleup) action.

```yaml
ecs-scaledown:
name: Scale down ECS Service
needs: [ecs-scaleup, ALL_OTHER_JOBS]
runs-on: ubuntu-latest
steps:
- name: ecs-scaledown
uses: trussworks/ecs-scaledown
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: "us-east-1"
service: github-actions-runner
cluster: github-runner
```
**NOTE**: When using this to deprovision Self-Hosted GitHub runners,
you must populate the `needs` argument in the YAML above with
all jobs that are using self-hosted runners.
To do this, replace ALL_OTHER_JOBS with a list of jobs denoted by name.
29 changes: 29 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: 'Deprovision GitHub Runners'
description: 'Scale down ECS service count'
inputs:
aws-access-key-id:
description: >-
AWS Access Key ID. This input is required if running in the GitHub hosted environment.
It is optional if running in a self-hosted environment that already has AWS credentials,
for example on an EC2 instance.
required: false
aws-secret-access-key:
description: >-
AWS Secret Access Key. This input is required if running in the GitHub hosted environment.
It is optional if running in a self-hosted environment that already has AWS credentials,
for example on an EC2 instance.
required: false
aws-region:
description: 'Your AWS region'
required: true
default: 'us-east-1'
service:
description: 'The name of the ECS service.'
required: true
cluster:
description: 'The name of the ECS cluster the service belongs to.'
required: true
runs:
using: 'node12'
main: 'dist/index.js'
post: 'dist/cleanup/index.js'
Loading

0 comments on commit ae55e00

Please sign in to comment.