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.
Successfully complete this lab by achieving the following learning objectives:
- Enable APIs and Create the Git Repo
- Enable APIs for Cloud Run and Cloud Build.
- Create a Git repo in Cloud Source Repositories.
- Activate the Cloud Shell.
- Clone your empty repo into your Cloud Shell terminal.
- Commit Application Code
- 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).
- 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 "email@example.com"
git config --global user.name "Your Name"
- Set Up Cloud Build
- 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.
- Commit the changes.
- Set Up Build Triggers
- 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).
- Add a build trigger to the repo with this configuration:
- Event: Push to a branch
- Source: cddemo
- Build configuration: Cloud Build configuration file
- Make a change to the application code.
- Commit the changes and observe the automated deployment.