Revolgy blog

Google container builder for Easy and Quick CD Pipeline

Written by Marek Bartík | July 23, 2018

I love Google Cloud Platform. I love Google Kubernetes Engine. And I love GitHub as well. But I need a quick CD pipeline for an easy automated app deployment.  I have an easy stateless php app running on nginx and php-fpm in Docker containers versioned in git on GitHub. And what I need is to deploy it quickly and cheap to GKE. I need the upper management to be able to deploy it themselves via press of a button so they can test / review the app. Public url for sharing the deployment with their colleagues / other managers / clients is necessary as well.

Setting up the whole Jenkins CI, gitlab-ci with runners or using some paid Pipeline as a service takes too much time, energy and money.

Here comes the Google Cloud Build (currently beta). Simply described the current state of the service (July 2018):

  • Cloud Build is a free (first 120 build-minutes per day) service available on Google Cloud Platform
  • Currently integrated with Cloud Source Repository, GitHub and Bitbucket
  • It supports trigger for git branches and tags
  • Build config can be none (just Dockerfile in the repo is enough) or Pipeline as a Code with cloudbuild.yaml file
  • Variable (and secrets) substitution
  • Suppose we have a GCP project with provisioned GKE cluster already
  • Open up Build triggers. It should be in Google console — Tools — Container Registry — Build triggers (but, you know, they change the UI like every week, so it might be somewhere else)

  • Link your GitHub account with GCP
  • Import your repo
  • Set the trigger
  • Choose the cloudbuild.yaml where you can define your CI/CD pipeline as a code.
  • It is ugly, I know. I needed a fast solution, not a pretty one.
  • I need to build two Docker images, from different Dockerfiles, push them to Google Container Registry, template kubernetes deployment manifests, deploy them on GKE (kubectl apply) and create an ingress resource for external http traffic.
  • After I push to the repo, the build is starts automatically.
I see the git commit and action which caused the trigger, pipeline steps, time they took, total time of the build, link to images in GCR. And log: All is immutable, I can easily rollback deployment to a tagged image with a commit id from git. I can Rebuild the build in Build history. Ingress DNS records are pushed to CloudFlare automatically.

The only small inconvenience was that I had to create my own deployment/service/ingress/whatever Kubernetes manifests and had to template them with sed. As Google Cloud Builder is in its beta version there is still space for improvement, but I am sure that colleagues from Google are working on it and will make necessary iterations soon enough. 

Check the source repo: https://github.com/bartimar/gke-test

EDIT: Check this amazing github repo of the one and only Kelsey Hightower with great tutorials on Google Cloud Builder: https://github.com/kelseyhightower/pipeline