Set up a GCP VM build infrastructure
This topic describes how to set up a CI build infrastructure in Google Cloud Platform.
This topic describes how to set up a CI build infrastructure in Google Cloud Platform (GCP). To do this, you will create an Ubuntu VM and then install a Harness Delegate and Drone VM Runner on it. The runner creates VMs dynamically in response to CI build requests.
This is one of several CI build infrastructure options. For example, you can also set up a Kubernetes cluster build infrastructure.
The following diagram illustrates a CI build farm. The Harness Delegate communicates directly with your Harness instance. The VM Runner maintains a pool of VMs for running builds. When the delegate receives a build request, it forwards the request to the runner, which runs the build on an available VM.
Prepare the Google Cloud VM
These are the requirements to configure the Google Cloud VM. This is the primary VM where you will host your Harness Delegate and runner.
Log into the Google Cloud Console and launch a VM to host your Harness Delegate and runner.
To find images to use on Google Compute Engine, run
gcloud compute images list. Valid image references follow the format ofprojects/PROJECT/global/images/IMAGE. For example:projects/ubuntu-os-cloud/global/images/ubuntu-2204-jammy-v20250701.
Configure the VM to allow ingress on ports 22 and 9079.
SSH into the VM, if you haven't done so already.
Run
gcloud auth application-default loginto create anapplication_default_credentials.jsonfile at/home/$(whoami)/.config/gcloud.
Configure the Drone pool on the Google Cloud VM
The pool.yml file defines the VM spec and pool size for the VM instances used to run the pipeline. A pool is a group of instantiated VMs that are immediately available to run CI pipelines. You can configure multiple pools in pool.yml, such as a Windows VM pool and a Linux VM pool.
Create a
/runnerfolder on your Google Cloud VM andcdinto it:mkdir /runner cd /runnerCopy your
application_default_credentials.jsonfile into the/runnerfolder. You created this file when you prepared the Google Cloud VM.In the
/runnerfolder, create apool.ymlfile.Modify
pool.ymlas described in the following example and the Pool settings reference.
Example pool.yml
Pool settings reference
You can configure the following settings in your pool.yml file. You can also learn more in the Drone documentation for the Pool File and Google drivers.
user data example
Provide cloud-init data in either user_data_path or user_data if you need custom configuration. Refer to the user data examples for supported runtime environments.
Below is a sample pool.yml for GCP with user_data configuration:
name
String
name: windows_pool
Unique identifier of the pool. You will need to specify this pool name in Harness when you set up the CI stage build infrastructure.
pool
Integer
pool: 1
Warm pool size number. Denotes the number of VMs in ready state to be used by the runner.
limit
Integer
limit: 3
Maximum number of VMs the runner can create at any time. pool indicates the number of warm VMs, and the runner can create more VMs on demand up to the limit.
For example, assume pool: 3 and limit: 10. If the runner gets a request for 5 VMs, it immediately provisions the 3 warm VMs (from pool) and provisions 2 more, which are not warm and take time to initialize.
platform
Key-value pairs, strings
platform:
os: linux
arch: amd64
Specify VM platform operating system (os) and architecture (arch). variant is optional.
`account`: Provide `project_id` and `json_path`. `project_id` is your GCP project ID, and `json_path` is the full path and filename of your local Google credentials file.
`image`: The image type to use for the build VM.
`machine_type`: The google machine type. See About Machine Families in the Google Cloud docs.
`zone`: To minimize latency, specify the zone where the delegate is running.
`disk`: You can provide the `size` (as an integer representing GB) and `type` (as a string, such as `"pd-balanced"`)
|
Start the runner
SSH into your Google Cloud VM and run the following command to start the runner:
This command mounts the volume to the Docker container providing access to pool.yml and JSON credentials to authenticate with GCP. It also exposes port 3000 and passes arguments to the container.
You might need to modify the command to use sudo and specify the runner directory path, for example:
Install the delegate
Install a Harness Docker Delegate on your Google Cloud VM.
In Harness, go to Account Settings, select Account Resources, and then select Delegates.
You can also create delegates at the project scope. In your Harness project, select Project Settings, and then select Delegates.
Select New Delegate or Install Delegate.
Select Docker.
Enter a Delegate Name.
Copy the delegate install command and paste it in a text editor.
To the first line, add
--network host, and, if required,sudo. For example:SSH into your Google Cloud VM and run the delegate install command.
For more information about delegates and delegate installation, go to Delegate installation overview.
Verify connectivity
Verify that the delegate and runner containers are running correctly. You might need to wait a few minutes for both processes to start. You can run the following commands to check the process status:
In the Harness UI, verify that the delegate appears in the delegates list. It might take two or three minutes for the Delegates list to update. Make sure the Connectivity Status is Connected. If the Connectivity Status is Not Connected, make sure the Docker host can connect to
https://app.harness.io.
The delegate and runner are now installed, registered, and connected.
Specify build infrastructure
Configure your pipeline's Build (CI) stage to use your GCP VMs as build infrastructure.
In Harness, go to the CI pipeline that you want to use the GCP VM build infrastructure.
Select the Build stage, and then select the Infrastructure tab.
Select VMs.
Enter the Pool Name from your pool.yml.
Save the pipeline.
Delegate selectors with self-managed VM build infrastructures
Although you must install a delegate to use a self-managed VM build infrastructure, you can choose to use a different delegate for executions and cleanups in individual pipelines or stages. To do this, use pipeline-level delegate selectors or stage-level delegate selectors.
Delegate selections take precedence in the following order:
Stage
Pipeline
Platform (build machine delegate)
This means that if delegate selectors are present at the pipeline and stage levels, then these selections override the platform delegate, which is the delegate that you installed on your primary VM with the runner. If a stage has a stage-level delegate selector, then it uses that delegate. Stages that don't have stage-level delegate selectors use the pipeline-level selector, if present, or the platform delegate.
For example, assume you have a pipeline with three stages called alpha, beta, and gamma. If you specify a stage-level delegate selector on alpha and you don't specify a pipeline-level delegate selector, then alpha uses the stage-level delegate, and the other stages (beta and gamma) use the platform delegate.
Troubleshoot self-managed VM build infrastructure
Go to the CI Knowledge Base for a broader list of frequently asked questions and answers.
Last updated
Was this helpful?