Serverless CI/CD — Google Cloud Build

As you can see from my previous blogs I’m a big fan of continuous deployment. Generally I would look to utilise open source platforms to provide the tool to assist in build and deploying applications, tools such as Jenkins and in particular the Kubernetes plugin for Ephemeral container based build agents.

But…I’m also a big fan of allowing a business to focus on their core value proposition by leveraging platforms (PaaS or similar) where possible. Leveraging technology solutions means a business can focus their staff on the key functionality and have their operations team focus on managing the core of their platform, leaving Cloud providers to manage the rest.

CI/CD tools are one of those pieces of infrastructure that many organisations require (especially if they wish to review deployment quality or deployment cadence) yet managing those ‘internal feeling’ systems can take up some time for your SysAdmins / Operators / SRE staff.

During Google Cloud Next 2018, Google announced a number of products/features in their serverless offering. The first of the tools I decided to have a play with is Google Cloud Build.

The remainder of this article provides an running example of utilising Google Cloud Build for a NodeJS express application.

TL;DR — The accompanying GitHub repo for this article

Firstly I created a really standard NodeJS express application. For running unit tests I decided to utilise Jest.

This is the package.json for the application

Nothing special there.

Also for the application we don’t utilise any Google Cloud tooling for writing our application. Keeps our app nicely platform agnostic.

I’m a big fan of code defined build pipelines. Google Cloud Build is now different and utilises a file called cloudbuild.yaml — The cloudbuild.yaml file informs Google of the steps to build/test/deploy your application.

Here is the example of the initial build file for the Node app.

Pretty straight forward — we use a Google Cloud Build to install our dependencies then again use the npm cloud build to run our tests.

Then we can utilise the GCP command line to submit this build to Google Cloud.

gcloud builds submit --config cloudbuild.yaml .

NOTE: The above command assumes you have configured the GCP command line and target project. Also don’t worry if you haven’t enabled the Cloud Build API on your Cloud project because the command line will ask if you wish to enable it.

Once you’ve submitted your build you can visit the cloud console and see the logs of your build. Completely serverless builds and no build agents to monitor/maintain!

Of course manually submitting only gets you so far — if you are looking to automate you can of course write your own git hooks but GCP also offer Build Triggers allowing you to automatically trigger builds based upon Git changes.

Of course with all Cloud offerings they have an op-ex based expense — at time of writing Cloud Build offers 120 build-minutes free per day. Full pricing details

Just one more tool for us to consider for the applications we all develop and support.

Be interested to hear people’s thoughts on using a serverless CI/CD tool.