Skip to content

refactor to object config #4546

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: npalm/dynamic-ec2-types
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ Join our discord community via [this invite link](https://discord.gg/bxgXW8jJGh)
| <a name="input_create_service_linked_role_spot"></a> [create\_service\_linked\_role\_spot](#input\_create\_service\_linked\_role\_spot) | (optional) create the service linked role for spot instances that is required by the scale-up lambda. | `bool` | `false` | no |
| <a name="input_delay_webhook_event"></a> [delay\_webhook\_event](#input\_delay\_webhook\_event) | The number of seconds the event accepted by the webhook is invisible on the queue before the scale up lambda will receive the event. | `number` | `30` | no |
| <a name="input_disable_runner_autoupdate"></a> [disable\_runner\_autoupdate](#input\_disable\_runner\_autoupdate) | Disable the auto update of the github runner agent. Be aware there is a grace period of 30 days, see also the [GitHub article](https://github.blog/changelog/2022-02-01-github-actions-self-hosted-runners-can-now-disable-automatic-updates/) | `bool` | `false` | no |
| <a name="input_dynamic_ec2"></a> [dynamic\_ec2](#input\_dynamic\_ec2) | Configuration for dynamic EC2 instance types feature. | <pre>object({<br/> enable_types = bool<br/> workflow_label_type_prefix = string<br/> })</pre> | <pre>{<br/> "enable_types": false,<br/> "workflow_label_type_prefix": "ghr-ec2-"<br/>}</pre> | no |
| <a name="input_enable_ami_housekeeper"></a> [enable\_ami\_housekeeper](#input\_enable\_ami\_housekeeper) | Option to disable the lambda to clean up old AMIs. | `bool` | `false` | no |
| <a name="input_enable_cloudwatch_agent"></a> [enable\_cloudwatch\_agent](#input\_enable\_cloudwatch\_agent) | Enables the cloudwatch agent on the ec2 runner instances. The runner uses a default config that can be overridden via `cloudwatch_config`. | `bool` | `true` | no |
| <a name="input_enable_ephemeral_runners"></a> [enable\_ephemeral\_runners](#input\_enable\_ephemeral\_runners) | Enable ephemeral runners, runners will only be used once. | `bool` | `false` | no |
Expand Down
60 changes: 30 additions & 30 deletions examples/default/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/default/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ terraform output -raw webhook_secret

| Name | Version |
|------|---------|
| <a name="provider_random"></a> [random](#provider\_random) | 3.6.3 |
| <a name="provider_random"></a> [random](#provider\_random) | 3.7.1 |

## Modules

Expand Down
3 changes: 2 additions & 1 deletion examples/default/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ module "runners" {
webhook_secret = random_id.random.hex
}

enable_dynamic_ec2_types = true
# configure the block device mappings, default for Amazon Linux2
# block_device_mappings = [{
# device_name = "/dev/xvda"
Expand Down Expand Up @@ -98,7 +99,7 @@ module "runners" {
}

# Enable debug logging for the lambda functions
# log_level = "debug"
log_level = "debug"

# tracing_config = {
# mode = "Active"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,8 @@ export async function scaleUp(eventSource: string, payload: ActionRequestMessage
if (eventSource !== 'aws:sqs') throw Error('Cannot handle non-SQS events!');

const dynamicEc2TypesEnabled = yn(process.env.ENABLE_DYNAMIC_EC2_TYPES, { default: false });
const requestedInstanceType = payload.labels?.find(label => label.startsWith('ghr-ec2-'))?.replace('ghr-ec2-', '');
const labelPrefix = process.env.WORKFLOW_LABEL_TYPE_PREFIX || 'ghr-ec2-';
const requestedInstanceType = payload.labels?.find(label => label.startsWith(labelPrefix))?.replace(labelPrefix, '');

if (dynamicEc2TypesEnabled && requestedInstanceType) {
logger.info(`Dynamic EC2 instance type requested: ${requestedInstanceType}`);
Expand All @@ -261,7 +262,7 @@ export async function scaleUp(eventSource: string, payload: ActionRequestMessage
// Combine configured runner labels with dynamic EC2 instance type label if present
let runnerLabels = process.env.RUNNER_LABELS || '';
if (dynamicEc2TypesEnabled && requestedInstanceType) {
const ec2Label = `ghr-ec2-${requestedInstanceType}`;
const ec2Label = `${labelPrefix}${requestedInstanceType}`;
runnerLabels = runnerLabels ? `${runnerLabels},${ec2Label}` : ec2Label;
logger.debug(`Added dynamic EC2 instance type label: ${ec2Label} to runner config.`);
}
Expand Down
2 changes: 1 addition & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ module "runners" {
github_app_parameters = local.github_app_parameters
enable_organization_runners = var.enable_organization_runners
enable_ephemeral_runners = var.enable_ephemeral_runners
enable_dynamic_ec2_types = var.enable_dynamic_ec2_types
dynamic_ec2 = var.dynamic_ec2
enable_job_queued_check = var.enable_job_queued_check
enable_jit_config = var.enable_jit_config
enable_on_demand_failover_for_errors = var.enable_runner_on_demand_failover_for_errors
Expand Down
2 changes: 1 addition & 1 deletion modules/multi-runner/README.md

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions modules/multi-runner/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,13 @@ variable "multi_runner_config" {
disable_runner_autoupdate = optional(bool, false)
ebs_optimized = optional(bool, false)
enable_ephemeral_runners = optional(bool, false)
enable_dynamic_ec2_types = optional(bool, false)
dynamic_ec2 = optional(object({
enable_types = bool
workflow_label_type_prefix = string
}), {
enable_types = false
workflow_label_type_prefix = "ghr-ec2-"
})
enable_job_queued_check = optional(bool, null)
enable_on_demand_failover_for_errors = optional(list(string), [])
enable_organization_runners = optional(bool, false)
Expand Down Expand Up @@ -180,7 +186,7 @@ variable "multi_runner_config" {
disable_runner_autoupdate: "Disable the auto update of the github runner agent. Be aware there is a grace period of 30 days, see also the [GitHub article](https://github.blog/changelog/2022-02-01-github-actions-self-hosted-runners-can-now-disable-automatic-updates/)"
ebs_optimized: "The EC2 EBS optimized configuration."
enable_ephemeral_runners: "Enable ephemeral runners, runners will only be used once."
enable_dynamic_ec2_types: "Enable dynamic EC2 instance types based on workflow job labels. When enabled, jobs can request specific instance types via the 'gh-ec2-instance-type' label (e.g., 'gh-ec2-t3.large')."
dynamic_ec2: "Configuration for dynamic EC2 instance types feature. This object allows you to enable dynamic instance types and configure the label prefix used in workflows."
enable_job_queued_check: "(Optional) 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."
enable_on_demand_failover_for_errors: "Enable on-demand failover. For example to fall back to on demand when no spot capacity is available the variable can be set to `InsufficientInstanceCapacity`. When not defined the default behavior is to retry later."
enable_organization_runners: "Register runners to organization, instead of repo level"
Expand Down
1 change: 1 addition & 0 deletions modules/runners/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ yarn run dist
| <a name="input_create_service_linked_role_spot"></a> [create\_service\_linked\_role\_spot](#input\_create\_service\_linked\_role\_spot) | (optional) create the service linked role for spot instances that is required by the scale-up lambda. | `bool` | `false` | no |
| <a name="input_credit_specification"></a> [credit\_specification](#input\_credit\_specification) | The credit option for CPU usage of a T instance. Can be unset, "standard" or "unlimited". | `string` | `null` | no |
| <a name="input_disable_runner_autoupdate"></a> [disable\_runner\_autoupdate](#input\_disable\_runner\_autoupdate) | Disable the auto update of the github runner agent. Be aware there is a grace period of 30 days, see also the [GitHub article](https://github.blog/changelog/2022-02-01-github-actions-self-hosted-runners-can-now-disable-automatic-updates/) | `bool` | `false` | no |
| <a name="input_dynamic_ec2"></a> [dynamic\_ec2](#input\_dynamic\_ec2) | Configuration for dynamic EC2 instance types feature. | <pre>object({<br/> enable_types = bool<br/> workflow_label_type_prefix = string<br/> })</pre> | <pre>{<br/> "enable_types": false,<br/> "workflow_label_type_prefix": "ghr-ec2-"<br/>}</pre> | no |
| <a name="input_ebs_optimized"></a> [ebs\_optimized](#input\_ebs\_optimized) | The EC2 EBS optimized configuration. | `bool` | `false` | no |
| <a name="input_egress_rules"></a> [egress\_rules](#input\_egress\_rules) | List of egress rules for the GitHub runner instances. | <pre>list(object({<br/> cidr_blocks = list(string)<br/> ipv6_cidr_blocks = list(string)<br/> prefix_list_ids = list(string)<br/> from_port = number<br/> protocol = string<br/> security_groups = list(string)<br/> self = bool<br/> to_port = number<br/> description = string<br/> }))</pre> | <pre>[<br/> {<br/> "cidr_blocks": [<br/> "0.0.0.0/0"<br/> ],<br/> "description": null,<br/> "from_port": 0,<br/> "ipv6_cidr_blocks": [<br/> "::/0"<br/> ],<br/> "prefix_list_ids": null,<br/> "protocol": "-1",<br/> "security_groups": null,<br/> "self": null,<br/> "to_port": 0<br/> }<br/>]</pre> | no |
| <a name="input_enable_cloudwatch_agent"></a> [enable\_cloudwatch\_agent](#input\_enable\_cloudwatch\_agent) | Enabling the cloudwatch agent on the ec2 runner instances, the runner contains default config. Configuration can be overridden via `cloudwatch_config`. | `bool` | `true` | no |
Expand Down
3 changes: 2 additions & 1 deletion modules/runners/scale-up.tf
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ resource "aws_lambda_function" "scale_up" {
AMI_ID_SSM_PARAMETER_NAME = var.ami_id_ssm_parameter_name
DISABLE_RUNNER_AUTOUPDATE = var.disable_runner_autoupdate
ENABLE_EPHEMERAL_RUNNERS = var.enable_ephemeral_runners
ENABLE_DYNAMIC_EC2_TYPES = var.enable_dynamic_ec2_types
ENABLE_DYNAMIC_EC2_TYPES = var.dynamic_ec2.enable_types
WORKFLOW_LABEL_TYPE_PREFIX = var.dynamic_ec2.workflow_label_type_prefix
ENABLE_JIT_CONFIG = var.enable_jit_config
ENABLE_JOB_QUEUED_CHECK = local.enable_job_queued_check
ENABLE_METRIC_GITHUB_APP_RATE_LIMIT = var.metrics.enable && var.metrics.metric.enable_github_app_rate_limit
Expand Down
14 changes: 10 additions & 4 deletions modules/runners/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -526,10 +526,16 @@ variable "enable_ephemeral_runners" {
default = false
}

variable "enable_dynamic_ec2_types" {
description = "Enable dynamic EC2 instance types based on workflow job labels. When enabled, jobs can request specific instance types via the 'gh:ec2:instance-type' label."
type = bool
default = false
variable "dynamic_ec2" {
description = "Configuration for dynamic EC2 instance types feature."
type = object({
enable_types = bool
workflow_label_type_prefix = string
})
default = {
enable_types = false
workflow_label_type_prefix = "ghr-ec2-"
}
}

variable "enable_job_queued_check" {
Expand Down
14 changes: 10 additions & 4 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -647,10 +647,16 @@ variable "enable_ephemeral_runners" {
default = false
}

variable "enable_dynamic_ec2_types" {
description = "Enable dynamic EC2 instance types based on workflow job labels. When enabled, jobs can request specific instance types via the 'gh-ec2-instance-type' label (e.g., 'gh-ec2-t3.large')."
type = bool
default = false
variable "dynamic_ec2" {
description = "Configuration for dynamic EC2 instance types feature."
type = object({
enable_types = bool
workflow_label_type_prefix = string
})
default = {
enable_types = false
workflow_label_type_prefix = "ghr-ec2-"
}
}

variable "enable_job_queued_check" {
Expand Down
Loading