☁️ 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
Prerequisites
Section titled “Prerequisites”Before you get started, if you don’t already have these, you’ll need to create:
- A free Google Account
- A Google Cloud Platform (GCP) Project
- A billing account connected to your GCP project
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:
gcloud auth loginDeploying
Section titled “Deploying”1. Build your API for production use
Section titled “1. Build your API for production use”Simply run:
dart_frog buildThis will create a /build directory with all the files needed to deploy your
API.
2. Deploy your API to Cloud Run
Section titled “2. Deploy your API to Cloud Run”In order to deploy to Cloud Run, you can run the following command:
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
/builddirectory - Build the Docker image in Cloud Build and upload it to Artifact Registry
- Deploy the image to the specified Cloud Run service
3. Enjoy your API on Cloud Run!
Section titled “3. Enjoy your API on Cloud Run!”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:
$ 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