Skip to content

Commit

Permalink
v1.1.0: simplify logic, remove extra cases
Browse files Browse the repository at this point in the history
  • Loading branch information
zachelrath committed Aug 23, 2023
1 parent 9be9dfd commit b83ce45
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 442 deletions.
67 changes: 8 additions & 59 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,74 +1,23 @@
# ecs-scaledown
# github-action-ecs-scale

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.
scale an ECS service's desired count up/down to a desired value.

## 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.
1. Uses the AWS SDK for JavaScript to update the specified ECS Service's `desired count` attribute to a given value.

### General Usage

```yaml
ecs-scaledown:
name: Scale down ECS Service
needs: [ecs-scaleup, ALL_OTHER_JOBS]
name: Scale down ECS Service to zero
runs-on: ubuntu-latest
steps:
- name: ecs-scaledown
uses: trussworks/ecs-scaledown
uses: zachelrath/github-action-ecs-scale
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
service: your-service
cluster: your-cluster
desired-count: 0
```
### Using with Self-Hosted GitHub Runners
If you are using this action to deprovision self-hosted GitHub runners from the [cmsgov/github-actions-runner-aws](https://github.com/CMSgov/github-actions-runner-aws) repository, the service, and cluster can all be specified by the single hash generated by the module, and you can replace those variables with a single variable called `repository-hash`, like so:

```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"
repository-hash: aa50c18a-3141-506e-a0da-b96b2e12048e
```


**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.
6 changes: 2 additions & 4 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ description: 'Update the desired number of tasks for an ECS service'
inputs:
service:
description: 'The name of the ECS service.'
required: false
default: ''
required: true
cluster:
description: 'The name of the ECS cluster the service belongs to.'
required: false
default: ''
required: true
desired-count:
description: 'The desired number of tasks to run in the service.'
required: true
Expand Down
Loading

0 comments on commit b83ce45

Please sign in to comment.