Skip to content

Adapt for new registration flow, allow to specify runner image #15

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 5 commits into
base: master
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
23 changes: 2 additions & 21 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ resource "google_compute_instance" "ci_runner" {

boot_disk {
initialize_params {
image = "centos-cloud/centos-7"
image = var.ci_runner_image
size = var.ci_runner_disk_size
type = "pd-standard"
}
Expand All @@ -98,24 +98,6 @@ echo "Installing docker machine."
curl -L https://github.com/docker/machine/releases/download/v0.16.2/docker-machine-Linux-x86_64 -o /tmp/docker-machine
sudo install /tmp/docker-machine /usr/local/bin/docker-machine

echo "Verifying docker-machine and generating SSH keys ahead of time."
docker-machine create --driver google \
--google-project ${var.gcp_project} \
--google-machine-type f1-micro \
--google-zone ${var.gcp_zone} \
--google-service-account ${google_service_account.ci_worker.email} \
--google-scopes https://www.googleapis.com/auth/cloud-platform \
--google-disk-type pd-ssd \
--google-disk-size ${var.ci_worker_disk_size} \
--google-machine-image ubuntu-os-cloud/global/images/ubuntu-2004-focal-v20220419 \
--google-tags ${var.ci_worker_instance_tags} \
--google-use-internal-ip \
--google-network ${var.ci_runner_network} \
%{if var.ci_runner_subnetwork != ""}--google-subnetwork ${var.ci_runner_subnetwork}%{endif} \
${var.gcp_resource_prefix}-test-machine

docker-machine rm -y ${var.gcp_resource_prefix}-test-machine

echo "Setting GitLab concurrency"
sed -i "s/concurrent = .*/concurrent = ${var.ci_concurrency}/" /etc/gitlab-runner/config.toml

Expand All @@ -125,14 +107,13 @@ sudo gitlab-runner register -n \
--token ${var.ci_token} \
--executor "docker+machine" \
--docker-image "alpine:latest" \
--tag-list "${var.ci_runner_gitlab_tags}" \
--machine-machine-driver google \
--docker-privileged=${var.docker_privileged} \
--machine-idle-time ${var.ci_worker_idle_time} \
--machine-machine-name "${var.gcp_resource_prefix}-worker-%s" \
--machine-machine-options "google-project=${var.gcp_project}" \
--machine-machine-options "google-machine-type=${var.ci_worker_instance_type}" \
--machine-machine-options "google-machine-image=ubuntu-os-cloud/global/images/ubuntu-2004-focal-v20220419" \
--machine-machine-options "google-machine-image=${var.ci_worker_image}" \
--machine-machine-options "google-zone=${var.gcp_zone}" \
--machine-machine-options "google-service-account=${google_service_account.ci_worker.email}" \
--machine-machine-options "google-scopes=https://www.googleapis.com/auth/cloud-platform" \
Expand Down
14 changes: 14 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,25 @@ variable "ci_runner_disk_size" {
default = "20"
description = "The size of the persistent disk in GB."
}

variable "ci_runner_image" {
type = string
default = "centos-cloud/centos-stream-9"
description = "Name of the image for the runner"
}

variable "ci_worker_image" {
type = string
default = "ubuntu-os-cloud/global/images/ubuntu-2404-noble-amd64-v20241115"
description = "Name of the image for the worker"
}

variable "ci_runner_gitlab_name" {
type = string
default = ""
description = "Register the runner in GitLab using this name. If empty the value \"gcp-$${var.gcp_project}\" will be used."
}

variable "ci_runner_gitlab_tags" {
type = string
default = ""
Expand Down