Automate “Cloud Run” Build & Deployment with Approval using “Cloud Build”

On August 18, 2021 there was a great announcement from Google Cloud Platform on Cloud Build Approvals allowing users to configure triggers that only execute a build when granted approval by a set of users.

We at Evonence were super excited about this feature and used it in one of our recent implementations where Five(5) Cloud Run Services were built & deployed fully in an automated manner using Cloud Build and additionally we added the Approval option for Production deployment.

Prerequisite 

You have an existing containerized Web application or use our below Hello world code in NodeJs from gist

The game starts now...

Make sure you have a GCP Project with Billing enabled and APIs like Cloud Source Repository, Cloud Build & Cloud Run, and so on are enabled

  1. Create a Cloud Source Repository

And add server.js, Dockerfile and cloudbuild_prod.yaml files into this new Cloud Source Repository by launching Cloud Shell and executing the gcloud source repos clone evonence-hello-world and make sure the structure is like this

Push the files to Source repository using git add cloudbuild_prod.yaml Dockerfile server.js && git commit -m "First commit" && git push

2. Goto Cloud Build Settings and add Cloud Run & Service Account User IAM role to  PROJECTNUMBER@cloudbuild.gserviceaccount.com service account

3. Create a Cloud Build Trigger with the following information and click on Create button

Once the trigger is configured try Running is it

which creates a container image and also deploys it to Cloud Run. Clicking on the URL of Cloud Run Service will give response like


4. Now, let's add Cloud Build Approval option by editing the Trigger and click on Save button

Now try running the trigger again 

And go to Cloud Build History 


Click on the Build number to Approve the build



Benefits

  1. Cloud is completely serverless and would be easy to create and tear down any build process on the fly

  2. Cloud Build provides first 120 builds-minutes per day totally free

Conclusion

Cloud Build enables you to configure triggers that do not immediately execute a build but instead mark a build as pending until approved. Building & Deploying any GCP Service will be easy using Cloud Build because it supports various Cloud Builder Images.












Previous
Previous

Cloud Run accessing Cloud SQL with Serverless VPC Connector

Next
Next

Evonence Achieves the Workspace Transformation Partner Specialization