Code Monkey home page Code Monkey logo

ecs-github-actions-runner's Introduction

ECS cluster for Github Actions runner

This is a CDK project to construct ECS cluster of Github self-hosted runner.

Stacks

This CDK project includes the following stacks.

  • <clusterName>-vpc-stack
    • Create VPC and Subnets for ECS cluster
  • <clusterName>-stack
    • Create ECS cluster and Autoscaling
  • <clusterName>-funcs-stack
    • Create Lambda functions to start and to stop Github Actions Runner tasks.

Preparing

Create a secret of AWS Secret Manager, which has the secret key named GITHUB_TOKEN which is setted value Github Personal Access Token.

If you want to connet EC2 node of ECS cluster by SSH, create key pair.

Configuration

Create your configuration file in config/ directory. your configuration file overwrite config/default.ts.

Minimum configuration is the following.

import { ConfigDefinition } from '../lib/Config';

const config: Partial<ConfigDefinition> = {
  repo: {
    owner: 'owner',
    name: 'your-repo-name',
  },
  secretName: 'your-secret-name',
};

export default config;

See config/minimum-sample.ts.

Full configuration sample is config/maximum-sample.ts

Deploy

When you want to deploy this CDK project, run the following commands. Set environment variable NODE_CONFIG_ENV to select your configuration file.

export NODE_CONFIG_ENV=<your-config-file-name(without extention)>
yarn cdk deploy --all

if you want to delete AWS resources of this CDK project, Run the following command.

export NODE_CONFIG_ENV=<your-config-file-name(without extention)>
yarn cdk destroy --all

Start and stop Github actions runner tasks

This cdk application include lambda functions to operate Github actions runner tasks. To start task, run the following command.

# for start EC2 runners
aws lambda invoke --function-name <clusterName>-start-runners-ec2 /dev/null

# for start Fargate runners
aws lambda invoke --function-name <clusterName>-start-runners-fargate /dev/null

To stop task, run the following command.

aws lambda invoke --function-name <clusterName>-stop-runners /dev/null

Github runner Docker image

You can pull Github runner image from ghcr.io/heromo/ecs-github-actions-runner:latest .

This image is configurable by the following environment variables.

  • REPOSITORY_URL: [Required] Repository to add the runner to.
  • TOKEN: [Required] Registration token.
  • EPHEMERAL: [Optional] runner runs ephemeral mode, If yes setted.
  • LABELS: [Optional] Extra labels in addition to the default labels.

REPOSITORY_URL is setted in ECS task definition. If you use lamba function to start runners, TOKEN is setted automatically.

Useful commands

  • yarn build compile typescript to js
  • yarn watch watch for changes and compile
  • yarn test perform the jest unit tests
  • yarn eslint check by eslint
  • yarn cdk deploy deploy this stack to your default AWS account/region
  • yarn cdk diff compare deployed stack with current state
  • yarn cdk synth emits the synthesized CloudFormation template

LICENSE

MIT

ecs-github-actions-runner's People

Contributors

dependabot[bot] avatar heromo avatar renovate[bot] avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

npraveenreddy

ecs-github-actions-runner's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Repository problems

These problems occurred while renovating this repository. View logs.

  • WARN: Found renovate config warnings

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Ignored or Blocked

These are blocked by an existing closed PR and will not be recreated unless you click a checkbox below.

Detected dependencies

dockerfile
docker/Dockerfile
github-actions
.github/workflows/eslint.yml
  • actions/checkout v4
  • actions/setup-node v4
  • HeRoMo/pronto-action v1.66.0
.github/workflows/image-publish.yml
  • actions/checkout v4
  • docker/setup-qemu-action v3
  • docker/setup-buildx-action v3
  • docker/login-action v3
  • docker/metadata-action v5
  • docker/build-push-action v6
.github/workflows/jest.yml
  • actions/checkout v4
  • actions/setup-node v4
  • actions/upload-artifact v4
nodenv
.node-version
  • node 20.17.0
npm
package.json
  • @aws-sdk/client-ecs 3.637.0
  • @aws-sdk/client-secrets-manager 3.637.0
  • @aws-sdk/types 3.609.0
  • @octokit/rest 21.0.2
  • aws-cdk-lib 2.75.0
  • config 3.3.12
  • constructs 10.3.0
  • source-map-support 0.5.21
  • @types/aws-lambda 8.10.144
  • @types/config 3.3.4
  • @types/jest 27.5.2
  • @types/node 20.16.2
  • @types/source-map-support 0.5.10
  • @typescript-eslint/eslint-plugin 8.3.0
  • @typescript-eslint/parser 8.3.0
  • aws-cdk 2.75.0
  • esbuild 0.23.1
  • eslint 9.9.1
  • eslint-config-airbnb-base 15.0.0
  • eslint-plugin-googleappsscript 1.0.5
  • eslint-plugin-import 2.29.1
  • eslint-plugin-jest 28.8.0
  • jest 27.5.1
  • ts-jest 27.1.5
  • ts-node 10.9.2
  • typescript 3.9.10

  • Check this box to trigger a request for Renovate to run again on this repository

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.