Skip to content

Create a nest js api running as container in Google Cloud Run

Notifications You must be signed in to change notification settings

rockonsoft/nest-cloud-run

Repository files navigation

Nest Cloud Run

Runs a simple nest.js api in Google Cloud Run

Branches

All git branches are merged into master

  • rock/run-in-cloud - the basic nest app running with a default controller and a process.env dump
  • rock/set-env-from-deploy - set NODE_ENV to develop for local development and set it to production on Cloud Run
  • rock/firestore - add firebase usable from development environment and from Cloud Run

Build image and deploy to Cloud Run

$ gcloud builds submit --tag gcr.io/[PROJECT-ID]/nest-cloud-run
$ gcloud beta run deploy --image gcr.io/[PROJECT-ID]/nest-cloud-run --platform managed
  • To set environment variables during deployment:
$ gcloud beta run deploy --image gcr.io/[PROJECT-ID]/nest-cloud-run --platform managed -update-env-vars NODE_ENV=production

Firestore

  • Create service account
$ gcloud iam service-accounts create [username]
  • Set new account as owner
$ gcloud projects add-iam-policy-binding [PROJECT_ID] --member "serviceAccount:[NAME]@[PROJECT_ID].iam.gserviceaccount.com" --role "roles/owner"
  • Generate a key file:
$ gcloud iam service-accounts keys create [somefilename].json --iam-account [email protected]

Update config

The config service is updated to use the key file as specified in the .env file if the service is running in development. When this is deployed in cloud run, the key file and the .env file is not deployed, based on the .dockerignore file.

Firestore service and controller

Added a firestore service that initializes the firestore store and create objects in firestore. Create a contoller for users (could be any CRUD type) that on POST will create an object in firestore.

Nest

Installation

$ npm install

Running the app

# development
$ npm run start

# watch mode
$ npm run start:dev

# production mode
$ npm run start:prod

Test

# unit tests
$ npm run test

# e2e tests
$ npm run test:e2e

# test coverage
$ npm run test:cov

About

Create a nest js api running as container in Google Cloud Run

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published