/ecs-scaleup

This repository provides a github action which can provision a self-hosted github runner via AWS ECS/Fargate

Primary LanguageJavaScriptApache License 2.0Apache-2.0

ecs-scaleup

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

This action wraps several AWS interactions into one, including existing AWS actions, which are used with small modifications. 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
  2. Use the AWS SDK for JavaScript to grab the desired task definition from AWS
  3. Uses the AWS SDK for JavaScript to increment the specified ECS Service's desired count attribute to the desired number
  4. Deploy the task definition from step 2. Started from existing action: aws-actions/amazon-ecs-deploy-task-definition. Removed usage of CodeDeploy and refactored to use task definition from step 2 instead of a file path.

Modifications made to existing AWS actions

Any instances of core.setOutput have been modified to return the item instead so that it can be passed to the next function.

All instances of

if (require.main === module) {
    run();
}

have been removed from files other than index.js.

aws-actions/configure-aws-credentials

Path: src/main/configAwsCreds.js

No other changes

aws-actions/amazon-ecs-deploy-task-definition

Path: src/main/deployTaskDefinition.js

The run() function is edited to accept the new task definition from the previous step as an argument. Removed uage of the filesystem and removed CodeDeploy provisioning to clean up code we won't need.

Cleanup functions

Path: src/cleanup/configAwsCreds.js

No changes. Removed the amazonEcrLogin cleanup function because there is no docker login, so nothing to clean up.

Use Case and Usage

General Use

ecs-scaleup:
  name: Scale up ECS service
  runs-on: ubuntu-latest
  steps:
    - name: ecs-scaleup
      uses: trussworks/ecs-scaleup@f9f61a55ff0565859d3fbfeabdfd603c9acf3387
      with:
        aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
        aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
        aws-region: us-east-1
        container-name: gh-runner-aa50c18a-3141-506e-a0da-b96b2e12048e
        task-definition: gh-runner-aa50c18a-3141-506e-a0da-b96b2e12048e
        service: gh-runner-aa50c18a-3141-506e-a0da-b96b2e12048e
        cluster: gh-runner-aa50c18a-3141-506e-a0da-b96b2e12048e
        desired-count: 3

Using with Self-Hosted GitHub Runners

If you are using this action to provision self-hosted GitHub runners from the cmsgov/github-actions-runner-aws repository, the container-name, task-definition, 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:

ecs-scaleup:
  name: Scale up ECS service
  runs-on: ubuntu-latest
  steps:
    - name: ecs-scaleup
      uses: trussworks/ecs-scaleup@f9f61a55ff0565859d3fbfeabdfd603c9acf3387
      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
        desired-count: 3

NOTE: If using this action to stand up self-hosted runners, any subsequent jobs should have:

needs: ecs-scaleup

in its YAML configuration.

See Also

This action should be paired with the trussworks/ecs-scaledown action.