Nest boilerplate with Typescript ๐ถ, Postgres ๐ฌ, TypeORM ๐and fully CI-CD with GitHub Action ๐โโ๏ธ and GKE ๐ณ
- Create a personal access token with
write:packages
scope here. - Add a secret
PAT
with above value
- 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
- Create cluster
gcloud container clusters create $GKE_CLUSTER --zone $GKE_ZONE --machine-type n1-standard-1
$ yarn install
# development
$ yarn start
# watch mode
$ yarn start:dev
# production mode
$ yarn start:prod
# unit tests
$ yarn test
# e2e tests
$ yarn start
$ yarn test:e2e
# test coverage
$ yarn test:cov
# 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