Skip to content

Commit 01db901

Browse files
Merge pull request #659 from marcofranssen/improve-readme
Improve readme
2 parents 65aab80 + efa2a22 commit 01db901

File tree

5 files changed

+62
-26
lines changed

5 files changed

+62
-26
lines changed

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
.idea
1212
.DS_Store
1313
*.out
14-
example/*.secrets*.tfvars
14+
secrets.auto.tfvars
1515
.envrc
1616
*.zip
1717
*.gz
1818
*.tgz
1919
*.env
2020
.vscode
2121

22-
**/coverage/*
22+
**/coverage/*

README.md

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
[![awesome-runners](https://img.shields.io/badge/listed%20on-awesome--runners-blue.svg)](https://github.com/jonico/awesome-runners)[![Terraform registry](https://img.shields.io/github/v/release/philips-labs/terraform-aws-github-runner?label=Terraform%20Registry)](https://registry.terraform.io/modules/philips-labs/github-runner/aws/) ![Terraform checks](https://github.com/philips-labs/terraform-aws-github-runner/workflows/Terraform%20root%20module%20checks/badge.svg) ![Lambda Webhook](https://github.com/philips-labs/terraform-aws-github-runner/workflows/Lambda%20Agent%20Webhook/badge.svg) ![Lambda Runners](https://github.com/philips-labs/terraform-aws-github-runner/workflows/Lambda%20Runners/badge.svg) ![Lambda Syncer](https://github.com/philips-labs/terraform-aws-github-runner/workflows/Lambda%20Runner%20Binaries%20Syncer/badge.svg)
2-
3-
41
# Terraform module for scalable self hosted GitHub action runners <!-- omit in toc -->
52

3+
[![awesome-runners](https://img.shields.io/badge/listed%20on-awesome--runners-blue.svg)](https://github.com/jonico/awesome-runners)[![Terraform registry](https://img.shields.io/github/v/release/philips-labs/terraform-aws-github-runner?label=Terraform%20Registry)](https://registry.terraform.io/modules/philips-labs/github-runner/aws/) ![Terraform checks](https://github.com/philips-labs/terraform-aws-github-runner/workflows/Terraform%20root%20module%20checks/badge.svg) ![Lambda Webhook](https://github.com/philips-labs/terraform-aws-github-runner/workflows/Lambda%20Agent%20Webhook/badge.svg) ![Lambda Runners](https://github.com/philips-labs/terraform-aws-github-runner/workflows/Lambda%20Runners/badge.svg) ![Lambda Syncer](https://github.com/philips-labs/terraform-aws-github-runner/workflows/Lambda%20Runner%20Binaries%20Syncer/badge.svg)
4+
65
This [Terraform](https://www.terraform.io/) module creates the required infrastructure needed to host [GitHub Actions](https://github.com/features/actions) self hosted, auto scaling runners on [AWS spot instances](https://aws.amazon.com/ec2/spot/). It provides the required logic to handle the life cycle for scaling up and down using a set of AWS Lambda functions. Runners are scaled down to zero to avoid costs when no workflows are active.
76

87
- [Motivation](#motivation)
@@ -75,32 +74,50 @@ Examples are provided in [the example directory](examples/). Please ensure you h
7574
- AWS cli (optional)
7675
- Node and yarn (for lambda development).
7776

78-
The module supports two main scenarios for creating runners. On repository level a runner will be dedicated to only one repository, no other repository can use the runner. On organization level you can use the runner(s) for all the repositories within the organization. See https://help.github.com/en/actions/hosting-your-own-runners/about-self-hosted-runners for more information. Before starting the deployment you have to choose one option.
77+
The module supports two main scenarios for creating runners. On repository level a runner will be dedicated to only one repository, no other repository can use the runner. On organization level you can use the runner(s) for all the repositories within the organization. See [GitHub instructions](https://help.github.com/en/actions/hosting-your-own-runners/about-self-hosted-runners) for more information. Before starting the deployment you have to choose one option.
78+
79+
GitHub workflows fail immediately if there is no action runner available for your builds. Since this module supports scaling down to zero, builds will fail in case there is no active runner available. We recommend to create an offline runner with matching labels to the configuration. Create this runner manually by following the [GitHub instructions](https://help.github.com/en/actions/hosting-your-own-runners/about-self-hosted-runners) for adding a new runner on your local machine. If you stop the process after the step of running the `config.sh` script the runner will remain offline. This offline runner ensures that builds will not fail immediately and stay queued until there is an EC2 runner to pick it up.
80+
81+
Another convenient way of deploying this temporary required runner is using following approach. This automates all the manual labor.
82+
83+
<details>
84+
<summary>Temporary runner using Docker</summary>
85+
86+
```bash
87+
docker run -it --name my-runner \
88+
-e RUNNER_LABELS=selfhosted,Linux,Ubuntu -e RUNNER_NAME=my-repo-docker-runner \
89+
-e GITHUB_ACCESS_TOKEN=$GH_PERSONAL_ACCESS_TOKEN \
90+
-e RUNNER_REPOSITORY_URL=https://github.com/my-org/my-repo \
91+
-v /var/run/docker.sock:/var/run/docker.sock \
92+
tcardonne/github-runner:ubuntu-20.04
93+
```
94+
95+
</details>
7996

80-
GitHub workflows fail immediately if there is no action runner available for your builds. Since this module supports scaling down to zero, builds will fail in case there is no active runner available. We recommend to create an offline runner with matching labels to the configuration. Create this runner manually by following the GitHub instructions for adding a new runner on your local machine. If you stop the process after the step of running the `config.sh` script the runner will remain offline. This offline runner ensures that builds will not fail immediately and stay queued until there is an EC2 runner to pick it up.
97+
You should stop and remove the container once the runner is registered as the builds would otherwise go to your local Docker container.
8198

8299
The setup consists of running Terraform to create all AWS resources and manually configuring the GitHub App. The Terraform module requires configuration from the GitHub App and the GitHub app requires output from Terraform. Therefore you first create the GitHub App and configure the basics, then run Terraform, and afterwards finalize the configuration of the GitHub App.
83100

84101
### Setup GitHub App (part 1)
85102

86-
Go to GitHub and create a new app. Beware you can create apps your organization or for a user. For now we support only organization level apps.
103+
Go to GitHub and [create a new app](https://docs.github.com/en/developers/apps/creating-a-github-app). Beware you can create apps your organization or for a user. For now we support only organization level apps.
87104

88105
1. Create app in Github
89106
2. Choose a name
90107
3. Choose a website (mandatory, not required for the module).
91108
4. Disable the webhook for now (we will configure this later).
92109
5. Permissions for all runners:
93-
- Repository:
94-
- `Actions`: Read-only (check for queued jobs)
95-
- `Checks`: Read-only (receive events for new builds)
96-
- `Metadata`: Read-only (default/required)
110+
- Repository:
111+
- `Actions`: Read-only (check for queued jobs)
112+
- `Checks`: Read-only (receive events for new builds)
113+
- `Metadata`: Read-only (default/required)
97114
6. _Permissions for repo level runners only_:
98-
- Repository:
99-
- `Administration`: Read & write (to register runner)
115+
- Repository:
116+
- `Administration`: Read & write (to register runner)
100117
7. _Permissions for organization level runners only_:
101-
- Organization
102-
- `Administration`: Read & write (to register runner)
103-
- `Self-hosted runners`: Read & write (to register runner)
118+
- Organization
119+
- `Administration`: Read & write (to register runner)
120+
- `Self-hosted runners`: Read & write (to register runner)
104121
8. Save the new app.
105122
9. On the General page, make a note of the "App ID" and "Client ID" parameters.
106123
10. Create a new client secret and also write it down.
@@ -120,7 +137,7 @@ For local development you can build all the lambdas at once using `.ci/build.sh`
120137

121138
#### Service-linked role <!-- omit in toc -->
122139

123-
To create spot instances the `AWSServiceRoleForEC2Spot` role needs to be added to your account. You can do that manually by following the [AWS docs](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/spot-requests.html#service-linked-roles-spot-instance-requests). To use terraform for creating the role, either add the following resource or let the module manage the the service linked role by setting `create_service_linked_role` to `true`. Be aware this is an account global role, so maybe you don't want to mange it via a specific deployment.
140+
To create spot instances the `AWSServiceRoleForEC2Spot` role needs to be added to your account. You can do that manually by following the [AWS docs](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/spot-requests.html#service-linked-roles-spot-instance-requests). To use terraform for creating the role, either add the following resource or let the module manage the the service linked role by setting `create_service_linked_role` to `true`. Be aware this is an account global role, so maybe you don't want to manage it via a specific deployment.
124141

125142
```hcl
126143
resource "aws_iam_service_linked_role" "spot" {
@@ -197,7 +214,7 @@ This is the default, no additional configuration is required.
197214

198215
You have to create an configure you KMS key. The module will use the context with key: `Environment` and value `var.environment` as encryption context.
199216

200-
```HCL
217+
```hcl
201218
resource "aws_kms_key" "github" {
202219
is_enabled = true
203220
}
@@ -231,7 +248,7 @@ idle_config = [{
231248

232249
Cron expressions are parsed by [cron-parser](https://github.com/harrisiirak/cron-parser#readme). The supported syntax.
233250

234-
```
251+
```bash
235252
* * * * * *
236253
┬ ┬ ┬ ┬ ┬ ┬
237254
│ │ │ │ │ |
@@ -379,7 +396,7 @@ We welcome contribution, please checkout the [contribution guide](CONTRIBUTING.m
379396

380397
This module is part of the Philips Forest.
381398

382-
```
399+
```bash
383400

384401
___ _
385402
/ __\__ _ __ ___ ___| |_
@@ -394,7 +411,3 @@ This module is part of the Philips Forest.
394411
Talk to the forestkeepers in the `forest`-channel on Slack.
395412
396413
[![Slack](https://philips-software-slackin.now.sh/badge.svg)](https://philips-software-slackin.now.sh)
397-
398-
```
399-
400-
```

examples/ubuntu/main.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,20 @@ module "runners" {
5151

5252
runner_log_files = [
5353
{
54+
"log_group_name" : "messages",
55+
"prefix_log_group" : true,
56+
"file_path" : "/var/log/messages",
57+
"log_stream_name" : "{instance_id}"
58+
},
59+
{
60+
"log_group_name" : "user_data",
61+
"prefix_log_group" : true,
5462
"file_path" : "/var/log/user-data.log",
5563
"log_stream_name" : "{instance_id}/user_data"
5664
},
5765
{
66+
"log_group_name" : "runner",
67+
"prefix_log_group" : true,
5868
"file_path" : "/home/runners/actions-runner/_diag/Runner_**.log",
5969
"log_stream_name" : "{instance_id}/runner"
6070
}

examples/ubuntu/providers.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ terraform {
1212

1313
provider "aws" {
1414
region = local.aws_region
15+
16+
// If you use roles with specific permissons please add your role
17+
// assume_role {
18+
// role_arn = "arn:aws:iam::123456789012:role/MyAdminRole"
19+
// }
1520
}
1621

1722
provider "random" {

examples/ubuntu/templates/user-data.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,15 @@ ${pre_install}
55

66
# Install AWS CLI
77
apt-get update
8-
DEBIAN_FRONTEND=noninteractive apt-get install -y awscli jq curl wget git uidmap
8+
DEBIAN_FRONTEND=noninteractive apt-get install -y \
9+
awscli \
10+
jq \
11+
curl \
12+
wget \
13+
git \
14+
uidmap \
15+
build-essential \
16+
unzip
917

1018
USER_NAME=runners
1119
useradd -m -s /bin/bash $USER_NAME

0 commit comments

Comments
 (0)