Custom Gitlab CICD using Auto DevOps template + Add Cloud Build in GCP

Johanes Glenn
FAUN — Developer Community 🐾
4 min readJan 14, 2021

Hi everyone, this is an additional story from an earlier post that focuses on Gitlab CICD using Auto DevOps to deploy to GKE. Now the Auto DevOps in itself is awesome, especially for newcomers who may have a huge learning curve to understand how to actually create the CICD pipeline. Auto DevOps in itself is a template that we may use which they already implement many good things on the pipelines.

However, it is troublesome if we somehow have some customization in between, for example, how if I want to allow a process taken within Google Cloud Build and then store the container image in the Artifact Registry / Container Registry and also enable the vulnerable scanning process? This is the objective of today’s story, which is the idea to “add” process and the possibility to “remove” the auto DevOps template.

Below is my previous story around Gitlab and Auto DevOps

Adding Cloud Build on Auto DevOps Template:

To actually add the process then we need to understand that the Auto DevOps option is actually activated the pipeline using the Auto DevOps CI templates. We can see the entire template from the GitLab reference:

The template actually includes multiple other templates and allows Auto DevOps to do its job. If you did not want to make things from scratch (for eg. how if we did not want to define our own test stage) we can utilize the existing template and modify it as we see fit.

What I will do is to add a process after the test stage is completed, then we go and [build another image with Cloud Buildstore in GCRdo vulnerable scanning] → then we continue with the rest of Auto DevOps (or just create our own deployment to GKE through another Cloud Build config).

Gitlab CICD Stages
Adding “push to cloud build” stage

Steps:

Notes: these are not a guide but only an overly simplified concept to use Gitlab CICD with GCP’s Services.

[One] Follow the previous steps on building the project and integrate with GKE. Please use the previous story as a reference.

[Two] We need some information stored which includes: Service Accounts Keys, and also the Project ID variable stored in Setting → CICD →Variable.

[Three] Create .gitlab-ci.yml and copy the Auto DevOps template + add “push to cloud build” stage in between test and deploy. Also, don’t forget to add config.yaml for cloud build.

The main idea is to use cloud-sdk images and do gcloud commands, which we need the variables from earlier variables stored.

[Four] Let’s push it :)

We got the “Push to cloud build” stage running after the test is passed
Logs of that stage
Cloud Build logs
Image in GCR with Vulnerabilities scanning result

That’s it, we modified and added custom stages that we want on GCP, on that custom we can have more stages on our pipelines utilizing GCP integrated services.

👋 Join FAUN today and receive similar stories each week in your inbox! Get your weekly dose of the must-read tech stories, news, and tutorials.

Follow us on Twitter 🐦 and Facebook 👥 and Instagram 📷 and join our Facebook and Linkedin Groups 💬

If this post was helpful, please click the clap 👏 button below a few times to show your support for the author! ⬇

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Published in FAUN — Developer Community 🐾

We help developers learn and grow by keeping them up with what matters. 👉 www.faun.dev

Written by Johanes Glenn

Cloud Customer Engineer — Infrastructure Modernization @GoogleCloud. Stories are my own opinion. https://linktr.ee/alevz

No responses yet

What are your thoughts?