Skip to content

Commit 4a0f722

Browse files
authored
chore(examples): multi-runner example with separate configuration files (#3139)
The example shows how runner configurations can be configured in Yaml files. This has the following advantages: - Compacter files for better readability = Possibility to use CODEOWNERS file on the different configurations.
1 parent a4e842a commit 4a0f722

File tree

5 files changed

+144
-135
lines changed

5 files changed

+144
-135
lines changed

examples/multi-runner/main.tf

Lines changed: 28 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -1,148 +1,41 @@
11
locals {
22
environment = var.environment != null ? var.environment : "multi-runner"
33
aws_region = "eu-west-1"
4+
5+
# Load runner configurations from Yaml files
6+
multi_runner_config = { for c in fileset("${path.module}/templates/runner-configs", "*.yaml") : trimsuffix(c, ".yaml") => yamldecode(file("${path.module}/templates/runner-configs/${c}")) }
47
}
58

69
resource "random_id" "random" {
710
byte_length = 20
811
}
912

1013
module "multi-runner" {
11-
source = "../../modules/multi-runner"
12-
multi_runner_config = {
13-
"linux-arm64" = {
14-
matcherConfig : {
15-
labelMatchers = [["self-hosted", "linux", "arm64", "amazon"]]
16-
exactMatch = true
17-
}
18-
fifo = true
19-
delay_webhook_event = 0
20-
redrive_build_queue = {
21-
enabled = false
22-
maxReceiveCount = null
23-
}
24-
runner_config = {
25-
runner_os = "linux"
26-
runner_architecture = "arm64"
27-
runner_extra_labels = "amazon"
28-
runner_name_prefix = "amazon-arm64_"
29-
enable_ssm_on_runners = true
30-
instance_types = ["t4g.large", "c6g.large"]
31-
runners_maximum_count = 1
32-
scale_down_schedule_expression = "cron(* * * * ? *)"
33-
}
34-
},
35-
"linux-ubuntu" = {
36-
matcherConfig : {
37-
labelMatchers = [["self-hosted", "linux", "x64", "ubuntu-latest"], ["self-hosted", "linux", "x64", "ubuntu-2204"]]
38-
exactMatch = true
39-
}
40-
fifo = true
41-
delay_webhook_event = 0
42-
redrive_build_queue = {
43-
enabled = false
44-
maxReceiveCount = null
45-
}
46-
runner_config = {
47-
runner_os = "linux"
48-
runner_architecture = "x64"
49-
runner_extra_labels = "ubuntu-latest,ubuntu-2204"
50-
runner_run_as = "ubuntu"
51-
runner_name_prefix = "ubuntu-2204-x64_"
52-
enable_ssm_on_runners = true
53-
instance_types = ["m5ad.large", "m5a.large"]
54-
runners_maximum_count = 1
55-
scale_down_schedule_expression = "cron(* * * * ? *)"
56-
userdata_template = "./templates/user-data.sh"
57-
ami_owners = ["099720109477"] # Canonical's Amazon account ID
58-
59-
ami_filter = {
60-
name = ["ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*"]
61-
}
62-
block_device_mappings = [{
63-
# Set the block device name for Ubuntu root device
64-
device_name = "/dev/sda1"
65-
delete_on_termination = true
66-
volume_type = "gp3"
67-
volume_size = 30
68-
encrypted = true
69-
iops = null
70-
throughput = null
71-
kms_key_id = null
72-
snapshot_id = null
73-
}]
74-
runner_log_files = [
75-
{
76-
log_group_name = "syslog"
77-
prefix_log_group = true
78-
file_path = "/var/log/syslog"
79-
log_stream_name = "{instance_id}"
80-
},
81-
{
82-
log_group_name = "user_data"
83-
prefix_log_group = true
84-
file_path = "/var/log/user-data.log"
85-
log_stream_name = "{instance_id}/user_data"
86-
},
87-
{
88-
log_group_name = "runner"
89-
prefix_log_group = true
90-
file_path = "/opt/actions-runner/_diag/Runner_**.log",
91-
log_stream_name = "{instance_id}/runner"
92-
}
93-
]
94-
}
95-
},
96-
"windows-x64" = {
97-
matcherConfig : {
98-
labelMatchers = [["self-hosted", "windows", "x64", "servercore-2022"]]
99-
exactMatch = true
100-
}
101-
fifo = true
102-
delay_webhook_event = 5
103-
runner_config = {
104-
runner_os = "windows"
105-
runner_architecture = "x64"
106-
runner_name_prefix = "servercore-2022-x64_"
107-
enable_ssm_on_runners = true
108-
instance_types = ["m5.large", "c5.large"]
109-
runner_extra_labels = "servercore-2022"
110-
runners_maximum_count = 1
111-
scale_down_schedule_expression = "cron(* * * * ? *)"
112-
runner_boot_time_in_minutes = 20
113-
ami_filter = {
114-
name = ["Windows_Server-2022-English-Core-ContainersLatest-*"]
115-
}
116-
}
117-
},
118-
"linux-x64" = {
119-
matcherConfig : {
120-
labelMatchers = [["self-hosted", "linux", "x64", "amazon"]]
121-
exactMatch = false
122-
}
123-
fifo = true
124-
delay_webhook_event = 0
125-
runner_config = {
126-
# Test retrieving tag information via AWS API (Cli)
127-
runner_metadata_options = {
128-
instance_metadata_tags = "disabled"
129-
http_endpoint = "enabled"
130-
http_tokens = "optional"
131-
http_put_response_hop_limit = 1
132-
}
133-
runner_os = "linux"
134-
runner_architecture = "x64"
135-
runner_name_prefix = "amazon-x64_"
136-
create_service_linked_role_spot = true
137-
enable_ssm_on_runners = true
138-
instance_types = ["m5ad.large", "m5a.large"]
139-
runner_extra_labels = "amazon"
140-
runners_maximum_count = 1
141-
enable_ephemeral_runners = true
142-
scale_down_schedule_expression = "cron(* * * * ? *)"
143-
}
144-
}
145-
}
14+
source = "../../modules/multi-runner"
15+
multi_runner_config = local.multi_runner_config
16+
# Alternative to loading runner configuration from Yaml files is using static configuration:
17+
# multi_runner_config = {
18+
# "linux-x64" = {
19+
# matcherConfig : {
20+
# labelMatchers = [["self-hosted", "linux", "x64", "amazon"]]
21+
# exactMatch = false
22+
# }
23+
# fifo = true
24+
# delay_webhook_event = 0
25+
# runner_config = {
26+
# runner_os = "linux"
27+
# runner_architecture = "x64"
28+
# runner_name_prefix = "amazon-x64_"
29+
# create_service_linked_role_spot = true
30+
# enable_ssm_on_runners = true
31+
# instance_types = ["m5ad.large", "m5a.large"]
32+
# runner_extra_labels = "amazon"
33+
# runners_maximum_count = 1
34+
# enable_ephemeral_runners = true
35+
# scale_down_schedule_expression = "cron(* * * * ? *)"
36+
# }
37+
# }
38+
# }
14639
aws_region = local.aws_region
14740
vpc_id = module.vpc.vpc_id
14841
subnet_ids = module.vpc.private_subnets
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
matcherConfig:
2+
exactMatch: true
3+
labelMatchers:
4+
- [self-hosted, linux, arm64, amazon]
5+
fifo: true
6+
delay_webhook_event: 0
7+
redrive_build_queue:
8+
enabled: false
9+
maxReceiveCount: null
10+
runner_config:
11+
runner_os: linux
12+
runner_architecture: arm64
13+
runner_extra_labels: amazon
14+
runner_name_prefix: amazon-arm64_
15+
enable_ssm_on_runners: true
16+
instance_types:
17+
- t4g.large
18+
- c6g.large
19+
runners_maximum_count: 1
20+
scale_down_schedule_expression: cron(* * * * ? *)
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
matcherConfig:
2+
exactMatch: true
3+
labelMatchers:
4+
- [ self-hosted, linux, x64, ubuntu-latest ]
5+
- [ self-hosted, linux, x64, ubuntu-2204 ]
6+
fifo: true
7+
delay_webhook_event: 0
8+
redrive_build_queue:
9+
enabled: false
10+
maxReceiveCount: null
11+
runner_config:
12+
runner_os: linux
13+
runner_architecture: x64
14+
runner_extra_labels: ubuntu-latest,ubuntu-2204
15+
runner_run_as: ubuntu
16+
runner_name_prefix: ubuntu-2204-x64_
17+
enable_ssm_on_runners: true
18+
instance_types:
19+
- m5ad.large
20+
- m5a.large
21+
runners_maximum_count: 1
22+
scale_down_schedule_expression: cron(* * * * ? *)
23+
userdata_template: ./templates/user-data.sh
24+
ami_owners:
25+
- "099720109477" # Canonical's Amazon account ID
26+
ami_filter:
27+
name:
28+
- ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*
29+
block_device_mappings:
30+
- device_name: /dev/sda1
31+
delete_on_termination: true
32+
volume_type: gp3
33+
volume_size: 30
34+
encrypted: true
35+
iops: null
36+
throughput: null
37+
kms_key_id: null
38+
snapshot_id: null
39+
runner_log_files:
40+
- log_group_name: syslog
41+
prefix_log_group: true
42+
file_path: /var/log/syslog
43+
log_stream_name: "{instance_id}"
44+
- log_group_name: user_data
45+
prefix_log_group: true
46+
file_path: /var/log/user-data.log
47+
log_stream_name: "{instance_id}/user_data"
48+
- log_group_name: runner
49+
prefix_log_group: true
50+
file_path: /opt/actions-runner/_diag/Runner_**.log
51+
log_stream_name: "{instance_id}/runner"
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
matcherConfig:
2+
exactMatch: false
3+
labelMatchers:
4+
- [ self-hosted, linux, x64, amazon ]
5+
fifo: true
6+
delay_webhook_event: 0
7+
runner_config:
8+
runner_os: linux
9+
runner_architecture: x64
10+
runner_extra_labels: amazon
11+
runner_name_prefix: amazon-x64_
12+
enable_ssm_on_runners: true
13+
instance_types:
14+
- m5ad.large
15+
- m5a.large
16+
runners_maximum_count: 1
17+
enable_ephemeral_runners: true
18+
create_service_linked_role_spot: true
19+
scale_down_schedule_expression: cron(* * * * ? *)
20+
runner_metadata_options:
21+
instance_metadata_tags: disabled
22+
http_endpoint: enabled
23+
http_tokens: optional
24+
http_put_response_hop_limit: 1
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
matcherConfig:
2+
exactMatch: true
3+
labelMatchers:
4+
- [self-hosted, windows, x64, servercore-2022]
5+
fifo: true
6+
delay_webhook_event: 5
7+
runner_config:
8+
runner_os: windows
9+
runner_architecture: x64
10+
runner_extra_labels: servercore-2022
11+
runner_name_prefix: servercore-2022-x64_
12+
enable_ssm_on_runners: true
13+
instance_types:
14+
- m5.large
15+
- c5.large
16+
runners_maximum_count: 1
17+
scale_down_schedule_expression: cron(* * * * ? *)
18+
runner_boot_time_in_minutes: 20
19+
ami_filter:
20+
name:
21+
- Windows_Server-2022-English-Core-ContainersLatest-*

0 commit comments

Comments
 (0)