Skip to content

Terraform module for GitLab CI runners deployed at GCP with focus on Node.js builds

Notifications You must be signed in to change notification settings

AckeeCZ/terraform-gcp-gitlab-runners

Repository files navigation

Ackee Node.js Optimized Gitlab CI Runners 🦄

Terraform module for GitLab CI runners deployed at GCP with focus on Node.js builds.

Why 🦄?

  • Autoscaling by working hours
  • Preemptible instances
  • Distributed cache using GCS (Google Cloud Storage)
  • Registry as a pull through cache for:
    • docker (Docker registry)
    • npm (Verdaccio)
  • NAT or Public IP setup
  • Highly customizable in general

First setup

After specifying gitlab_url, runner_token, project and optionally some other variables, run terraform. Initialization of the controller will take a while and then the infrastructure is ready (signalized with a newly registered runner in GitLab Runners Admin Area). It is then recommended to adjust the HW requirements (instance types), to balance between quick builds and willingness to pay for them. Our setup can be viewed in the example folder.

Requirements

Name Version
terraform >= 0.14

Providers

Name Version
google n/a
random n/a
template n/a

Modules

Name Source Version
cloud-nat terraform-google-modules/cloud-nat/google 2.0.0

Resources

Name Type
google_compute_address.outgoing_traffic_europe_west1 resource
google_compute_instance.gitlab_runner resource
google_project_iam_member.controller_iam resource
google_service_account.runner_controller resource
google_service_account.runner_instance resource
google_service_account_iam_member.controller_instance resource
google_service_account_key.runner_sa_key resource
google_storage_bucket.runner_cache resource
google_storage_bucket_iam_binding.runner_cache resource
random_string.random_suffix resource
template_file.runner_config data source

Inputs

Name Description Type Default Required
controller_disk_size The size of the persistent disk in GB for the controller string "100" no
controller_disk_type GCP disk type for controller string "pd-balanced" no
controller_gitlab_name Name of registered runner in GitLab string "GCP runner" no
controller_gitlab_tags List of runner's tags delimited with , string "cloud" no
controller_gitlab_untagged Register the runner to also execute GitLab jobs that are untagged. string "true" no
controller_image Image for controller string "ubuntu-os-cloud/ubuntu-2004-lts" no
controller_instance_type Instance type for controller, speed & power is not needed here string "e2-small" no
controller_permissions Roles needed for controller list(string)
[
"roles/compute.instanceAdmin.v1",
"roles/compute.networkAdmin",
"roles/compute.securityAdmin",
"roles/logging.logWriter"
]
no
docker_machine_version Version of docker machine for runners string "v0.16.2" no
enable_cloud_nat Use Cloud NAT instance instead of public IP addreses bool false no
gitlab_url GitLab URL where cloud runners are intended to be used string n/a yes
network GCP network for use string "default" no
project GCP project for cloud runners string n/a yes
region GCP region string "europe-west1" no
runner_cache_location GCS bucket location for runner cache string "EUROPE-WEST1" no
runner_concurrency The maximum number of summoned instances. number 12 no
runner_disk_size The size of the persistent disk in GB for summoned instances (higher number than needed for better IOPS) string "200" no
runner_docker_image Docker image to be used, for runners string "docker-stable" no
runner_idle_count_working_hours Always up instances during working hours number 4 no
runner_idle_time The maximum idle time for summoned instances before they went down number 60 no
runner_idle_time_working_hours The maximum idle time for summoned instances before they went down during working hours number 600 no
runner_instance_tags The GCP instance networking tags to apply string "gitlab-runner" no
runner_instance_type Runner instance type. Adjust it for build needs string "n2d-standard-2" no
runner_max_builds Each machine can handle up to 100 jobs in a row number 100 no
runner_mount_volumes Docker volume mounts list(string)
[
"/cache",
"/builds:/builds",
"/var/run/docker.sock:/var/run/docker.sock"
]
no
runner_token Registration token for runner obtained in GitLab string n/a yes
working_hours Working hours for autoscaling runners string "\"* * 8-18 * * mon-fri *\"" no
zone Zone for GCE instances string "europe-west1-c" no

Outputs

Name Description
runners_service_account n/a

About

Terraform module for GitLab CI runners deployed at GCP with focus on Node.js builds

Resources

Stars

Watchers

Forks

Packages

No packages published