Cloud Run Deployments with CI/CD

30 minutes
  • 4 Learning Objectives

About this Hands-on Lab

In this lab, we’ll configure a continuous deployment pipeline for Cloud Run using Cloud Build. We’ll set up Cloud Source Repositories and configure Cloud Build to automate our deployment pipeline. Then, we’ll commit changes to Git and observe the fully automated pipeline as it builds and deploys our new image into service. You should be familiar with the GCP console, Cloud Shell, and the basics of Git to perform this hands-on lab.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Enable APIs and Create the Git Repo
  1. Enable APIs for Cloud Run and Cloud Build.
  2. Create a Git repo in Cloud Source Repositories.
  3. Activate the Cloud Shell.
  4. Clone your empty repo into your Cloud Shell terminal.
Commit Application Code
  1. Add code for a functioning container that provides a web service on port 8080 (you can use the example Amazing App code as mentioned in the lab information).
  2. Use Git to add the new code to your repository and commit your changes.

Note: The first time you try to commit with Git, you will need to configure your default identity:

git config --global user.email "you@example.com"
git config --global user.name "Your Name"
Set Up Cloud Build
  1. Add a Cloud Build YAML configuration file to your repo. It must contain build steps that build the container, push it to GCR and deploy it to Cloud Run (with the correct options for region, platform and authentication). See https://cloud.google.com/build/docs/configuring-builds/create-basic-configuration for an example.
  2. Commit the changes.
Set Up Build Triggers
  1. Grant Cloud Run Admin and Service Account User roles to the Cloud Build service account (this can be done from the Cloud Run settings page).
  2. Add a build trigger to the repo with this configuration:
    • Event: Push to a branch
    • Branch: ^master$
    • Build configuration: Cloud Build configuration file
  3. Make a change to the application code.
  4. Commit the changes and observe the automated deployment.

Additional Resources

Log in to Google Cloud Platform by right-clicking Open Google Console and selecting the option to open it in a new private browser window. Then, sign in using the credentials provided on the lab page.

To complete this lab, you will need to build a working container that provides a web server. You can use the Amazing App container by following these instructions. Once you have accessed the lab environment, activate the Cloud Shell. Inside the shell, download this zip file:

wget https://github.com/linuxacademy/content-google-cloud-run-deep-dive/raw/master/amazingapp.zip

Inside the zip file are three folders — one for each version of the container. You can use any of the versions, but make sure to copy the files into your local Git repo when you reach that stage of the lab.

To help you write your cloudbuild.yaml file, refer to the fully managed example.

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?