Go to Firestore create database
Enable the Cloud Run Admin, Cloud Storage, Cloud Logging, and Error Reporting APIs.
Clone the sample repo and open the sample application in Cloud Shell:
Go to Cloud Shell
Cloud Shell provides command-line access to your Google Cloud resources directly from the browser.
In Cloud Shell, configure the gcloud
tool to use your new Google Cloud project:
# Configure gcloud for your project gcloudconfigsetprojectPROJECT_ID
Replace PROJECT_ID with the Google Cloud project ID that you created using the Google Cloud console.
The Google Cloud CLI is the primary way you interact with your Google Cloud resources from the command line. In this tutorial, you use the gcloud
tool to deploy and monitor your app.
pip
:pip3 install -r requirements.txt --user
~/.local/bin/gunicorn -b :8080 main:app
Google Cloud offers several options for running your code. For this example, you use Cloud Run to deploy a scalable app to Google Cloud. Cloud Run doesn't require you to manage servers and automatically scales to support traffic spikes.
gcloud builds submit --tag gcr.io/PROJECT_ID
/bookshelf .
Replace PROJECT_ID
with the Google Cloud project ID that you created.
gcloud run deploy bookshelf --image gcr.io/PROJECT_ID
/bookshelf \ --platform managed --region us-central1 --allow-unauthenticated
Your app is now viewable at the URL displayed in the output of gcloud run
:
Service[bookshelf]revision[bookshelf-00001]hasbeendeployedandisserving100percentoftraffic. ServiceURL:https://bookshelf-swsmmh5s5a-uc.a.run.app
For more information on deploying to Cloud Run, see the Cloud Run documentation.
You cannot store information on your Cloud Run instances, because it is lost if the instance is restarted, and doesn't exist when new instances are created. Instead, you use a database that all your instances read from and write to.
Google Cloud offers several options for storing your data. In this example, you use Firestore to store the data for each book. Firestore is a fully managed, serverless, NoSQL document database that lets you store and query data. Firestore auto scales to meet your app needs, and scales to zero when you're not using it. Add your first book now.
To create a book for your deployed app, click Add book.
Moby Dick
.Herman Melville
.Click Save. There is now an entry to your Bookshelf app.
Firestore stores the books by using the Firestore Client Library. Here is an example of fetching a Firestore document:
For more information on using Firestore, see Adding data to Firestore.
Now that you've added a book, it's time to add the book cover image. You cannot store files on your instances. A database isn't the right choice for image files. Instead, you use Cloud Storage.
Cloud Storage is the primary blob store for Google Cloud. You can use Cloud Storage to host app assets that you want to share across Google Cloud. To use Cloud Storage, you need to create a Cloud Storage bucket, a basic container to hold your data.
_bucket
so the name looks like YOUR_PROJECT_ID_bucket
. This name is subject to the bucket name requirements. All other fields can remain at their default values. The bookshelf app sends uploaded files to Cloud Storage by using the Cloud Storage Client Library.
For more information on using Cloud Storage, see the Cloud Storage introduction.
You've deployed your app and created and modified books. To monitor these events for your users, use Application Performance Management.
In the Google Cloud, go to the Logs Explorer
Go to Logs ExplorerYou can monitor your app in real time. If you have any issues with your app, this is one of the first places to look.
/errors
URL in your app.YOUR_CLOUD_RUN_URL/errors
This generates a new test exception and sends it to Google Cloud Observability.
In the Google Cloud console, return to the Error Reporting page, and in a few moments the new error is visible. Click Auto Reload so you don't need to manually refresh the page.
To avoid incurring charges to your Google Cloud account for the resources used in this tutorial, either delete the project that contains the resources, or keep the project and delete the individual resources.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-04-17 UTC.