Site icon Learning & Doing

Serverless Firebase Development: Challenge Lab

firebase

“Serverless Firebase Development: Challenge Lab”

Solusi

Topics tested:

Task 1: Create a Firestore database

This task is super easy. In the Google Cloud Console,

  1. Navigate to Firestore.
  2. Select Native mode for this project.
  3. Choose nam5 (United States) as the location of your database.
  4. Click CREATE DATABASE.

Task 2: Populate the Database

git clone https://github.com/rosera/pet-theory.git
cd ~/pet-theory/lab06/firebase-import-csv/solution
npm install
node index.js netflix_titles_original.csv

After the records written to the database, go back to the Cloud Console and verify the Firebase Database is updated.

Task 3: Create a REST API

You will need to build and deploy the code in pet-theory/lab06/firebase-rest-api/solution-01 as a Cloud Run Service via Google Container Registry. Run the following in the Cloud Shell:

npm install

gcloud builds submit \
  --tag gcr.io/$GOOGLE_CLOUD_PROJECT/rest-api:0.1

gcloud beta run deploy netflix-dataset-service \
  --image gcr.io/$GOOGLE_CLOUD_PROJECT/rest-api:0.1 \
  --platform managed \
  --region us-central1 \
  --allow-unauthenticated

After the Cloud Run deployed, you can test the service by running the following:

SERVICE_URL=$(gcloud beta run services describe netflix-dataset-service --platform managed --region us-central1 --format="value(status.url)")

echo $SERVICE_URL

curl -X GET $SERVICE_URL

Task 4: Firestore API access

This time you have to repeat the previous task for revision 0.2 of the code. You can update the service by running the following:

cd ../solution-02
npm install

gcloud builds submit \
  --tag gcr.io/$GOOGLE_CLOUD_PROJECT/rest-api:0.2

gcloud beta run deploy netflix-dataset-service \
  --image gcr.io/$GOOGLE_CLOUD_PROJECT/rest-api:0.2 \
  --platform managed \
  --region us-central1 \
  --allow-unauthenticated

After the Cloud Run updated, you can test the service endpoint with /2019:

SERVICE_URL=$(gcloud beta run services describe netflix-dataset-service --platform managed --region us-central1 --format="value(status.url)")

echo $SERVICE_URL

curl -X GET $SERVICE_URL/2019

Task 5: Deploy the Staging Frontend

Next, go to the pet-theory/lab06/firebase-frontend directory. You will build and deploy the staging frontend in a similar way.

gcloud builds submit \
  --tag gcr.io/$GOOGLE_CLOUD_PROJECT/frontend-staging:0.1

gcloud beta run deploy frontend-staging-service \
  --image gcr.io/$GOOGLE_CLOUD_PROJECT/frontend-staging:0.1 \
  --platform managed \
  --region us-central1 \
  --allow-unauthenticated

Task 6: Deploy the Production Frontend

To deploy a production frontend, you need to configure the service endpoint in the public/app.js file by modifying the following:

npm install
   
gcloud builds submit \
  --tag gcr.io/$GOOGLE_CLOUD_PROJECT/frontend-production:0.1
   
gcloud beta run deploy frontend-production-service \
  --image gcr.io/$GOOGLE_CLOUD_PROJECT/frontend-production:0.1 \
  --platform managed \
  --region us-central1 \
  --allow-unauthenticated

Penutup

Sahabat Blog Learning & Doing demikianlah penjelasan mengenai Serverless Firebase Development: Challenge Lab. Semoga Bermanfaat . Sampai ketemu lagi di postingan berikut nya.

Exit mobile version