Google Cloud - Run

Google Cloud Run is a fully managed compute platform for deploying and scaling containerized applications.


Docker Files

Google Cloud Run requires the application to use docker, so add those two files to the backend folder.


FROM node:14
COPY . /app
RUN npm install
RUN npm run build
CMD ["node", "./dist/server.js"]



Google Cloud Project

Go to and create an account.

Create a new project for the production environment. To create a staging environment the steps are the same.

Enable billing

The project needs the billing enabled:

Google SDK

Install the

Sign in to your account calling gcloud auth login.


The first step is to build the image with Google Cloud Build.


  • PROJECT-ID: By your Google Cloud project ID.

  • APPLICATION-ID: By the name of your application.

gcloud builds submit --tag 

On your first try, you will receive an error warning you to enable the Google Build API, so please do it and try again.

After the image is built, you can deploy it to Google Cloud Run:

gcloud run deploy --image --platform managed --project PROJECT-ID

You'll be prompted to:

  • Enable the API: Select yes.

  • Region: Select the one you have the database hosted.

  • Allow unauthenticated invocations: Select yes.

Create deployment scripts

You may want to create a deployment script.


  "scripts": {
    "deploy:staging": "gcloud builds submit --tag --project PROJECT-ID-STAGING && gcloud run deploy backend --image --platform managed --project PROJECT-ID-STAGING --memory=2Gi --region us-central1",
    "deploy:production": "gcloud builds submit --tag --project PROJECT-ID-PRODUCTION && gcloud run deploy backend --image --platform managed --project PROJECT-ID-PRODUCTION --memory=2Gi --region us-central1"

Environment Variables

Go to the Google Cloud Run console.

Select the service you just deployed.

Click on Edit & Deploy a new Revision.

Go to variables and add the environment variables.

The environment variables are the same you set on the setup but related to production, with a few changes.



You DON'T need to specify the GOOGLE_CLOUD_PLATFORM_CREDENTIALS because you are deploying inside the Google Cloud platform. But you have to make sure the Compute Engine default service account contains the following permissions:

  • Service Account Token Creator

  • Storage Admin


Set this to your hosted frontend URL (if you have one already).


Set this one with the URL you received after the first deployment. Don't forget to add the /api suffix. It will be something like

Last updated