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
feat: Add hooks for prebuilt images (AMI), including amazon linux packer example (#1444)
* Initial creation of runner image
* Refactored startup script and added it to the per-boot folder
* Make the runner location a variable
So we can pass the runner version in at packer build time if we want to update the runner version.
* Retrieve external config setting via tags
Retrieve the required config via the instance tags so we dont have to pass in and set environment on the instance in an awkward way.
* Enable tag based config
Give the instance the permission to query its own tags and set the correct tags on the instance.
* Add a CI job
* Fix the CI build
* Fix the formatting
* Retain user_data provisioning and remove duplication
refactored to make sure user_data continues to work with minimal breaking changes.
Use a single set of scripts shared between image and user_data provisioning.
* Fix interpolation issues in template file
* fix build
* Fix formatting
* minor tweaks and fixes
* Fixes from testing
* Enable docker on boot
* Add in output of start time for the runner
* Scoop up the runner log
* Add a powershell build script for windows users
* Fix formatting
* Use SSM parameters for configuration
Its best practice to use SSM parameters for configuration of the runners. In adding this i have also added parameter path based config so its easy to extend in the future.
* Make the SSM policy more specific
* Update .github/workflows/packer-build.yml
Co-authored-by: Niek Palm <[email protected]>
* Added condition to the describe tags policy
* Dont use templatefile on the tags policy
Because of the use of ${} in the policy terraform is trying to replace it.
* Added an option to turn off userdata scripting
* Added/updated documentation
* Revert policy as it has no effect on the permissions
* Add reference to prebuilt images in the main readme
* Add an example of deploying with prebuilt images
* Update readme
* Use current user as ami_owner
* Update example to 5 secs
* Updated ami name to include the arch
* Fixed log file variable
* Added explicit info about required settings to the readme
* Change userdata_enabled to enabled_userdata
Keep within existing naming convention
Co-authored-by: Niek Palm <[email protected]>
Copy file name to clipboardExpand all lines: README.md
+11-4
Original file line number
Diff line number
Diff line change
@@ -16,6 +16,7 @@ This [Terraform](https://www.terraform.io/) module creates the required infrastr
16
16
-[Install app](#install-app)
17
17
-[Encryption](#encryption)
18
18
-[Idle runners](#idle-runners)
19
+
-[Prebuilt Images](#prebuilt-images)
19
20
-[Examples](#examples)
20
21
-[Sub modules](#sub-modules)
21
22
-[ARM64 configuration for submodules](#arm64-configuration-for-submodules)
@@ -265,6 +266,10 @@ idle_config = [{
265
266
}]
266
267
```
267
268
269
+
### Prebuilt Images
270
+
271
+
This module also allows you to run agents from a prebuilt AMI to gain faster startup times. You can find more information in [the image README.md](/images/README.md)
272
+
268
273
#### Supported config <!-- omit in toc -->
269
274
270
275
Cron expressions are parsed by [cron-parser](https://github.com/harrisiirak/cron-parser#readme). The supported syntax.
@@ -289,6 +294,7 @@ Examples are located in the [examples](./examples) directory. The following exam
289
294
290
295
-_[Default](examples/default/README.md)_: The default example of the module
291
296
-_[Permissions boundary](examples/permissions-boundary/README.md)_: Example usages of permissions boundaries.
297
+
-_[Prebuilt Images](examples/prebuilt/README.md)_: Example usages of deploying runners with a custom prebuilt image.
292
298
293
299
## Sub modules
294
300
@@ -346,10 +352,10 @@ In case the setup does not work as intended follow the trace of events:
@@ -422,6 +428,7 @@ In case the setup does not work as intended follow the trace of events:
422
428
| <aname="input_syncer_lambda_s3_key"></a> [syncer\_lambda\_s3\_key](#input\_syncer\_lambda\_s3\_key)| S3 key for syncer lambda function. Required if using S3 bucket to specify lambdas. |`any`|`null`| no |
423
429
| <aname="input_syncer_lambda_s3_object_version"></a> [syncer\_lambda\_s3\_object\_version](#input\_syncer\_lambda\_s3\_object\_version)| S3 object version for syncer lambda function. Useful if S3 versioning is enabled on source bucket. |`any`|`null`| no |
424
430
| <aname="input_tags"></a> [tags](#input\_tags)| Map of tags that will be added to created resources. By default resources will be tagged with name and environment. |`map(string)`|`{}`| no |
431
+
| <aname="input_enabled_userdata"></a> [enabled_userdata](#input\_enabled_userdata)| Should the userdata script be enabled for the runner. Set this to false if you are using your own prebuilt AMI |`bool`|`true`| no |
425
432
| <aname="input_userdata_post_install"></a> [userdata\_post\_install](#input\_userdata\_post\_install)| Script to be ran after the GitHub Actions runner is installed on the EC2 instances |`string`|`""`| no |
426
433
| <aname="input_userdata_pre_install"></a> [userdata\_pre\_install](#input\_userdata\_pre\_install)| Script to be ran before the GitHub Actions runner is installed on the EC2 instances |`string`|`""`| no |
427
434
| <aname="input_userdata_template"></a> [userdata\_template](#input\_userdata\_template)| Alternative user-data template, replacing the default template. By providing your own user\_data you have to take care of installing all required software, including the action runner. Variables userdata\_pre/post\_install are ignored. |`string`|`null`| no |
This module shows how to create GitHub action runners using a prebuilt AMI for the runners
4
+
5
+
## Usages
6
+
7
+
Steps for the full setup, such as creating a GitHub app can be found in the root module's [README](../../README.md).
8
+
9
+
### Lambdas
10
+
11
+
You can either download the released lambda code or build them locally yourself.
12
+
13
+
First download the Lambda releases from GitHub. Ensure you have set the version in `lambdas-download/main.tf` for running the example. The version needs to be set to a GitHub release version, see https://github.com/philips-labs/terraform-aws-github-runner/releases
14
+
15
+
```bash
16
+
cd lambdas-download
17
+
terraform init
18
+
terraform apply
19
+
cd ..
20
+
```
21
+
22
+
Alternatively you can build the lambdas locally with Node or Docker, there is a simple build script in `<root>/.ci/build.sh`. In the `main.tf` you need to specify the build location for all of the zip files.
Before running Terraform, ensure the GitHub app is configured. See the [configuration details](../../README.md#usages) for more details.
33
+
34
+
### Packer Image
35
+
36
+
You will need to build your image. This example deployment uses the image example in `/images/linux-amz2`. You must build this image with packer in your AWS account first. Once you have built this you need to provider your owner ID as a variable
37
+
38
+
## Deploy
39
+
40
+
To use your image in the terraform modules you will need to set some values on the module.
41
+
42
+
Assuming you have built the `linux-amzn2` image which has a pre-defined AMI name in the following format `github-runner-amzn2-x86_64-YYYYMMDDhhmm` you can use the following values.
43
+
44
+
```hcl
45
+
46
+
module "runners" {
47
+
...
48
+
# set the name of the ami to use
49
+
ami_filter = { name = ["github-runner-amzn2-x86_64-2021*"] }
50
+
# provide the owner id of
51
+
ami_owners = ["<your owner id>"]
52
+
53
+
enabled_userdata = false
54
+
...
55
+
}
56
+
```
57
+
58
+
If your owner is the same as the account you are logging into then you can use `aws_caller_identity` to retrieve it dynamically.
0 commit comments