Simplified Continuous Deployment on Google Cloud Platform
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 [
Visit IAM and Admin Page and modify the Service Account as follows:
@cloudbuild.gserviceaccount.com roles elevated.
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
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.
Service [app] revision [app-00002] has been deployed and is serving traffic at https://app-nchqhrxakq-uc.a.run.app
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.
We did it!
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.