Deploying Dart APIs on Google Cloud Run

Deploying Dart APIs on Google Cloud Run

Jun 12, 2022

Step-1 ⟫ First, you need to install Docker if you haven’t already.

Docker will build your app into a container with a minimal operating system ready to run your server on any platform. We'll host it once it's all finished.

👉 Creating a Dart server app

After installing the Dart SDK, version 2.14 or later, use the dart command to create a new server app:

$ dart create -t server-shelf myserver

👉 Running the server with Docker Desktop

If you have Docker Desktop installed, you can build and run on your machine with the docker command:

$ docker build -t dart-server .
$ docker run -it --rm -p 8080:8080 --name myserver dart-server

When finished, you can stop the container using the name you provided:

$ docker kill myserver

Step-2 Deploying to Google

This section will walk you through the process of deploying an API on Google Cloud Run. Before you begin, you must link your Google account to your billing account.

👉 Setting up BillingClick to link billing account

Then select your billing account and click SET ACCOUNT (in case you haven’t created your billing already. You can do so by following Create a new Cloud Billing account

👉 Time to deploy this image(from above), to Cloud Run.

  • Make sure you have the Google Cloud SDK installed on your machine.

  • Authenticate your user account with the gcloud CLI using

$ gcloud auth login
  • List your projects and set the preferred project

// List your GCP projects
$ gcloud projects list

// Set your project
gcloud config set project \
'YOUR PROJECT ID'

Now we need to publish our image inside the Google Container Registry (storing our docker image in GCP) using

$ gcloud builds submit --tag gcr.io/[YOUR-PROJECT-ID]/hello_world
// Replace [YOUR-PROJECT-ID] with your project id
  • Finally, we deploy this container image to Cloud Run using

$ gcloud run deploy --image gcr.io/[YOUR-PROJECT-ID]/hello_world
// Replace [YOUR-PROJECT-ID] with your project id

Video Demo

Enjoy this post?

Buy Rahul Sharma a coffee

More from Rahul Sharma