Skip to content

Commit 5e1fdc0

Browse files
authored
feat: Support spot VM instance (#203)
1 parent 95d2b46 commit 5e1fdc0

File tree

9 files changed

+57
-17
lines changed

9 files changed

+57
-17
lines changed

modules/gh-runner-gke/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ This example shows how to deploy Self Hosted Runners on GKE that supports Docker
102102
| project\_id | The project id to deploy Github Runner cluster | `string` | n/a | yes |
103103
| region | The GCP region to deploy instances into | `string` | `"us-east4"` | no |
104104
| service\_account | Optional Service Account for the nodes | `string` | `""` | no |
105+
| spot | A boolean that represents whether the underlying node VMs are spot | `bool` | `false` | no |
105106
| subnet\_ip | IP range for the subnet | `string` | `"10.0.0.0/17"` | no |
106107
| subnet\_name | Name for the subnet | `string` | `"runner-subnet"` | no |
107108
| subnetwork\_project | The ID of the project in which the subnetwork belongs. If it is not provided, the project\_id is used. | `string` | `""` | no |

modules/gh-runner-gke/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ module "runner-cluster" {
7676
auto_upgrade = true
7777
machine_type = var.machine_type
7878
enable_private_nodes = var.enable_private_nodes
79+
spot = var.spot
7980
}
8081
]
8182
}

modules/gh-runner-gke/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,3 +189,9 @@ variable "enable_private_nodes" {
189189
description = "Whether nodes have internal IP addresses only."
190190
default = false
191191
}
192+
193+
variable "spot" {
194+
type = bool
195+
description = "A boolean that represents whether the underlying node VMs are spot"
196+
default = false
197+
}

modules/gh-runner-mig-container-vm/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ This example shows how to deploy a Self Hosted Runner on MIG Container VMs.
4141
| repo\_url | Repo URL for the Github Action | `string` | n/a | yes |
4242
| restart\_policy | The desired Docker restart policy for the runner image | `string` | `"Always"` | no |
4343
| service\_account | Service account email address | `string` | `""` | no |
44+
| spot | Provision a SPOT instance | `bool` | `false` | no |
45+
| spot\_instance\_termination\_action | Action to take when Compute Engine preempts a Spot VM. | `string` | `"STOP"` | no |
4446
| subnet\_ip | IP range for the subnet | `string` | `"10.10.10.0/24"` | no |
4547
| subnet\_name | Name for the subnet | `string` | `"gh-runner-subnet"` | no |
4648
| subnetwork\_project | The ID of the project in which the subnetwork belongs. If it is not provided, the project\_id is used. | `string` | `""` | no |

modules/gh-runner-mig-container-vm/main.tf

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -163,15 +163,17 @@ module "mig_template" {
163163
"https://www.googleapis.com/auth/cloud-platform",
164164
]
165165
}
166-
disk_size_gb = 100
167-
disk_type = "pd-ssd"
168-
auto_delete = true
169-
name_prefix = "gh-runner"
170-
source_image_family = "cos-stable"
171-
source_image_project = "cos-cloud"
172-
startup_script = "export TEST_ENV='hello'"
173-
source_image = reverse(split("/", module.gce-container.source_image))[0]
174-
metadata = merge(var.additional_metadata, { "gce-container-declaration" = module.gce-container.metadata_value })
166+
disk_size_gb = 100
167+
disk_type = "pd-ssd"
168+
auto_delete = true
169+
name_prefix = "gh-runner"
170+
source_image_family = "cos-stable"
171+
source_image_project = "cos-cloud"
172+
startup_script = "export TEST_ENV='hello'"
173+
source_image = reverse(split("/", module.gce-container.source_image))[0]
174+
spot = var.spot
175+
spot_instance_termination_action = var.spot_instance_termination_action
176+
metadata = merge(var.additional_metadata, { "gce-container-declaration" = module.gce-container.metadata_value })
175177
tags = [
176178
"gh-runner-vm"
177179
]

modules/gh-runner-mig-container-vm/variables.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,15 @@ variable "cooldown_period" {
119119
type = number
120120
default = 60
121121
}
122+
123+
variable "spot" {
124+
type = bool
125+
description = "Provision a SPOT instance"
126+
default = false
127+
}
128+
129+
variable "spot_instance_termination_action" {
130+
description = "Action to take when Compute Engine preempts a Spot VM."
131+
type = string
132+
default = "STOP"
133+
}

modules/gh-runner-mig-vm/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ This example shows how to deploy a MIG Self Hosted Runner with an image pre-bake
4848
| source\_image | Source disk image. If neither source\_image nor source\_image\_family is specified, defaults to the latest public CentOS image. | `string` | `""` | no |
4949
| source\_image\_family | Source image family. If neither source\_image nor source\_image\_family is specified, defaults to the latest public Ubuntu image. | `string` | `"ubuntu-1804-lts"` | no |
5050
| source\_image\_project | Project where the source image comes from | `string` | `"ubuntu-os-cloud"` | no |
51+
| spot | Provision a SPOT instance | `bool` | `false` | no |
52+
| spot\_instance\_termination\_action | Action to take when Compute Engine preempts a Spot VM. | `string` | `"STOP"` | no |
5153
| startup\_script | User startup script to run when instances spin up | `string` | `""` | no |
5254
| subnet\_ip | IP range for the subnet | `string` | `"10.10.10.0/24"` | no |
5355
| subnet\_name | Name for the subnet | `string` | `"gh-runner-subnet"` | no |

modules/gh-runner-mig-vm/main.tf

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,16 @@ module "mig_template" {
132132
"https://www.googleapis.com/auth/cloud-platform",
133133
]
134134
}
135-
disk_size_gb = 100
136-
disk_type = "pd-ssd"
137-
auto_delete = true
138-
name_prefix = "gh-runner"
139-
source_image_family = var.source_image_family
140-
source_image_project = var.source_image_project
141-
startup_script = local.startup_script
142-
source_image = var.source_image
135+
disk_size_gb = 100
136+
disk_type = "pd-ssd"
137+
auto_delete = true
138+
name_prefix = "gh-runner"
139+
source_image_family = var.source_image_family
140+
source_image_project = var.source_image_project
141+
startup_script = local.startup_script
142+
source_image = var.source_image
143+
spot = var.spot
144+
spot_instance_termination_action = var.spot_instance_termination_action
143145
metadata = merge({
144146
"secret-id" = google_secret_manager_secret_version.gh-secret-version.name
145147
}, {

modules/gh-runner-mig-vm/variables.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,3 +153,15 @@ variable "instance_tags" {
153153
description = "Additional tags to add to the instances"
154154
default = []
155155
}
156+
157+
variable "spot" {
158+
type = bool
159+
description = "Provision a SPOT instance"
160+
default = false
161+
}
162+
163+
variable "spot_instance_termination_action" {
164+
description = "Action to take when Compute Engine preempts a Spot VM."
165+
type = string
166+
default = "STOP"
167+
}

0 commit comments

Comments
 (0)