https://github.com/nikovirtala/cdk-github-actions-runner
Deploy self-hosted GitHub Actions runner to AWS Fargate using AWS Cloud Development Kit (CDK)
https://github.com/nikovirtala/cdk-github-actions-runner
aws-ecs aws-fargate aws-fargate-application cdk cdk-examples ecs-service fargate
Last synced: 7 days ago
JSON representation
Deploy self-hosted GitHub Actions runner to AWS Fargate using AWS Cloud Development Kit (CDK)
- Host: GitHub
- URL: https://github.com/nikovirtala/cdk-github-actions-runner
- Owner: nikovirtala
- License: mit
- Created: 2020-04-22T07:46:24.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2023-06-19T22:58:39.000Z (almost 2 years ago)
- Last Synced: 2025-03-29T12:51:19.501Z (28 days ago)
- Topics: aws-ecs, aws-fargate, aws-fargate-application, cdk, cdk-examples, ecs-service, fargate
- Language: TypeScript
- Homepage:
- Size: 488 KB
- Stars: 128
- Watchers: 7
- Forks: 24
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# GitHub Actions runner on AWS Fargate
This repository contains an example how to run self-hosted GitHub Actions runners on AWS Fargate!
## Construct
The solution presented in this repository is available as a Construct library in [NPM](https://www.npmjs.com/package/@cloudgardener/cdk-aws-fargate-github-actions-runner) and [GitHub](https://github.com/cloudgardener/cdk-aws-fargate-github-actions-runner).
You can import it to your project by:
```ts
import { GithubActionsRunner } from "@cloudgardener/cdk-aws-fargate-github-actions-runner";
```## Docker image
Docker image is based on [`ubuntu:20.04`](https://hub.docker.com/_/ubuntu) / `focal`. I may consider moving back to `ubuntu:rolling` once https://github.com/actions/runner/issues/1584 is resolved.
On top the base image I have installed GitHub Actions Runner based on [About self-hosted runners](https://help.github.com/en/actions/hosting-your-own-runners/about-self-hosted-runners) in GitHub documentation.
## Deployment
The application is deployed to AWS using [AWS Cloud Development Kit (AWS CDK)](https://docs.aws.amazon.com/cdk/latest/guide/home.html).
- Store two parameters `GITHUB_ACCESS_TOKEN` and `GITHUB_ACTIONS_RUNNER_CONTEXT` in to SSM Parameter Store.
- For repository level runner set `GITHUB_ACTIONS_RUNNER_CONTEXT` value to `https://github.com//`
- For organization level runner set `GITHUB_ACTIONS_RUNNER_CONTEXT` value to `https://github.com/`
- Run `cdk synth --profile `
- Run `cdk deploy --profile `
- Wait a little while ...Now you should be able find your self-hosted runner from repository setting in GitHub:

We can see also from the Fargate Task Logs that the runner is successfully registered:

## Personal Access Token Scopes
Registering self-hosted runner to repository level requires admin access to the repository, and `repo` scope for the access token.

Registering self-hosted runner to Organization level requires admin access to the organization, and `admin:org` scope for the access token.

## Price Comparision
You can read about the comparisions I made from [Price Comparision](docs/price-comparision.md) document.
## Useful commands
- `npm run build` compile typescript to js
- `npm run watch` watch for changes and compile
- `npm run test` perform the jest unit tests
- `cdk deploy` deploy this stack to your default AWS account/region
- `cdk diff` compare deployed stack with current state
- `cdk synth` emits the synthesized CloudFormation template