VOOZH about

URL: https://dzone.com/articles/cicd-using-google-cloud-build-and-google-cloud-run-1

โ‡ฑ CI/CD Using Google Cloud Build and Google Cloud Run โ€” Part 2


Related

  1. DZone
  2. Software Design and Architecture
  3. Cloud Architecture
  4. CI/CD Using Google Cloud Build and Google Cloud Run โ€” Part 2

CI/CD Using Google Cloud Build and Google Cloud Run โ€” Part 2

In this article, I have covered steps to set up triggers on the Github repo which will run cloud build and cloud run to deploy the image and run respectively.

By Oct. 02, 20 ยท Tutorial
Likes
Comment
Save
4.5K Views

Join the DZone community and get the full member experience.

Join For Free

Description

This article is in continuation of CI/CD using Google Cloud Build and Google Cloud Run - Part 1 where I have discussed steps to set up a pipeline to build and deploy docker image using gcloud commands to Google Cloud Build and Google Cloud Run.

In this article, I have covered steps to set up triggers on the Github repo which will run cloud build and cloud run to deploy the image and run respectively. I will also explain the commands and build files used in the previous article.

Pre-Requisites

Problem Statement

  • Explain build file from the previous post
  • Setup a build pipeline using Google Cloud Build
  • Setup a deployment pipeline using Google Cloud Run
  • Validate deployment
  • Check build history, log, deployment service

Solution

Description of Build File

In step 6 of the previous article, I have created a file "cloud build.YAML"

YAML




x


1
steps:
2
3
#This command is calling docker image from Google Container Repo "gcr.io/cloud-builders/docker"
4
#in arguments it is passing "build -t"
5
#and image name = gcr.io/$PROJECT_ID/hello-app
6
#and this image is built using contents from current directory "."
7
- name: 'gcr.io/cloud-builders/docker'
8
 args: [ 'build', '-t', 'gcr.io/$PROJECT_ID/hello-app', '.']
9

 
10
#This command is calling docker image from Google Container Repo "gcr.io/cloud-builders/docker"
11
#in arguments it is calling "push" action
12
#and passing image name = gcr.io/$PROJECT_ID/hello-app
13
#which pushes image to GCR
14
- name: 'gcr.io/cloud-builders/docker'
15
 args: [ 'push', 'gcr.io/$PROJECT_ID/hello-app']
16
17
#This command is calling docker image from Google Container Repo "gcr.io/cloud-builders/docker"
18
#in arguments it is calling cloud run with deploy action
19
#and passing service name = cloudrunservice
20
#and image name = gcr.io/$PROJECT_ID/hello-app 
21
#This image should be there in GCR
22
#next argument passes region = 'us-central1' where it has to be deployed
23
#platform is managed and it allows unauthenticated access
24
- name: 'gcr.io/cloud-builders/gcloud'
25
 args:
26
 - 'run'
27
 - 'deploy'
28
 - 'cloudrunservice'
29
 - '--image'
30
 - 'gcr.io/$PROJECT_ID/hello-app'
31
 - '--region'
32
 - 'us-central1'
33
 - '--platform'
34
 - 'managed'
35
 - '--allow-unauthenticated'
36
images:
37
 - 'gcr.io/$PROJECT_ID/hello-app'



Setting Up Continuous Build

Follow Step 1 and Step 2 from the previous article.

Fork repo 

https://github.com/KumarAbhishekShahi/gcbdemo-repo.git

Select Cloud Build from Left Panel. On Cloud Build Screen, Select Triggers from Left Panel, Click Connect Repository.

Select Github as source repository, Click Continue

Authenticate for Github and then Select Repo from the list and click Connect Repository

Select Default-Push-Trigger and Repo name,

Setting Up Continuous Deploy

Open Cloud Run from the left panel, 

Click on Create Service

Specify Service Name and Authentication as allow unauthenticated invocations. Leave everything else as default and click Next.

Select Continuous deploy new revisions from a source repository and click on a setup with cloud build.

Specify Source Repository Provider as Github and authenticate. After authentication, select your repo from the second drop-down. Click Next.

Specify Build Configuration - Branch = Master and Build Type = Dockerfile and click Save

Click Create to create service

Run Pipeline To Build and Deploy

Go to Github Repo you have configured, modify any file and commit. It will trigger build and deploy.

Check Build History

Open cloud build from the left panel, select history from popup,

Check Build Steps and Build Log

Click on any of the builds from the previous step, it will list down steps from the build file and their logs,

Check Cloud Run Service and Deployment

Open Cloud Run from the left panel, select the service you want to see,

Click the URL listed to run the application

Enjoy!!

I hope you liked this step by step article for beginners. Please drop me a note in the comments with your feedback and any questions you have. Thank you so much for reading and learning!

Continuous Integration/Deployment Cloud Google (verb)

Opinions expressed by DZone contributors are their own.

Related

  • Google Cloud AI Agents With Gemini 3: Building Multi-Agent Systems That Actually Work
  • TPU vs GPU: Real-World Performance Testing for LLM Training on Google Cloud
  • Orchestrating Retail-Scale Data on Google Cloud
  • Deploying a Serverless Application on Google Cloud

Partner Resources

ร—

Comments

The likes didn't load as expected. Please refresh the page and try again.

Let's be friends: