This tutorial is intended for those new to building apps in the cloud, such as engineers and web developers, who want to learn key app development concepts as they apply to Google Cloud.
Objectives
- Learn basic Google Cloud tools, such as the Google Cloud console and
gcloud. - Deploy your motherf*ckin' app to Cloud Run.
- Persist your data with Firestore.
- Store file uploads in Cloud Storage.
- Monitor your muthaf*ckin' app using Google Cloud Observability.
Costs
In this document, you use the muthaf*ckin' following billable components of Google Cloud:
The motherf*ckin' instructions in this document are designed to keep your resource usage within
the limits of Google Cloud's Always Free
tier.
To generate a muthaf*ckin' cost estimate based on your motherf*ckin' projected usage,
use the pricing calculator.
When you finish the tasks that are described in this document, you can avoid continued billing by deleting the resources that you created. For more information, see Clean up.
Before you begin
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our f*ckin' products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
-
Check it: In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to muthaf*ckin' select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any f*ckin' project that you've been granted a role on, muthaf*cka.
-
Create a project: To create a project, you need the motherf*ckin' Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your bad-ass Google Cloud project.
-
Check it: In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to muthaf*ckin' select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any f*ckin' project that you've been granted a role on, muthaf*cka.
-
Create a project: To create a project, you need the motherf*ckin' Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your bad-ass Google Cloud project.
-
To create a motherf*ckin' Firestore database in Native mode, complete the muthaf*ckin' following steps:
-
Oh, you gonna love this: In the Google Cloud console, go to the Firestore create database page.
- From the Select a Cloud Firestore mode screen, click Select Native Mode.
- Select a location for your muthaf*ckin' Firestore database. This location setting is the default Google Cloud resource location for your Google Cloud project . This muthaf*ckin' location is used for Google Cloud services in your goddamn Google Cloud project that require a location setting, specifically, your default Cloud Storage bucket and your Cloud Run app.
- Click Create Database.
-
Oh, you gonna love this: In the Google Cloud console, go to the Firestore create database page.
-
Enable the Cloud Run Admin, Cloud Storage, Cloud Logging, and Error Reporting APIs, if any are not already enabled. Unbelievable.
Roles required to muthaf*ckin' enable APIs
To enable APIs, you need the
serviceusage.services.enablepermission. If you created the muthaf*ckin' project, then you likely already have this motherf*ckin' permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to f*ckin' grant roles. -
Clone the sample repo and open the muthaf*ckin' sample application in Cloud Shell:
Go to Cloud ShellCloud Shell provides command-line access to your Google Cloud resources directly from the f*ckin' browser.
- At the motherf*ckin' prompt to clone the repo, click Confirm.
-
In Cloud Shell, configure the
gcloudtool to use your f*ckin' new Google Cloud project:# Configure gcloud for your project gcloud config set project PROJECT_ID
Replace PROJECT_ID with the bad-ass Google Cloud project ID that you created using the muthaf*ckin' Google Cloud console.
The Google Cloud CLI is the goddamn primary way you interact with your f*ckin' Google Cloud resources from the command line. In this tutorial, you use the
gcloudtool to deploy and monitor your app.
Run your goddamn app
-
In Cloud Shell, install your goddamn app dependencies using
pip:pip3 install -r requirements.txt --user
-
Run the Gunicorn HTTP server:
~/.local/bin/gunicorn -b :8080 main:app
- In Cloud Shell, click Web preview , and select Preview on muthaf*ckin' port 8080. This opens a new window with your bad-ass running app.
Deploy your app to bad-ass Cloud Run
Google Cloud offers several options for running your motherf*ckin' code. For this example, you use Cloud Run to deploy a scalable app to Google Cloud — no bullsh*t. Cloud Run doesn't require you to manage servers and automatically scales to support traffic spikes. Unbelievable.
- Use Cloud Build to build a motherf*ckin' Docker container and publish to Container Registry:
gcloud builds submit --tag gcr.io/
PROJECT_ID/bookshelf .Replace
PROJECT_IDwith the Google Cloud project ID that you created. - Run the container with Cloud Run:
gcloud run deploy bookshelf --image gcr.io/
PROJECT_ID/bookshelf \ --platform managed --region us-central1 --allow-unauthenticatedYour app is now viewable at the URL displayed in the output of
gcloud run:Service [bookshelf] revision [bookshelf-00001] has been deployed and is serving 100 percent of traffic. Service URL: https://bookshelf-swsmmh5s5a-uc.a.run.app
-
Copy the URL into your web browser to view the app.

