DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
Securing Your Software Supply Chain with JFrog and Azure
Register Today

Trending

  • What Is JHipster?
  • Power BI Report by Pulling Data From SQL Tables
  • Breaking Down the Monolith
  • What to Pay Attention to as Automation Upends the Developer Experience

Trending

  • What Is JHipster?
  • Power BI Report by Pulling Data From SQL Tables
  • Breaking Down the Monolith
  • What to Pay Attention to as Automation Upends the Developer Experience
  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.

Kumar Shahi user avatar by
Kumar Shahi
CORE ·
Oct. 02, 20 · Tutorial
Like (4)
Save
Tweet
Share
3.81K 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

  • Google Cloud Account - Create a trial account here
  • Knowledge of CI/CD and Pipeline Concept
  • Github Account - Create a new account here
  • CI/CD using Google Cloud Build and Google Cloud Run - Part 1 

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

connect repo

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

select repo

Select Default-Push-Trigger and Repo name,

connect repo

Setting Up Continuous Deploy

Open Cloud Run from the left panel, 

cloud run

Click on Create Service

cloud run

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

service settings

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

set up

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

source repo

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

builders config

Click Create to create service

create

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,

cloud build

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,

build summary

Check Cloud Run Service and Deployment

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

demo-service

Click the URL listed to run the application

hello world

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.

Trending

  • What Is JHipster?
  • Power BI Report by Pulling Data From SQL Tables
  • Breaking Down the Monolith
  • What to Pay Attention to as Automation Upends the Developer Experience

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: