Cloud Run Data in GCS and Firestore

30 minutes
  • 3 Learning Objectives

About this Hands-on Lab

In this lab, we’ll deploy a basic image gallery app with Cloud Run, and then refactor it so it uses Cloud Storage instead of local file system storage. Then, we’ll add the ability to add metadata to images, which we’ll store in the Cloud Firestore NoSQL database. You should be familiar with the GCP console and Cloud Shell to perform this hands-on lab. Some experience with Python will be beneficial.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Deploy the image-gallery App to Cloud Run
  1. Download the image-gallery code from the course GitHub repo.
  2. Build the container image from the 1-local-storage directory.
  3. Deploy the container to Cloud Run.
  4. Upload a picture of a dog (any dog will do).
Refactor the App to Use Cloud Storage
  1. Create a Cloud Storage bucket for image uploads.
  2. Refactor the code to use Cloud Storage instead of local storage. You can refer to the updated code in 2-cloud-storage, or just use the code in that directory instead of updating your own. Don’t forget to change the value of BUCKET_NAME.
  3. Rebuild the container and deploy the updated version of the app to Cloud Run, using gcloud run deploy options of --cpu=2 --max-instances=1 --memory=4Gi.
  4. Re-upload your dog picture.
  5. Deploy a new revision to force the instance to be removed and recreated. The image you uploaded should persist.
Deploy the Cloud Firestore Version of the App
  1. Go to the Cloud Firestore section in the GCP console, and enable Firestore in Native Mode. Choose the us-east1 region.
  2. Refactor the code to use Cloud Firestore in addition to Cloud Storage. You can refer to the updated code in 3-firestore, or just use the code in that directory instead of updating your own.
  3. Rebuild the container and deploy the updated version of the app to Cloud Run.
  4. Upload a dog picture with a description. You should see the image uploaded to Cloud Storage and a document created in Cloud Firestore.

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.

The code for this lab can be found in the image-gallery directory in this GitHub repo: https://github.com/ACloudGuru-Resources/content-google-cloud-run-deep-dive

Note: In the lab, use the gcloud run deploy options of --cpu=2 --max-instances=1 --memory=4Gi.

You need to enable some APIs to complete this lab. You can do this in one command from the Cloud Shell terminal:

gcloud services enable run.googleapis.com 
cloudbuild.googleapis.com

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?