Simplified Continuous Deployment on Google Cloud Platform

Timothy
Timothy
May 26 · 3 min read

If you’re new to Google Cloud Run, feel free to catch up by reading Deploying Containerized Application with Google Cloud Run.

Developers love to focus on writing codes while automating deployment processes. Google Cloud Platform provides such flexibility by providing tools to make deployment seem effortless.

In this article, our focus would be to integrate Cloud Build Trigger with Cloud Source Repositories, GitHub or Bitbucket and also setup continuous deployment to Google Cloud Run.

Our source codes can be found on GitHub here:

Continuous Deployment with Cloud Build

Cloud Build Triggers automatically builds our image whenever there are changes pushed to the build source. We could build our images either by using a Dockerfile or cloudbuild.yaml ( our build config can also be a JSON file).
In addition, Cloud Build offers 120 free build-minutes per day.

We’ll be using a cloudbuild.yaml to perform the following operations:

  • Build the Docker Image
  • Push the image to the Container Registry
  • Deploy a new revision to the Cloud Run service

Replace Project ID [projectz-239507] and Service Name [app] with your own values.

Elevate Service Account Permissions

We need to add the Cloud Run Admin and Service Account User roles to our Cloud Build Service Account [@cloudbuild.gserviceaccount.com].

Visit IAM and Admin Page and modify the Service Account as follows:

Setup Cloud Build Triggers

We’ll proceed to creating a trigger that listens to changes on a particular branch on our source codes and performs the operation in our cloudbuild.yaml file.

Visit the Cloud Build Triggers Page

Select your Source Code option and Continue.

Define your trigger, enter it’s Name, Trigger Type and Branch, Build Configuration ( as mentioned, we’ll be making use of the cloudbuild file).

Click on Create Trigger. You can monitor the Trigger on the History tab.

From this point on, anytime you push to your repository, you automatically trigger a build and a deployment to your Cloud Run service.
You can learn more about Cloud Build from here.

Thanks for reading through! Let me know if I missed any step, if something didn’t work out quite right for you or if this guide was helpful.

Originally Posted on Mercurie Blog

Timothy

Written by

Timothy

Campus Rep 🚩 @githubeducation | Software Engineer @DigitalMercurie I timz.tech | http://fullstackgcp.com

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade