Skip to content

☁️ Google Cloud Run

Cloud Run is a service in the Google Cloud Platform that allows you to deploy highly scalable containerized applications using your favorite language on a fully managed serverless platform. You can use Cloud Run to serve requests from your Dart Frog API to the internet. This will provide:

  • Fully managed autoscaling to handle any number of requests
  • Only pay for the computing resources you use, and pay nothing when your service isn’t being used
  • Automatic logging in Cloud Logging

Before you get started, if you don’t already have these, you’ll need to create:

Additionally, you’ll need the gcloud command line interface (CLI) installed on your computer.

Finally, you’ll want to log in to gcloud by running:

Terminal window
gcloud auth login

Simply run:

Terminal window
dart_frog build

This will create a /build directory with all the files needed to deploy your API.

In order to deploy to Cloud Run, you can run the following command:

Terminal window
gcloud run deploy [SERVICE_NAME] \
--source build \
--project=[PROJECT_ID] \
--region=[REGION] \
--allow-unauthenticated
  • [SERVICE_NAME]: The name of the Cloud Run service you want to create/update
  • [PROJECT_ID]: The ID of the Google Cloud project
  • [REGION]: The GCP region you wish to deploy to (ex: us-central1)

Running this command will do three things:

  • Upload the code in the /build directory
  • Build the Docker image in Cloud Build and upload it to Artifact Registry
  • Deploy the image to the specified Cloud Run service

Congratulations 🎉, you have successfully built and deployed your API to Cloud Run. You can now access your API at the Service URL that is printed in the last line of output.

Example:

Terminal window
$ gcloud run deploy hello --source build --allow-unauthenticated
Building using Dockerfile and deploying container to Cloud Run service [hello] in project [dart-demo] region [us-central1]
Building and deploying new service... Done.
Uploading sources...
Building Container... Logs are available at [https://console.cloud.google.com/cloud-build/builds/df7f07d1-d88b-4443-a2b1-bdfd3cdab15b?project=700116488077].
Creating Revision... Revision deployment finished. Waiting for health check to begin.
Routing traffic...
Setting IAM Policy...
Done.
Service [hello] revision [hello-00001-yen] has been deployed and is serving 100 percent of traffic.
Service URL: https://hello-gpua4upw6q-uc.a.run.app