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 Video Library
Refcards
Trend Reports

Events

View Events Video Library

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

Trending

  • The Hidden Cost of Overprivileged Tokens: Designing Messaging Platforms That Assume Compromise
  • Querying Without a Query Language
  • Designing API-First EMR Architectures in .NET: Enabling Modular Growth in Compliance-Driven Systems
  • Spec-Driven Integration: Turning API Sprawl Into a Governed Capability Fleet for AI
  1. DZone
  2. Software Design and Architecture
  3. Cloud Architecture
  4. CI/CD Using Google Cloud Build and Google Cloud Run — Part 1

CI/CD Using Google Cloud Build and Google Cloud Run — Part 1

Here in this article, I am demonstrating every step to deploy an application in Cloud Run using the pipeline.

By 
Kumar Shahi user avatar
Kumar Shahi
·
Sep. 23, 20 · Tutorial
Likes (5)
Comment
Save
Tweet
Share
8.6K Views

Join the DZone community and get the full member experience.

Join For Free

Description

Google cloud is one of the most popular cloud providers which offers a breadth of services to fulfill almost every cloud requirement. Google Cloud Build and Google Cloud Run are two services from google cloud to achieve build and deployment automation using pipelines.

CI/CD stands for Continuous Integration and Continuous Deployment of application in an automated way using DevOps automation tools.

Here in this article, I am demonstrating every step to deploy an application in Cloud Run using the pipeline.

Pre-requisites

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

Problem Statement

  • Clone a web application developed using python and flask
  • Create a docker image and publish to Google Cloud Registry
  • Develop a pipeline to build and deploy the application to GCP
  • Setup trigger on commit in Github repo to execute pipeline

Solution

1. Log in to your google cloud account. https://console.cloud.google.com/

google cloud platform

2. Create a project.  

This step is not mandatory but if you are using a trial account then its good to create everything in a project so that once the activity is done you can remove the project and save on billing.

From Left Panel, Open IAM, and Admin-> Manage Resources

google cloud platform

Click Create Project

google cloud platform

Enter the project name "gcb-demo" and hit the "Create" button.

gcb-demo

3. Activate cloud shell

activate cloud shell

4. Execute the below commands to clone application code

Shell
x
23
 
1
# Lists credentialed accounts
2
$ gcloud auth list
3
 
          
4
# List Cloud SDK properties for the currently active project
5
$ gcloud config list project
6
 
          
7
# Set PROJECT_ID environment variable
8
$ export PROJECT_ID=<project id displayed from previous command>
9
 
          
10
# Create a directory to keep our code
11
$ mkdir gcbdemo
12
 
          
13
# Change current directory to gcbdemo
14
$ cd gcbdemo
15
 
          
16
# Clone code from github repository
17
$ git clone https://github.com/KumarAbhishekShahi/gcbdemo-repo.git
18
 
          
19
# Change current diectory to gcbdemo-repo
20
$ cd gcbdemo-repo
21
 
          
22
# List files under gcbdemo-repo directory
23
$ ls


5. Execute the below commands to create, tag, publish, and run the docker image.

Shell
 




x


 
1
# Create a docker image named "hello-app" using contents from current directory
2
$ docker build -t hello-app .
3
 
          
4
# Tag image "hello-app" to gcr namespace
5
$ docker tag hello-app gcr.io/$PROJECT_ID/hello-app
6
 
          
7
# Push image to Google Container Repository
8
$ docker push gcr.io/$PROJECT_ID/hello-app
9
 
          
10
# Run hello-app in detached mode and map container port to host port
11
$ docker run -p 8080:8080 -d gcr.io/$PROJECT_ID/hello-app
12
 
          
13
# Test application URL and it should return <h3>Hello World!</h3>
14
$ curl http://localhost:8080
15
 
          



6. Create a pipeline now with the name cloudbuild.yaml in the current directory.

YAML
 




xxxxxxxxxx
1
22


 
1
steps:
2
 
          
3
#build docker container
4
- name: 'gcr.io/cloud-builders/docker'
5
  args: [ 'build', '-t', 'gcr.io/$PROJECT_ID/hello-app', '.']
6
  
7
#push container to container registry
8
- name: 'gcr.io/cloud-builders/docker'
9
  args: [ 'push', 'gcr.io/$PROJECT_ID/hello-app']
10
  
11
#deploy to cloud run
12
- name: 'gcr.io/cloud-builders/gcloud'
13
  args:
14
  - 'run'
15
  - 'deploy'
16
  - 'cloudrunservice'
17
  - '--image'
18
  - 'gcr.io/$PROJECT_ID/hello-app'
19
  - '--region'
20
  - 'us-central1'
21
  - '--platform'
22
  - 'managed'
23
  - '--allow-unauthenticated'
24
images:
25
  - 'gcr.io/$PROJECT_ID/hello-app'



7. You need to complete few configurations before running your pipeline

  • Enable Cloud Run API
    • Select API and Services from left panel --> Dashboard

getting started

  • Search for Cloud Run API and open it.

cloud run API

  • Click Enable to enable the API for this project

cloud run API

  • Enable Cloud Build API — Follow the same steps for Cloud Build API as above.
  • Allow permission to execute build and run commands.
    • From left panel open Cloud Build -> Settings

cloud builder

  • Enable Cloud Run Admin Role & It will ask to enable Service Accounts also -> Allow that too.

service account permissions

8. You can run this pipeline using the below command to perform a build operation which will generate a docker image. It will also perform deploy operations to the cloud run.

Shell
 




xxxxxxxxxx
1


 
1
$ gcloud builds submit --config cloudbuild.yaml



9. Check Cloud Build history.

Go to Cloud Build --> History from Left Panel

build history

10. Check storage created and your hosted image.

Go to Storage->Browse from Left Panel

storage browser

11. Check image in Cloud Registry.

Go to Cloud Registry from Left Panel and will show you a newly pushed image.

10. Check Cloud Run Service and deployment.

Go to Cloud Run from Left Panel, It will show newly created service. Open it

cloud run

It displays metrics for the service. Click on the URL displayed on top here to run the application.

URL display

11. Test Application.

Once you will click the URL in the previous step it will run your application and display like this.

cloudrunservice

Enjoy!

Next Steps

The next article in this series includes details of each step including the docker step, cloud build step, cloud run step, and various commands. Read the next article to make sure you understand the steps completely.

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.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

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

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook