Question

Difficulty: MediumDeploying Serverless Applications with Cloud Run and Cloud Functions

An application developer needs to deploy a stateless HTTP web service named report-generator packaged as a container image to Google Cloud Run in the us-east1 region. The containerized application is built to listen on the port defined by the standard PORT environment variable injected by the Cloud Run container runtime at startup. Which command should the developer execute to deploy this container image from Artifact Registry to Cloud Run while adhering to Google Cloud serverless best practices?

  1. gcloud run deploy report-generator --image=us-east1-docker.pkg.dev/my-project/apps/report-generator:v1 --region=us-east1Answer
  2. B
    gcloud run deploy report-generator --image=us-east1-docker.pkg.dev/my-project/apps/report-generator:v1 --region=us-east1 --set-env-vars=PORT=80
  3. C
    gcloud functions deploy report-generator --image=us-east1-docker.pkg.dev/my-project/apps/report-generator:v1 --region=us-east1 --trigger-http
  4. D
    gcloud run deploy report-generator --image=us-east1-docker.pkg.dev/my-project/apps/report-generator:v1 --region=us-east1 --service-account=project-owner@my-project.iam.gserviceaccount.com

Answer

Execute the standard gcloud run deploy command specifying the service name, container image path in Artifact Registry, and target region.
The correct command uses `gcloud run deploy` to specify the service name, container image from Artifact Registry, and target region. Cloud Run automatically injects the `PORT` environment variable (defaulting to 8080) into the container container environment, allowing the application to start receiving HTTP requests cleanly without requiring custom port environment variable overrides.

Step-by-Step Solution

1
Identify the proper target serverless compute platform for pre-packaged container images.
Google Cloud Run is the appropriate serverless service for deploying container images.
Cloud Run natively supports any stateless container image that listens for web requests on the injected PORT environment variable.
2
Construct the gcloud CLI command with required deployment flags.
gcloud run deploy report-generator --image=us-east1-docker.pkg.dev/my-project/apps/report-generator:v1 --region=us-east1
Specifying the service name, container image location, and deployment region creates a revision of the Cloud Run service without modifying port environment variables or using improper deployment tools.

Key Concept

Cloud Run Container Deployment and Port Binding Rules
Rate this question