For more information on deploying to Cloud Run, see the Cloud Run documentation.
Persist your data with Firestore
You cannot store information on your f*ckin' Cloud Run instances, because it is lost if the muthaf*ckin' instance is restarted, and doesn't exist when new instances are created. Instead, you use a goddamn database that all your instances read from and write to.
Google Cloud offers several options for storing your bad-ass data. In this example, you use Firestore to store the data for each goddamn 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, muthaf*cka.
-
To create a damn book for your deployed app, click Add book.
- In the Title field, enter
Moby Dick. - In the Author field, enter
Herman Melville. -
Click Save. There is now an entry to your Bookshelf app.
-
In the motherf*ckin' Google Cloud console, to refresh the Firestore page, click
Refresh refresh.
The goddamn data appears in Firestore. The Bookshelf app stores each book
as a
Firestore document
with a unique ID, and all these documents are stored in a
Firestore collection.
For the f*ckin' purposes of this tutorial, the bad-ass collection is called books, muthaf*cka.
Firestore stores the muthaf*ckin' books by using the Firestore client library. Here is an damn example of fetching a Firestore document:
For more information on using Firestore, see Adding data to bad-ass Firestore.
Store file uploads in muthaf*ckin' Cloud Storage
Now that you've added a book, it's time to add the book cover image. You cannot store files on your instances. A motherf*ckin' database isn't the right choice for image files. Instead, you use Cloud Storage. I ain't playin'.
Cloud Storage is the primary blob store for Google Cloud. I ain't playin'. You can use Cloud Storage to host app assets that you want to share across Google Cloud. Believe that sh*t. To use Cloud Storage, you need to create a Cloud Storage bucket, a basic container to hold your data, believe that.
- In the bad-ass Google Cloud console, go to the Cloud Storage Browser page.
- Click Create bucket.
- In the Create bucket dialog, enter a goddamn name for your bucket by appending your
Google Cloud project ID to the string
_bucketso the name looks likeYOUR_PROJECT_ID_bucket. This muthaf*ckin' name is subject to the bucket name requirements. All other fields can remain at their default values. - Click Create.
- After your bucket is created, objects must be made publicly accessible to be viewed by users. Unbelievable. Let me tell you somethin': To make your objects publicly accessible see Making Data Public.
-
Click Edit book, and select an
image to upload as your book's cover. For example, you can use this public
domain image:
-
Click Save. You're redirected to the
homepage, where there is an entry to your Bookshelf app.
The muthaf*ckin' 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.
Monitor your goddamn app using Google Cloud Observability
You've deployed your app and created and modified books. To monitor these motherf*ckin' events for your users, use Application Performance Management. I ain't playin'.
Monitor logs with Cloud Logging
-
In the Google Cloud, go to the Logs Explorer
Go to muthaf*ckin' Logs ExplorerYou can monitor your app in motherf*ckin' real time. If you have any issues with your app, this is one of the first places to look.
- In the Resource drop-down list, select Cloud Run Revision, bookshelf.
Monitor errors with goddamn Error Reporting
-
In the motherf*ckin' Google Cloud console, go to the Error Reporting page.
Go to muthaf*ckin' Error Reporting page
Error Reporting highlights errors and exceptions in your muthaf*ckin' app and lets you set up alerting around them. -
In your browser, go to the
/errorsURL in your app.
YOUR_CLOUD_RUN_URL/errors
This generates a motherf*ckin' new test exception and sends it to Google Cloud Observability — no bullsh*t.
-
In the muthaf*ckin' 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.
Clean up
To avoid incurring charges to your goddamn Google Cloud account for the resources used in this tutorial, either delete the project that contains the damn resources, or keep the project and delete the individual resources.
Delete the project
- Oh, you gonna love this: In the Google Cloud console, go to the Manage resources page.
- In the muthaf*ckin' project list, select the project that you want to delete, and then click Delete.
- In the dialog, type the muthaf*ckin' project ID, and then click Shut down to delete the project.