Table of Contents (🔎 Click to expand/collapse)
Quest Outline (🔎 Click to expand/collapse)
Level | Code | Name | Note |
---|---|---|---|
Fundamental | GSP642 |
Importing Data to a Firestore Database | EN |
Fundamental | GSP643 |
Build a Serverless Web App with Firebase | EN |
Fundamental | GSP747 |
Deploy a Hugo Website with Cloud Build and Firebase Pipeline | EN |
Fundamental | GSP174 |
Google Assistant: Build an Application with Dialogflow and Cloud Functions | EN |
Advanced | GSP344 |
Serverless Firebase Development: Challenge Lab |
This lab is recommended for students who are enrolled in the Serverless Firebase Development quest.
Prerequisites:
- Firestore
- Cloud Run
- Cloud Build
- Container Registry
In this lab you will create a frontend solution using a Rest API and Firestore database. Cloud Firestore is a NoSQL document database that is part of the Firebase platform where you can store, sync, and query data for your mobile and web apps at scale. Lab content is based on resolving a real world scenario through the use of Google Cloud serverless infrastructure.
You will build the following architecture:
Link to the project:
$ gcloud config set project $(gcloud projects list --format='value(PROJECT_ID)' --filter='qwiklabs-gcp')
Clone the repo:
$ git clone https://github.com/rosera/pet-theory.git
In this scenario you create a Firestore Database in Google Cloud. The high level architecture diagram below summarizes the general architecture.
Requirements:
Field | Value |
---|---|
Cloud Firestore | Native Mode |
Location | Nam5 (United States) |
To complete this section successfully, you are required to implement the following:
- Cloud Firestore Database
- Use Firestore Native Mode
- Add location Nam5 (United States)
- Click Navigation Menu > Firestore.
- Click SELECT NATIVE MODE.
- Select
nam5 (United States)
as the location. - Click CREATE DATABASE.
In this scenario, populate the database using test data. A high level architecture diagram below summarizes the general architecture.
To complete this section successfully, you are required to implement the following tasks:
- Use the sample code from
pet-theory/lab06/firebase-import-csv/solution
. - To import CSV use the node
pet-theory/lab06/firebase-import-csv/solution/index.js
.
# navigate to target folder and install dependencies
$ cd ~/pet-theory/lab06/firebase-import-csv/solution
$ npm install
# import csv file
$ node index.js netflix_titles_original.csv
In this scenario, create an example REST API. A high level architecture diagram below summarizes the general architecture.
To complete this section successfully, you are required to implement the following tasks:
- Access
pet-theory/lab06/firebase-rest-api/solution-01
- Build and Deploy the code to Google Container Registry
- Container Registry Image:
rest-api:0.1
- Container Registry Image:
- Deploy the image as a Cloud Run Service
- Cloud Run Service:
netflix-dataset-service
- Permission:
--allow-unauthenticated
- Cloud Run Service:
curl -X GET $SERVICE_URL
should respond with:{"status":"Netflix Dataset! Make a query."}
# navigate to target folder and install dependencies
$ cd ~/pet-theory/lab06/firebase-rest-api/solution-01
$ npm install
# build and deploy the code to Google Container Registry (gcr)
$ gcloud builds submit --tag="gcr.io/$GOOGLE_CLOUD_PROJECT/rest-api:0.1"
# deploy the image as a Cloud Run Service
$ gcloud run deploy netflix-dataset-service \
--region="us-central1" \
--image="gcr.io/$GOOGLE_CLOUD_PROJECT/rest-api:0.1" \
--allow-unauthenticated
# [Optional] check the resoponse
$ SERVICE_URL="<SERVICE_URL_OF_REST_API>"
$ curl -X GET $SERVICE_URL
In this scenario, deploy an updated revision of the code to access the Firestore DB. A high level architecture diagram below summarizes the general architecture.
To complete this section successfully, you are required to implement the following tasks:
- Access
pet-theory/lab06/firebase-rest-api/solution-02
. - Build the updated application
- Use Cloud Build to tag and deploy image revision to Container Registry
- Container Registry Image:
rest-api:0.2
- Container Registry Image:
- Deploy the new image as Cloud Run service
- Cloud Run Service:
netflix-dataset-service
- Permission:
--allow-unauthenticated
- Cloud Run Service:
curl -X GET $SERVICE_URL/2019
should respond with json dataset
# navigate to target folder and install dependencies
$ cd ~/pet-theory/lab06/firebase-rest-api/solution-02
$ npm install
# build and deploy the code to Google Container Registry (gcr)
$ gcloud builds submit --tag="gcr.io/$GOOGLE_CLOUD_PROJECT/rest-api:0.2"
# deploy the image as a Cloud Run Service
$ gcloud run deploy netflix-dataset-service \
--region="us-central1" \
--image="gcr.io/$GOOGLE_CLOUD_PROJECT/rest-api:0.2" \
--allow-unauthenticated
# [Optional] check the resoponse
$ SERVICE_URL="<SERVICE_URL_OF_NETFLIX_DATASET_SERVICE>"
$ curl -X GET $SERVICE_URL/2019
In this scenario, deploy the Staging Frontend. A high level architecture diagram below summarizes the general architecture.
To complete this section successfully, you are required to implement the following tasks:
- Access
pet-theory/lab06/firebase-frontend
- Build the frontend staging application
- Use Cloud Build to tag and deploy image revision to Container Registry
- Container Registry Image:
frontend-staging:0.1
- Container Registry Image:
- Deploy the new image as Cloud Run service
- Cloud Run Service:
frontend-staging-service
- Cloud Run Service:
- Frontend access to Rest API and Firestore Database
# edit the REST_API_SERVICE URL
$ cd ~/pet-theory/lab06/firebase-frontend/public
$ nano app.js
# navigate to target folder and install dependencies
$ cd ~/pet-theory/lab06/firebase-frontend
$ npm install
# build and deploy the code to Google Container Registry (gcr)
$ gcloud builds submit --tag="gcr.io/$GOOGLE_CLOUD_PROJECT/frontend-staging:0.1"
# deploy the image as a Cloud Run Service
$ gcloud run deploy frontend-staging-service \
--region="us-central1" \
--image="gcr.io/$GOOGLE_CLOUD_PROJECT/frontend-staging:0.1"
In this scenario, update the Staging Frontend to use the Firestore database. A high level architecture diagram below summarizes the general architecture.
To complete this section successfully, you are required to implement the following tasks:
- Access
pet-theory/lab06/firebase-frontend/public
- Update the frontend application i.e.
app.js
to use the REST API - Don't forget to append the year to the
SERVICE_URL
- Use Cloud Build to tag and deploy image revision to Container Registry
- Container Registry Image:
frontend-production:0.1
- Container Registry Image:
- Deploy the new image as Cloud Run service
- Cloud Run Service:
frontend-production-service
- Cloud Run Service:
- Frontend access to Rest API and Firestore Database
# navigate to target folder and install dependencies
$ cd ~/pet-theory/lab06/firebase-frontend
$ npm install
# build and deploy the code to Google Container Registry (gcr)
$ gcloud builds submit --tag="gcr.io/$GOOGLE_CLOUD_PROJECT/frontend-production:0.1"
# deploy the image as a Cloud Run Service
$ gcloud run deploy frontend-production-service \
--region="us-central1" \
--image="gcr.io/$GOOGLE_CLOUD_PROJECT/frontend-production:0.1"