This module creates a managed instance group of VM instances running gitlab-runner instances. Container Optimized OS images are used to simplify updates and management of the Docker host. gitlab-runner is installed into the VM host (not as a container) and registered to gitlab via cloud-init.
- Automatic gitlab-runner registration to gitlab.com
- Instances are preemptible by default, reducing cost by 70 to 80%.
- Automatically unregister on [preemption][preemption], reboot, shutdown to clean up.
- Managed instance group automatically restarts preempted instances.
- Health checking against the gitlab-runner Prometheus metrics endpoint.
- Unhealthy instances are terminated and re-created.
variable "project" {
description = "The instance group project"
}
variable "registration_token" {
description = "The Gitlab registration token used to register this runner, found via /settings/ci_cd in the GitLab Web UI"
}
module gitlab-runner-public {
name = "gitlab-runner-public"
source = "git::https://gitlab.com/openinfrastructure/code/terraform-google-gitlab-runner.git?ref=v0.1.0"
project = var.project
registration_token = var.registration_token
tag-list = ["docker", "gcp", "public"]
service_account_email = "gitlab-runner-public@${var.project}.iam.gserviceaccount.com"
machine_type = "f1-micro"
}
module gitlab-runner-private {
name = "gitlab-runner-private"
source = "git::https://gitlab.com/openinfrastructure/code/terraform-google-gitlab-runner.git?ref=v0.1.0"
project = var.project
registration_token = var.registration_token
tag-list = ["docker", "gcp", "private"]
service_account_email = "gitlab-runner-private@${var.project}.iam.gserviceaccount.com"
machine_type = "f1-micro"
}
Run terraform apply to update the instance template, then replace the instances with new ones using:
gcloud compute instance-groups managed rolling-action replace gitlab-runner
Container Optimizes OS uses systemd-journal for all logs. Log into an instance
and run sudo journalctl
to view system boot logs including cloud-init
execution steps.