GitLab CI Runners on Google Cloud - The Easy Way

2 minute read.

Af­ter spend­ing quite some time op­ti­miz­ing dock­er im­ages and build times on a se­mi-large C++ project, the 1 vCPU + 2.75 Gib RAM run­ners still took 7+ min­utes to build. Times 3-5 stages–that’s quite in­hibitive to pro­duc­tiv­i­ty.

Fi­nal re­sort: Up­grade the hard­ware.

There are a lot of tu­to­ri­als on how to set up Git­Lab CI run­ners on var­i­ous cloud in­fra­struc­ture providers, but I have one big prob­lem:

I am a cloud noob and I just want my C++ builds to go faster on Git­Lab CI!

Luck­i­ly there’s a some­thing called “In­fra­struc­ture as Code” (IaC), which al­lows shar­ing the amaz­ing work oth­er smart an skilled peo­ple have done pre­vi­ous­ly rather than strug­gling through an out­dat­ed tu­to­ri­al/step-by-step guide, just to fig­ure out you need to do it all again, since you messed some­thing up in the third step.

Ter­raform to the Res­cue

Ter­raform is a frame­work for IaC. It al­lows defin­ing the spec­i­fi­ca­tion of your cloud in­fra­struc­ture in text to the have it ap­plied to some in­fra­struc­ture ser­vice, in this case Google Cloud Plat­form (GCP).

I found ter­raform-google-git­lab-run­ner.

Set up

Find the project’s in­struc­tions here.

It’s fair­ly sim­ple and the com­mands a straight for­ward, you can eas­i­ly read it and find con­fig­u­ra­tion for the parts you need to tai­lor to your need.

  • In­stall Ter­raform and Google Cloud CLI, lo­gin is straight for­ward through Google
  • Make sure to set the projects full name your-project-123456, oth­er­wise it will er­ror out with 403 unau­tho­rized
  • Buck­et names are unique across the en­tire GCP uni­verse, you have to con­fig­ure a dif­fer­ent one in ex­am­ples/stan­dard/
  • Make sure that the zone you choose sup­ports the work­er in­stance type (some ma­chine types are on­ly sup­port­ed in some re­gions)
  • To de­bug the run­ner, you can SSH via the GCP web con­sole (no auth re­quired, it just works). su­do git­lab-run­ner stop && su­do git­lab-run­ner run will give you the full out­put while you start a job in Git­Lab.


With that, I was able to re­duce the build time by 60%, ex­pect­ing around ~50$/mo for about 10-20 runs per day of a pipe­line with 20 x 7 min (now 3 min) jobs. (Might up­date this once I have the ex­act num­ber.)

Thanos power from 8 x 3 GHz + 16 GB runners on Gitlab CI