Created
March 14, 2021 03:51
-
-
Save ekoyudhi/b4a3e478babd379a9bb8951eb0f1a9bb to your computer and use it in GitHub Desktop.
Serverless Firebase Development: Challenge Lab
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gcloud config set project $(gcloud projects list --format='value(PROJECT_ID)' --filter='qwiklabs-gcp') | |
git clone https://github.com/rosera/pet-theory.git | |
# 1. Firestore Database Create | |
Go to Firestore > Select Naive Mode > Location: nam5 > Create Database | |
# 2. Firestore Database Populate | |
cd pet-theory/lab06/firebase-import-csv/solution | |
npm install | |
node index.js netflix_titles_original.csv | |
# 3. Cloud Build Rest API Staging | |
cd ~/pet-theory/lab06/firebase-rest-api/solution-01 | |
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 --allow-unauthenticated | |
# Choose 1 and us-central1 | |
# 4. Cloud Build Rest API Production | |
cd ~/pet-theory/lab06/firebase-rest-api/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 --allow-unauthenticated | |
# go to cloud run and click netflix-dataset-service then copy the url | |
SERVICE_URL=<copy url from your netflix-dataset-service> | |
curl -X GET $SERVICE_URL/2019 | |
# 5. Cloud Build Frontend Staging | |
cd ~/pet-theory/lab06/firebase-frontend/public | |
nano app.js # comment line 3 and uncomment line 4, insert your netflix-dataset-service url | |
npm install | |
cd ~/pet-theory/lab06/firebase-frontend | |
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 | |
# Choose 1 and us-central1 | |
# 6. Cloud Build Frontend Production | |
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 | |
# Choose 1 and us-central1 |
## MANUAL STEP
# 1. Firestore Database Create
# Go to Firestore > Select Naive Mode > Location: nam5 > Create Database
# then copy below to .sh file and change the REGION based on your specific lab requirements and fire it.
gcloud auth list
gcloud auth login
export REGION=us-east4 # Update top level region here.
export PROJECT_ID=$(gcloud config get-value project)
gcloud iam service-accounts create qwiklab \
--display-name "My Qwiklab Service Account"
gcloud projects add-iam-policy-binding ${PROJECT_ID} \
--member serviceAccount:qwiklab@${PROJECT_ID}.iam.gserviceaccount.com \
--role roles/datastore.owner
gcloud iam service-accounts keys create ~/key.json \
--iam-account qwiklab@${PROJECT_ID}.iam.gserviceaccount.com
export GOOGLE_APPLICATION_CREDENTIALS="/home/${USER}/key.json"
gcloud config set run/region $REGION
gcloud config set project $(gcloud projects list --format='value(PROJECT_ID)' --filter='qwiklabs-gcp')
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
cd ~/pet-theory/lab06/firebase-rest-api/solution-01
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 --allow-unauthenticated
cd ~/pet-theory/lab06/firebase-rest-api/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 --allow-unauthenticated
export SERVICE_URL=$(gcloud run services describe netflix-dataset-service --platform=managed --region=$REGION --format='value(status.url)')
curl -X GET $SERVICE_URL/2019
cd ~/pet-theory/lab06/firebase-frontend/public
nano app.js # comment line 3 and uncomment line 4, insert your netflix-dataset-service url
npm install
cd ~/pet-theory/lab06/firebase-frontend
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
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can use
SERVICE_URL=$(gcloud run services describe netflix-dataset-service --region=us-central1 --format "get(status.url)")