HanG321 Blog

Serverless Cloud Run Development: Challenge Lab

Provision the Qwiklabs environment

Task 1:

+-----------------+-----------------------------------+
|      FIELD      |               VALUE               |
+-----------------+-----------------------------------+
| Billing Image   | billing-staging-api:0.1           |
| Billing Service | public-billing-service            |
| Authentication  | unauthenticated                   |
| Code            | pet-theory/lab07/unit-api-billing |
+-----------------+-----------------------------------+

 

cd ~/<CODE>
gcloud builds submit \
--tag gcr.io/$GOOGLE_CLOUD_PROJECT/<BILLING_IMAGE>

 

gcloud run deploy <SERVICE> \
--image gcr.io/$GOOGLE_CLOUD_PROJECT/<BILLING_IMAGE> \
--<AUTHENTICATED>

 

Task 2:

+----------------+-------------------------------------------+
|     FIELD      |                   VALUE                   |
+----------------+-------------------------------------------+
| Image Name     | frontend-staging:0.1                      |
| Service Name   | frontend-staging-service                  |
| Authentication | unauthenticated                           |
| Code           | pet-theory/lab07/staging-frontend-billing |
+----------------+-------------------------------------------+

 

Task 3:

+----------------+--------------------------------------+
|     FIELD      |                VALUE                 |
+----------------+--------------------------------------+
| Image Name     | billing-staging-api:0.2              |
| Service Name   | private-billing-service              |
| Authentication | authenticated                        |
| Code           | pet-theory/lab07/staging-api-billing |
+----------------+--------------------------------------+

 

cd ~/<CODE>
gcloud beta run services delete public-billing-service

 

BILLING_SERVICE=private-billing-service
BILLING_URL=$(gcloud run services describe $BILLING_SERVICE \
  --format "value(status.URL)")
curl -X get -H "Authorization: Bearer $(gcloud auth print-identity-token)" $BILLING_URL

 

Task 4:

+-----------------+---------------------------+
|      FIELD      |           VALUE           |
+-----------------+---------------------------+
| Service Account | billing-service-sa        |
| Display Name    | Billing Service Cloud Run |
+-----------------+---------------------------+

 

gcloud iam service-accounts create <SERVICE_ACOUNT> --display-name "<DISPLAY_NAME>"

 

Task 5:

+-----------------+-----------------------------------+
|      FIELD      |               VALUE               |
+-----------------+-----------------------------------+
| Image Name      | billing-prod-api:0.1              |
| Service Name    | billing-prod-service              |
| Authentication  | authenticated                     |
| Code            | pet-theory/lab07/prod-api-billing |
| Service Account | billing-service-sa                |
+-----------------+-----------------------------------+

 

cd ~/<CODE>
## similar to task 3 build and deploy command above

 

gcloud run services add-iam-policy-binding <SERVICE_NAME> \
  --member=serviceAccount:<SERVICE_ACCOUNT>@$GOOGLE_CLOUD_PROJECT.iam.gserviceaccount.com \
  --role=roles/run.invoker

 

PROD_BILLING_SERVICE=private-billing-servicePROD_BILLING_URL=$(gcloud run services \
    describe $PROD_BILLING_SERVICE \
    --format "value(status.URL)")
curl -X get -H "Authorization: Bearer \
    $(gcloud auth print-identity-token)" \
    $PROD_BILLING_URL

 

Task 6:

+-----------------+-----------------------------------+
|      FIELD      |               VALUE               |
+-----------------+-----------------------------------+
| Service Account | frontend-service-sa               |
| Display Name    | Billing Service Cloud Run Invoker |
+-----------------+-----------------------------------+

 

Task 7:

+-----------------+----------------------------------------+
|      FIELD      |                 VALUE                  |
+-----------------+----------------------------------------+
| Image Name      | frontend-prod:0.1                      |
| Service Name    | frontend-prod-service                  |
| Authentication  | unauthenticated                        |
| Code            | pet-theory/lab07/prod-frontend-billing |
| Service Account | frontend-service-sa                    |
+-----------------+----------------------------------------+

 

cd ~/<CODE>
## similar to task 5 build and deploy command above

 

gcloud run services add-iam-policy-binding <SERVICE_NAME> \
  --member=serviceAccount:<SERVICE_ACCOUNT>@$GOOGLE_CLOUD_PROJECT.iam.gserviceaccount.com \
  --role=roles/run.invoker

 

Congratulations

Exit mobile version