Skip to content

openinfrastructure/terraform-google-gitlab-runner

Repository files navigation

Overview

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.

Features

  1. Automatic gitlab-runner registration to gitlab.com
  2. Instances are preemptible by default, reducing cost by 70 to 80%.
  3. Automatically unregister on [preemption][preemption], reboot, shutdown to clean up.
  4. Managed instance group automatically restarts preempted instances.
  5. Health checking against the gitlab-runner Prometheus metrics endpoint.
  6. Unhealthy instances are terminated and re-created.

Example Usage

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"
}

Operational Playbook

Update instances

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

Logs

cloud-init Logs

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.

About

Managed instance group of Gitlab runners on GCP

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published