You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Merge
* Add extra parameters to configure lambda
* Experiment with varialbes
* Experiment with varialbes
* Experiment with varialbes
* Experiment with varialbes
* Experiment with varialbes
* Experiment with varialbes
* Experiment with varialbes
* Experiment with dist
* Experiment with dist
* Experiment with dist
* Experiment with dist
* Experiment with dist
* Experiment with dist
* Experiment with dist
* Experiment with dist
* Experiment with dist
* Experiment with dist
* Experiment with dist
* Experiment with dist
* Experiment with dist
* Experiment with dist
* Experiment with dist
* Experiment with dist
* Experiment with dist
* Experiment with dist
* Experiment with dist
* Experiment with dist
* Experiment with dist
* Experiment with dist
* Experiment with dist
* Experiment with dist
* Experiment with dist
* Experiment with dist
* Experiment with dist
* Experiment with dist
* Experiment with dist
* Experiment with dist
* Experiment with dist
* Experiment with dist
* Experiment with dist
* Experiment with dist
* Experiment with dist
* Refactor to have predictive names
* Refactor to have predictive names
* Refactor to have predictive names
* Refactor to have predictive names
* Refactor to have predictive names
* Refactor to have predictive names
* Refactor to have predictive names
* Refactor to have predictive names
* Refactor to have predictive names
* Add option to download lambd's
* cleanup
* Move sqs policy for webhook to root module
* Fix release
* Refactor to aws_iam_role_policy instead of policy attachment
* trigger
* cleanup, refactor
* cleanup, refactor
* Add tagging, and set concurrency for scale lambda to 1
* Update readme, explain offline runners
* Update readme, fix typos and restructure some sentences
Co-authored-by: Gertjan Maas <[email protected]>
Copy file name to clipboardExpand all lines: README.md
+79-11Lines changed: 79 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,12 +1,10 @@
1
1
# Terraform module for scalable self hosted GitHub action runners
2
2
3
-
> WIP: Module is in development
4
-
5
3
This [Terraform](https://www.terraform.io/) modules create the required infra structure needed to host [GitHub Action](https://github.com/features/actions) self hosted runners on [AWS spot instances](https://aws.amazon.com/ec2/spot/). All logic required to handle the lifecycle for an action runners is implemented in AWS Lambda functions.
6
4
7
5
## Motivation
8
6
9
-
GitHub Actions `self hosted` runners provides you with a flexible option to run your CI workloads on compute of your choice. Currently there is no option provided to automate the creation and scaling of action runners. This module takes care of creating the AWS infra structure to host action runners on spot instances. And provides lambda modules to orchestrate the lifecycle of the action runners.
7
+
GitHub Actions `self hosted` runners provides you with a flexible option to run your CI workloads on compute of your choice. Currently there is no option provided to automate the creation and scaling of action runners. This module takes care of creating the AWS infra structure to host action runners on spot instances. And provides lambda modules to orchestrate the life cycle of the action runners.
10
8
11
9
Lambda is chosen as runtime for two major reasons. First it allows to create small components with minimal access to AWS and GitHub. Secondly it provides a scalable setup for minimal costs that works on repo level and scales to organization level. The lambdas will create Linux based EC2 instances with Docker to serve CI workloads that can run on Linux and/or Docker. The main goal is here to support Docker based workloads.
12
10
@@ -37,12 +35,15 @@ Besides these permissions, the lambdas also need permission to CloudWatch (for l
37
35
Examples are provided in [the example directory](examples/). Please ensure you have installed the following tools.
38
36
39
37
- Terraform, or [tfenv](https://github.com/tfutils/tfenv).
40
-
- Bash shell or compatible.
41
-
- TODO: building lambda ?
42
-
- AWS cli
38
+
- Bash shell or compatible
39
+
- Docker (optional, to build lambdas without node).
40
+
- AWS cli (optional)
41
+
- Node and yarn (for lambda development).
43
42
44
43
The module support 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.
45
44
45
+
GitHub workflows will fail immediately if there is no action runner available for your builds. Since this module supports to scale from 0 and up, your builds will fail in case there is no active runner available. So we recommend to create an offline runner with matching labels to the configuration. Create this runner by following the GitHub instruction on your local machine. You can stop the process after the step of running the `config.sh`. This offline runner will ensure your builds will not fail immediately and stay queued until there is a runner to pick it up.
46
+
46
47
The setup consists of running Terraform to create all AWS resources and configure the GitHub App. The Terraform module requires configuration from the GitHub App and the GitHub app requires output from Terraform. Therefore you should first create the GitHub App, configure the basics. Then run Terraform and finalize the configuration of the GitHub App afterwards.
47
48
48
49
### Setup GitHub App (part 1)
@@ -62,11 +63,41 @@ Go to GitHub and create a new app. Beware you can create apps your organization
62
63
63
64
### Setup terraform module
64
65
65
-
1. Create a terraform workspace and initiate the module, see the examples for more details.
66
+
First you need to download the lambda releases. The lambda code is available as a GitHub release asset. Downloading can be done with the provided terraform module for example. Note that this requires `curl` to be installed on your machine. Create an empty workspace with the following terraform code:
67
+
68
+
```terraform
69
+
module "lambdas" {
70
+
source = "../../../modules/download-lambda"
71
+
lambdas = [
72
+
{
73
+
name = "webhook"
74
+
tag = "v0.0.0-beta"
75
+
},
76
+
{
77
+
name = "runners"
78
+
tag = "v0.0.0-beta"
79
+
},
80
+
{
81
+
name = "runner-binaries-syncer"
82
+
tag = "v0.0.0-beta"
83
+
}
84
+
]
85
+
}
86
+
87
+
output "files" {
88
+
value = module.lambdas.files
89
+
}
90
+
```
91
+
92
+
Next run `terraform init && terraform apply` as result the lambdas will be download to the same directory. Alternatively you can download the zip artifacts with any other tool of you favour.
93
+
94
+
For local development you can build all the lambda's at once using `.ci/build.sh` or per lambda using `yarn dist`.
95
+
96
+
Next create a second terraform workspace and initiate the module, see the examples for more details.
3.Check the terraform output for the API gateway url, which you need in the next step.
130
+
Check the terraform output for the API gateway url (endpoint), which you need in the next step. The lambda for syncing the GitHub distribution will be executed by a trigger via CloudWatch. To ensure the binary is cached, trigger the `runner-binaries-syncer` manually. The payload does not matter. (e.g. `aws lambda invoke --function-name <environment>-syncer response.json`)
97
131
98
132
### Setup GitHub App (part 2)
99
133
@@ -104,8 +138,42 @@ Go back to the GitHub App and update the following settings.
104
138
3. Provide the webhook secret.
105
139
4. Enable the `Check run` event for the webhook.
106
140
141
+
You are now ready to run action workloads on self hosted runner, remember builds will fail if there is no (offline) runner available with matching labels.
142
+
107
143
## Examples
108
144
145
+
TODO
146
+
147
+
## Inputs
148
+
149
+
| Name | Description | Type | Default | Required |
| environment | A name that identifies the environment, used as prefix and for tagging. |`string`| n/a | yes |
154
+
| github_app | GitHub app parameters, see your github aapp. Ensure the key is base64 encoded. | <pre>object({<br> key_base64 = string<br> id = string<br> client_id = string<br> client_secret = string<br> webhook_secret = string<br> })</pre> | n/a | yes |
155
+
| subnet_ids | List of subnets in which the action runners will be launched, the subnets needs to be subnets in the `vpc_id`. |`list(string)`| n/a | yes |
156
+
| vpc_id | The VPC for security groups of the action runners. |`string`| n/a | yes |
157
+
| minimum_running_time_in_minutes | The time an ec2 action runner should be running at minium before terminated if non busy. |`number`|`5`| no |
158
+
| runner_binaries_syncer_lambda_timeout | Time out of the binaries sync lambda in seconds. |`number`|`300`| no |
159
+
| runner_binaries_syncer_lambda_zip | File location of the binaries sync lambda zip file. |`string`|`null`| no |
160
+
| runner_extra_labels | Extra labels for the runners (GitHub). Separate each label by a comma |`string`|`""`| no |
161
+
| runners_lambda_zip | File location of the lambda zip file for scaling runners. |`string`|`null`| no |
162
+
| runners_scale_down_lambda_timeout | Time out for the scale up lambda in seconds. |`number`|`60`| no |
163
+
| runners_scale_up_lambda_timeout | Time out for the scale down lambda in seconds. |`number`|`60`| no |
164
+
| scale_down_schedule_expression | Scheduler expression to check every x for scale down. |`string`|`"cron(*/5 * * * ? *)"`| no |
165
+
| tags | Map of tags that will be added to created resources. By default resources will be tagged with name and environment. |`map(string)`|`{}`| no |
166
+
| webhook_lambda_timeout | Time out of the webhook lambda in seconds. |`number`|`10`| no |
167
+
| webhook_lambda_zip | File location of the wehbook lambda zip file. |`string`|`null`| no |
0 commit comments