Skip to content
This repository was archived by the owner on Jan 16, 2025. It is now read-only.

Commit 77f350b

Browse files
authored
feat: Change default location of runner to /opt and fix Ubuntu example (#1572)
1 parent b76acbe commit 77f350b

File tree

11 files changed

+35
-15
lines changed

11 files changed

+35
-15
lines changed

Diff for: README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ In case the setup does not work as intended follow the trace of events:
422422
| <a name="input_role_permissions_boundary"></a> [role\_permissions\_boundary](#input\_role\_permissions\_boundary) | Permissions boundary that will be added to the created roles. | `string` | `null` | no |
423423
| <a name="input_runner_additional_security_group_ids"></a> [runner\_additional\_security\_group\_ids](#input\_runner\_additional\_security\_group\_ids) | (optional) List of additional security groups IDs to apply to the runner | `list(string)` | `[]` | no |
424424
| <a name="input_runner_allow_prerelease_binaries"></a> [runner\_allow\_prerelease\_binaries](#input\_runner\_allow\_prerelease\_binaries) | Allow the runners to update to prerelease binaries. | `bool` | `false` | no |
425-
| <a name="input_runner_as_root"></a> [runner\_as\_root](#input\_runner\_as\_root) | Run the action runner under the root user. | `bool` | `false` | no |
425+
| <a name="input_runner_as_root"></a> [runner\_as\_root](#input\_runner\_as\_root) | Run the action runner under the root user. Variable `runner_run_as` will be ingored. | `bool` | `false` | no |
426426
| <a name="input_runner_binaries_s3_sse_configuration"></a> [runner\_binaries\_s3\_sse\_configuration](#input\_runner\_binaries\_s3\_sse\_configuration) | Map containing server-side encryption configuration for runner-binaries S3 bucket. | `any` | `{}` | no |
427427
| <a name="input_runner_binaries_syncer_lambda_timeout"></a> [runner\_binaries\_syncer\_lambda\_timeout](#input\_runner\_binaries\_syncer\_lambda\_timeout) | Time out of the binaries sync lambda in seconds. | `number` | `300` | no |
428428
| <a name="input_runner_binaries_syncer_lambda_zip"></a> [runner\_binaries\_syncer\_lambda\_zip](#input\_runner\_binaries\_syncer\_lambda\_zip) | File location of the binaries sync lambda zip file. | `string` | `null` | no |
@@ -435,6 +435,7 @@ In case the setup does not work as intended follow the trace of events:
435435
| <a name="input_runner_log_files"></a> [runner\_log\_files](#input\_runner\_log\_files) | (optional) Replaces the module default cloudwatch log config. See https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Agent-Configuration-File-Details.html for details. | <pre>list(object({<br> log_group_name = string<br> prefix_log_group = bool<br> file_path = string<br> log_stream_name = string<br> }))</pre> | `null` | no |
436436
| <a name="input_runner_metadata_options"></a> [runner\_metadata\_options](#input\_runner\_metadata\_options) | Metadata options for the ec2 runner instances. | `map(any)` | <pre>{<br> "http_endpoint": "enabled",<br> "http_put_response_hop_limit": 1,<br> "http_tokens": "optional"<br>}</pre> | no |
437437
| <a name="input_runner_os"></a> [runner\_os](#input\_runner\_os) | The Operating System to use for GitHub Actions Runners (linux,win) | `string` | `"linux"` | no |
438+
| <a name="input_runner_run_as"></a> [runner\_run\_as](#input\_runner\_run\_as) | Run the GitHub actions agent as user. | `string` | `"ec2-user"` | no |
438439
| <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 |
439440
| <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 |
440441
| <a name="input_runners_lambda_zip"></a> [runners\_lambda\_zip](#input\_runners\_lambda\_zip) | File location of the lambda zip file for scaling runners. | `string` | `null` | no |

Diff for: examples/ubuntu/main.tf

+1-2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ module "runners" {
3535
# enable access to the runners via SSM
3636
enable_ssm_on_runners = true
3737

38+
runner_run_as = "runners"
3839
userdata_template = "./templates/user-data.sh"
3940
ami_owners = ["099720109477"] # Canonical's Amazon account ID
4041

@@ -75,6 +76,4 @@ module "runners" {
7576
# idleCount = 1
7677
# }]
7778

78-
# disable KMS and encryption
79-
# encrypt_secrets = false
8079
}

Diff for: examples/ubuntu/outputs.tf

+8-5
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@ output "runners" {
44
}
55
}
66

7-
output "webhook" {
8-
value = {
9-
secret = random_id.random.hex
10-
endpoint = module.runners.webhook.endpoint
11-
}
7+
output "webhook_endpoint" {
8+
value = module.runners.webhook.endpoint
129
}
10+
11+
output "webhook_secret" {
12+
sensitive = true
13+
value = random_id.random.hex
14+
}
15+

Diff for: examples/ubuntu/templates/user-data.sh

+3-1
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,12 @@ su -l $USER_NAME -c "systemctl --user enable docker"
6262
${install_runner}
6363

6464
# config runner for rootless docker
65-
cd /home/$USER_NAME/actions-runner/
65+
cd /opt/actions-runner/
6666
echo DOCKER_HOST=unix:///run/user/$USER_ID/docker.sock >>.env
6767
echo PATH=/home/$USER_NAME/bin:$PATH >>.env
6868

6969
${post_install}
7070

71+
cd /opt/actions-runner
72+
7173
${start_runner}

Diff for: main.tf

+1
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ module "runners" {
110110
runner_boot_time_in_minutes = var.runner_boot_time_in_minutes
111111
runner_extra_labels = var.runner_extra_labels
112112
runner_as_root = var.runner_as_root
113+
runner_run_as = var.runner_run_as
113114
runners_maximum_count = var.runners_maximum_count
114115
idle_config = var.idle_config
115116
enable_ssm_on_runners = var.enable_ssm_on_runners

Diff for: modules/runners/README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -150,14 +150,15 @@ No modules.
150150
| <a name="input_role_permissions_boundary"></a> [role\_permissions\_boundary](#input\_role\_permissions\_boundary) | Permissions boundary that will be added to the created role for the lambda. | `string` | `null` | no |
151151
| <a name="input_runner_additional_security_group_ids"></a> [runner\_additional\_security\_group\_ids](#input\_runner\_additional\_security\_group\_ids) | (optional) List of additional security groups IDs to apply to the runner | `list(string)` | `[]` | no |
152152
| <a name="input_runner_architecture"></a> [runner\_architecture](#input\_runner\_architecture) | The platform architecture of the runner instance\_type. | `string` | `"x64"` | no |
153-
| <a name="input_runner_as_root"></a> [runner\_as\_root](#input\_runner\_as\_root) | Run the action runner under the root user. | `bool` | `false` | no |
153+
| <a name="input_runner_as_root"></a> [runner\_as\_root](#input\_runner\_as\_root) | Run the action runner under the root user. Variable `runner_run_as` will be ingored. | `bool` | `false` | no |
154154
| <a name="input_runner_boot_time_in_minutes"></a> [runner\_boot\_time\_in\_minutes](#input\_runner\_boot\_time\_in\_minutes) | The minimum time for an EC2 runner to boot and register as a runner. | `number` | `5` | no |
155155
| <a name="input_runner_ec2_tags"></a> [runner\_ec2\_tags](#input\_runner\_ec2\_tags) | Map of tags that will be added to the launch template instance tag specificatons. | `map(string)` | `{}` | no |
156156
| <a name="input_runner_extra_labels"></a> [runner\_extra\_labels](#input\_runner\_extra\_labels) | Extra labels for the runners (GitHub). Separate each label by a comma | `string` | `""` | no |
157157
| <a name="input_runner_group_name"></a> [runner\_group\_name](#input\_runner\_group\_name) | Name of the runner group. | `string` | `"Default"` | no |
158158
| <a name="input_runner_iam_role_managed_policy_arns"></a> [runner\_iam\_role\_managed\_policy\_arns](#input\_runner\_iam\_role\_managed\_policy\_arns) | Attach AWS or customer-managed IAM policies (by ARN) to the runner IAM role | `list(string)` | `[]` | no |
159159
| <a name="input_runner_log_files"></a> [runner\_log\_files](#input\_runner\_log\_files) | (optional) List of logfiles to send to CloudWatch, will only be used if `enable_cloudwatch_agent` is set to true. Object description: `log_group_name`: Name of the log group, `prefix_log_group`: If true, the log group name will be prefixed with `/github-self-hosted-runners/<var.environment>`, `file_path`: path to the log file, `log_stream_name`: name of the log stream. | <pre>list(object({<br> log_group_name = string<br> prefix_log_group = bool<br> file_path = string<br> log_stream_name = string<br> }))</pre> | `null` | no |
160160
| <a name="input_runner_os"></a> [runner\_os](#input\_runner\_os) | The EC2 Operating System type to use for action runner instances (linux,win). | `string` | `"linux"` | no |
161+
| <a name="input_runner_run_as"></a> [runner\_run\_as](#input\_runner\_run\_as) | Run the GitHub actions agent as user. | `string` | `"ec2-user"` | no |
161162
| <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 |
162163
| <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 |
163164
| <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 |

Diff for: modules/runners/runner-config.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
resource "aws_ssm_parameter" "runner_config_run_as" {
22
name = "/${var.environment}/runner/run-as"
33
type = "String"
4-
value = var.runner_as_root ? "root" : "ec2-user"
4+
value = var.runner_as_root ? "root" : var.runner_run_as
55
tags = local.tags
66
}
77

Diff for: modules/runners/templates/install-runner.sh

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@ fi
1212
file_name="actions-runner.tar.gz"
1313

1414
echo "Creating actions-runner directory for the GH Action installtion"
15-
cd /home/"$user_name"
15+
cd /opt/
1616
mkdir actions-runner && cd actions-runner
1717

18-
1918
if [[ -n "$RUNNER_TARBALL_URL" ]]; then
2019
echo "Downloading the GH Action runner from $RUNNER_TARBALL_URL to $file_name"
2120
curl -o $file_name -L "$RUNNER_TARBALL_URL"

Diff for: modules/runners/templates/start-runner.sh

+2
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ if [[ "$run_as" == "root" ]]; then
5858
export RUNNER_ALLOW_RUNASROOT=1
5959
fi
6060

61+
chown -R $run_as .
62+
6163
echo "Configure GH Runner as user $run_as"
6264
sudo --preserve-env=RUNNER_ALLOW_RUNASROOT -u "$run_as" -- ./config.sh --unattended --name "$instance_id" --work "_work" $${config}
6365

Diff for: modules/runners/variables.tf

+7-1
Original file line numberDiff line numberDiff line change
@@ -208,11 +208,17 @@ variable "instance_profile_path" {
208208
}
209209

210210
variable "runner_as_root" {
211-
description = "Run the action runner under the root user."
211+
description = "Run the action runner under the root user. Variable `runner_run_as` will be ingored."
212212
type = bool
213213
default = false
214214
}
215215

216+
variable "runner_run_as" {
217+
description = "Run the GitHub actions agent as user."
218+
type = string
219+
default = "ec2-user"
220+
}
221+
216222
variable "runners_maximum_count" {
217223
description = "The maximum number of runners that will be created."
218224
type = number

Diff for: variables.tf

+7-1
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,17 @@ variable "instance_type" {
148148
}
149149

150150
variable "runner_as_root" {
151-
description = "Run the action runner under the root user."
151+
description = "Run the action runner under the root user. Variable `runner_run_as` will be ingored."
152152
type = bool
153153
default = false
154154
}
155155

156+
variable "runner_run_as" {
157+
description = "Run the GitHub actions agent as user."
158+
type = string
159+
default = "ec2-user"
160+
}
161+
156162
variable "runners_maximum_count" {
157163
description = "The maximum number of runners that will be created."
158164
type = number

0 commit comments

Comments
 (0)