Skip to content
/ nest-boilerplate Public template

NestJS boilerplate with Typescript ๐ŸŽถ, Postgres ๐Ÿฌ, TypeORM ๐ŸŽ‰and fully CI-CD with GitHub Action ๐Ÿƒโ€โ™‚๏ธ and GKE๐Ÿณ

Notifications You must be signed in to change notification settings

Notekunn/nest-boilerplate

Repository files navigation

Nest Logo TypeORM Logo PostgreSQL Logo Jest Logo Prettier Logo ESLint Logo Docker Logo

GitHub Actions Logo Kubernetes Logo CommitLint Logo Semantic Release Logo CommitLint Logo Fastify Logo

Description

Nest boilerplate with Typescript ๐ŸŽถ, Postgres ๐Ÿฌ, TypeORM ๐ŸŽ‰and fully CI-CD with GitHub Action ๐Ÿƒโ€โ™‚๏ธ and GKE ๐Ÿณ

Setup Github Action Secret

  • Create a personal access token with write:packages scope here.
  • Add a secret PAT with above value

Setup Google Cloud

  • Install Google Cloud CLI here
  • Setup Google Cloud CLI with gcloud init and create a project with billing account
  • Enable Container Registry API:
  gcloud services enable containerregistry.googleapis.com container.googleapis.com
  • Config environment variables:
  export GKE_PROJECT=$(gcloud config get-value project)
  export GKE_CLUSTER=nest-cluster
  export GKE_ZONE=asia-southeast1-a
  export SA_NAME=gke-sa
  export SA_EMAIL=${SA_NAME}@${GKE_PROJECT}.iam.gserviceaccount.com
  • Create a service account:
  gcloud iam service-accounts create $SA_NAME --display-name "GKE Service Account"
  • Add role to service account:
  gcloud projects add-iam-policy-binding $GKE_PROJECT --member serviceAccount:$SA_EMAIL --role roles/container.admin
  gcloud projects add-iam-policy-binding $GKE_PROJECT --member serviceAccount:$SA_EMAIL --role roles/storage.admin
  gcloud projects add-iam-policy-binding $GKE_PROJECT --member serviceAccount:$SA_EMAIL --role roles/container.clusterViewer
  gcloud projects add-iam-policy-binding $GKE_PROJECT --member serviceAccount:$SA_EMAIL --role roles/iam.serviceAccountTokenCreator
  • Export service account key:
  gcloud iam service-accounts keys create key.json --iam-account $SA_EMAIL
  export GKE_SA_KEY=$(cat key.json | base64)
  • Add GKE_PROJECT, GKE_CLUSTER, GKE_ZONE, GKE_SA_KEY, to Github Action Secret

Setup GKE

  • Create cluster
 gcloud container clusters create $GKE_CLUSTER --zone $GKE_ZONE --machine-type n1-standard-1

Installation

$ yarn install

Running the app

# development
$ yarn start

# watch mode
$ yarn start:dev

# production mode
$ yarn start:prod

Test

# unit tests
$ yarn test

# e2e tests
$ yarn start
$ yarn test:e2e

# test coverage
$ yarn test:cov

TypeORM

# generate migration
yarn migration:generate MigrationName
# or
yarn build && yarn typeorm migration:generate -p ./src/database/migrations/MigrationName

# run migration
yarn migration:run
  • Other commands:
# drop schema
yarn typeorm schema:drop

# create migration
yarn migration:create MigrationName

About

NestJS boilerplate with Typescript ๐ŸŽถ, Postgres ๐Ÿฌ, TypeORM ๐ŸŽ‰and fully CI-CD with GitHub Action ๐Ÿƒโ€โ™‚๏ธ and GKE๐Ÿณ

Resources

Stars

Watchers

Forks

Packages

No packages published