Skip to content

Commit fc96500

Browse files
committed
Refactory, cleanup, update pre-build example
1 parent 61318d5 commit fc96500

File tree

14 files changed

+42
-29
lines changed

14 files changed

+42
-29
lines changed

.editorconfig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,13 @@
1+
# EditorConfig is awesome: https://EditorConfig.org
2+
3+
# top-most EditorConfig file
4+
root = true
5+
16
[*]
7+
indent_style = space
8+
indent_size = 2
9+
tab_width = 2
210
end_of_line = lf
11+
charset = utf-8
12+
trim_trailing_whitespace = true
13+
insert_final_newline = true

.vscode/extensions.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
// Extension identifier format: ${publisher}.${name}. Example: vscode.csharp
66
"editorconfig.editorconfig",
77
"yzhang.markdown-all-in-one",
8-
"sonarsource.sonarlint-vscode",
98
"hashicorp.terraform"
109
]
1110
}

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,7 @@ The example for [ephemeral runners](./examples/ephemeral) is based on the [defau
309309

310310
### Prebuilt Images
311311

312-
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)
313-
312+
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). When the GitHub runner is part of the AMI you can disable the binary syncer by setting `enable_runner_binaries_syncer = false`.
314313

315314
## Examples
316315

@@ -407,6 +406,7 @@ In case the setup does not work as intended follow the trace of events:
407406
| <a name="input_enable_job_queued_check"></a> [enable\_job\_queued\_check](#input\_enable\_job\_queued\_check) | Only scale if the job event received by the scale up lambda is is in the state queued. By default enabled for non ephemeral runners and disabled for ephemeral. Set this variable to overwrite the default behavior. | `bool` | `null` | no |
408407
| <a name="input_enable_managed_runner_security_group"></a> [enable\_managed\_runner\_security\_group](#input\_enable\_managed\_runner\_security\_group) | Enabling the default managed security group creation. Unmanaged security groups can be specified via `runner_additional_security_group_ids`. | `bool` | `true` | no |
409408
| <a name="input_enable_organization_runners"></a> [enable\_organization\_runners](#input\_enable\_organization\_runners) | Register runners to organization, instead of repo level | `bool` | `false` | no |
409+
| <a name="input_enable_runner_binaries_syncer"></a> [enable\_runner\_binaries\_syncer](#input\_enable\_runner\_binaries\_syncer) | Option to disable the lambda to sync GitHub runner distribution, usefull when using a pre-build AMI. | `bool` | `true` | no |
410410
| <a name="input_enable_runner_detailed_monitoring"></a> [enable\_runner\_detailed\_monitoring](#input\_enable\_runner\_detailed\_monitoring) | Should detailed monitoring be enabled for the runner. Set this to true if you want to use detailed monitoring. See https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-cloudwatch-new.html for details. | `bool` | `false` | no |
411411
| <a name="input_enable_ssm_on_runners"></a> [enable\_ssm\_on\_runners](#input\_enable\_ssm\_on\_runners) | Enable to allow access the runner instances for debugging purposes via SSM. Note that this adds additional permissions to the runner instances. | `bool` | `false` | no |
412412
| <a name="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 |

examples/prebuilt/README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Action runners deployment with prebuilt image
22

3-
This module shows how to create GitHub action runners using a prebuilt AMI for the runners
3+
This module shows how to create GitHub action runners using a prebuilt AMI for the runners.
4+
5+
- Configured to run with org level runners.
6+
- GitHub runner binary syncer is not deployed.
47

58
## Usages
69

@@ -56,7 +59,7 @@ module "runners" {
5659
...
5760
# set the name of the ami to use
5861
ami_filter = { name = ["github-runner-amzn2-x86_64-2021*"] }
59-
# provide the owner id of
62+
# provide the owner id of
6063
ami_owners = ["<your owner id>"]
6164
6265
enabled_userdata = false

examples/prebuilt/main.tf

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ module "runners" {
1515
vpc_id = module.vpc.vpc_id
1616
subnet_ids = module.vpc.private_subnets
1717

18-
prefix = local.environment
18+
prefix = local.environment
19+
enable_organization_runners = false
1920

2021
github_app = {
2122
key_base64 = var.github_app_key_base64
@@ -36,6 +37,9 @@ module "runners" {
3637
ami_filter = { name = [var.ami_name_filter] }
3738
ami_owners = [data.aws_caller_identity.current.account_id]
3839

40+
# disable binary syncer since github agent is already installed in the AMI.
41+
enable_runner_binaries_syncer = false
42+
3943
# enable access to the runners via SSM
4044
enable_ssm_on_runners = true
4145

examples/prebuilt/outputs.tf

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
output "runners" {
2-
value = {
3-
lambda_syncer_name = module.runners.binaries_syncer.lambda.function_name
4-
}
5-
}
6-
71
output "webhook_endpoint" {
82
value = module.runners.webhook.endpoint
93
}

images/linux-amzn2/github_agent.linux.pkr.hcl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ packer {
1010
variable "runner_version" {
1111
description = "The version (no v prefix) of the runner software to install https://github.com/actions/runner/releases"
1212
type = string
13-
default = "2.286.1"
13+
default = "2.295.0"
1414
}
1515

1616
variable "region" {

main.tf

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ locals {
33
"ghr:environment" = var.prefix
44
})
55

6-
s3_action_runner_url = var.enable_runner_binaries_syncer ? "s3://${module.runner_binaries[0].bucket.id}/${module.runner_binaries[0].runner_distribution_object_key}" : null
76
github_app_parameters = {
87
id = module.ssm.parameters.github_app_id
98
key_base64 = module.ssm.parameters.github_app_key_base64
@@ -134,8 +133,14 @@ module "runners" {
134133
prefix = var.prefix
135134
tags = local.tags
136135

137-
s3_bucket_runner_binaries = var.enable_runner_binaries_syncer ? module.runner_binaries[0].bucket : null
138-
s3_location_runner_binaries = local.s3_action_runner_url
136+
# s3_bucket_runner_binaries = var.enable_runner_binaries_syncer ? module.runner_binaries[0].bucket : null
137+
# s3_location_runner_binaries = local.s3_action_runner_url
138+
# var.enable_runner_binaries_syncer ? "s3://${module.runner_binaries[0].bucket.id}/${module.runner_binaries[0].runner_distribution_object_key}" : null
139+
s3_runner_binaries = var.enable_runner_binaries_syncer ? {
140+
arn = module.runner_binaries[0].bucket.arn
141+
id = module.runner_binaries[0].bucket.id
142+
key = module.runner_binaries[0].runner_distribution_object_key
143+
} : null
139144

140145
runner_os = var.runner_os
141146
instance_types = var.instance_types

modules/runners/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ yarn run dist
127127
| <a name="input_enable_job_queued_check"></a> [enable\_job\_queued\_check](#input\_enable\_job\_queued\_check) | Only scale if the job event received by the scale up lambda is is in the state queued. By default enabled for non ephemeral runners and disabled for ephemeral. Set this variable to overwrite the default behavior. | `bool` | `null` | no |
128128
| <a name="input_enable_managed_runner_security_group"></a> [enable\_managed\_runner\_security\_group](#input\_enable\_managed\_runner\_security\_group) | Enabling the default managed security group creation. Unmanaged security groups can be specified via `runner_additional_security_group_ids`. | `bool` | `true` | no |
129129
| <a name="input_enable_organization_runners"></a> [enable\_organization\_runners](#input\_enable\_organization\_runners) | n/a | `bool` | n/a | yes |
130+
| <a name="input_enable_runner_binaries_syncer"></a> [enable\_runner\_binaries\_syncer](#input\_enable\_runner\_binaries\_syncer) | Option to disable the lambda to sync GitHub runner distribution, usefull when using a pre-build AMI. | `bool` | `true` | no |
130131
| <a name="input_enable_runner_detailed_monitoring"></a> [enable\_runner\_detailed\_monitoring](#input\_enable\_runner\_detailed\_monitoring) | Enable detailed monitoring for runners | `bool` | `false` | no |
131132
| <a name="input_enable_ssm_on_runners"></a> [enable\_ssm\_on\_runners](#input\_enable\_ssm\_on\_runners) | Enable to allow access to the runner instances for debugging purposes via SSM. Note that this adds additional permissions to the runner instances. | `bool` | n/a | yes |
132133
| <a name="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 |
@@ -180,8 +181,7 @@ yarn run dist
180181
| <a name="input_runners_lambda_s3_key"></a> [runners\_lambda\_s3\_key](#input\_runners\_lambda\_s3\_key) | S3 key for runners lambda function. Required if using S3 bucket to specify lambdas. | `any` | `null` | no |
181182
| <a name="input_runners_lambda_s3_object_version"></a> [runners\_lambda\_s3\_object\_version](#input\_runners\_lambda\_s3\_object\_version) | S3 object version for runners lambda function. Useful if S3 versioning is enabled on source bucket. | `any` | `null` | no |
182183
| <a name="input_runners_maximum_count"></a> [runners\_maximum\_count](#input\_runners\_maximum\_count) | The maximum number of runners that will be created. | `number` | `3` | no |
183-
| <a name="input_s3_bucket_runner_binaries"></a> [s3\_bucket\_runner\_binaries](#input\_s3\_bucket\_runner\_binaries) | n/a | <pre>object({<br> arn = string<br> })</pre> | n/a | yes |
184-
| <a name="input_s3_location_runner_binaries"></a> [s3\_location\_runner\_binaries](#input\_s3\_location\_runner\_binaries) | S3 location of runner distribution. | `string` | n/a | yes |
184+
| <a name="input_s3_runner_binaries"></a> [s3\_runner\_binaries](#input\_s3\_runner\_binaries) | Bucket details for cached GitHub binary. | <pre>object({<br> arn = string<br> id = string<br> key = string<br> })</pre> | n/a | yes |
185185
| <a name="input_scale_down_schedule_expression"></a> [scale\_down\_schedule\_expression](#input\_scale\_down\_schedule\_expression) | Scheduler expression to check every x for scale down. | `string` | `"cron(*/5 * * * ? *)"` | no |
186186
| <a name="input_scale_up_reserved_concurrent_executions"></a> [scale\_up\_reserved\_concurrent\_executions](#input\_scale\_up\_reserved\_concurrent\_executions) | Amount of reserved concurrent executions for the scale-up lambda function. A value of 0 disables lambda from being triggered and -1 removes any concurrency limitations. | `number` | `1` | no |
187187
| <a name="input_sqs_build_queue"></a> [sqs\_build\_queue](#input\_sqs\_build\_queue) | SQS queue to consume accepted build events. | <pre>object({<br> arn = string<br> })</pre> | n/a | yes |

modules/runners/main.tf

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,10 @@ resource "aws_launch_template" "runner" {
122122
)
123123
}
124124

125-
126125
user_data = var.enabled_userdata ? base64encode(templatefile(local.userdata_template, {
127126
pre_install = var.userdata_pre_install
128127
install_runner = templatefile(local.userdata_install_runner[var.runner_os], {
129-
S3_LOCATION_RUNNER_DISTRIBUTION = var.enable_runner_binaries_syncer ? var.s3_location_runner_binaries : ""
128+
S3_LOCATION_RUNNER_DISTRIBUTION = var.enable_runner_binaries_syncer ? "s3://${var.s3_runner_binaries.id}/${var.s3_runner_binaries.key}" : ""
130129
RUNNER_ARCHITECTURE = var.runner_architecture
131130
})
132131
post_install = var.userdata_post_install

modules/runners/policies-runner.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ resource "aws_iam_role_policy" "dist_bucket" {
3939
role = aws_iam_role.runner.name
4040
policy = templatefile("${path.module}/policies/instance-s3-policy.json",
4141
{
42-
s3_arn = var.s3_bucket_runner_binaries.arn
42+
s3_arn = "${var.s3_runner_binaries.arn}/${var.s3_runner_binaries.key}"
4343
}
4444
)
4545
}

modules/runners/policies/instance-s3-policy.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"Sid": "githubActionDist",
66
"Effect": "Allow",
77
"Action": ["s3:GetObject", "s3:GetObjectAcl"],
8-
"Resource": ["${s3_arn}/*"]
8+
"Resource": ["${s3_arn}"]
99
}
1010
]
1111
}

modules/runners/variables.tf

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,15 @@ variable "prefix" {
4646
default = "github-actions"
4747
}
4848

49-
variable "s3_bucket_runner_binaries" {
49+
variable "s3_runner_binaries" {
50+
description = "Bucket details for cached GitHub binary."
5051
type = object({
5152
arn = string
53+
id = string
54+
key = string
5255
})
5356
}
5457

55-
variable "s3_location_runner_binaries" {
56-
description = "S3 location of runner distribution."
57-
type = string
58-
}
59-
6058
variable "block_device_mappings" {
6159
description = "The EC2 instance block device configuration. Takes the following keys: `device_name`, `delete_on_termination`, `volume_type`, `volume_size`, `encrypted`, `iops`, `throughput`, `kms_key_id`, `snapshot_id`."
6260
type = list(object({

outputs.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ output "binaries_syncer" {
1717
value = var.enable_runner_binaries_syncer ? {
1818
lambda = module.runner_binaries[0].lambda
1919
lambda_role = module.runner_binaries[0].lambda_role
20-
location = local.s3_action_runner_url
20+
location = "s3://${module.runner_binaries[0].bucket.id}/module.runner_binaries[0].bucket.key"
2121
bucket = module.runner_binaries[0].bucket
2222
} : null
2323
}

0 commit comments

Comments
 (0)