Skip to content

Skeleton of a NodeJS backend, using NestJS + GraphQL + NATS + Microservices + Docker + CI/CD + automated deployments with GitHub Actions using Kubernetes, Helm and AWS EKS.

greg-md/node-skeleton

Repository files navigation

Node Skeleton

Maintainability Test Coverage Known Vulnerabilities Quality Gate Status

Skeleton of a NodeJS backend, using NestJS + GraphQL + NATS + Microservices + Docker + CI/CD + automated deployments with GitHub Actions using Kubernetes, Helm and AWS EKS.

The code is following Domain-Driven Design (DDD).

Useful Documentation:

What has been done to the default app:

  • npm i -g @nestjs/cli
  • nest new node-skeleton
  • cd node-skeleton
  • nest generate app micro
  • npm i nestjs/platform-fastify
  • npm remove @nestjs/platform-express @types/express supertest @types/supertest
  • npm i @nestjs/microservices
  • npm i nats
  • npm i sinon
  • npm i @nestjs/config
  • npm i @nestjs/graphql graphql-tools graphql apollo-server-fastify @moonwalker/graphql-nats-subscriptions
  • npm i winston colors

GitHub Repository Secrets

CC_TEST_REPORTER_ID # CodeClimate Code Coverage Reporter ID
AWS_ACCESS_KEY_ID # AWS Access Key ID
AWS_SECRET_ACCESS_KEY # AWS Access Key Secret
KUBE_CONFIG_DATA # cat $HOME/.kube/eksctl/clusters/skeleton | base64

Table of Contents

Local Run

Using Docker:

docker-compose up

Build & Deploy

You can build & deploy out of the box to local minikube or to AWS EKS using Kubernetes.

Pre Requirements

Install kubectl;

Install Helm;

Minikube

Install minikube;

Start minikube:

minikube start

AWS ECR

Install and configure AWS CLI;

Install eksctl;

Create AWS Cluster:

eksctl create cluster -f ./build-deploy/cluster/skeleton.yaml --auto-kubeconfig

Scale Cluster if needed:

eksctl scale nodegroup --cluster=skeleton --nodes=4 --name=skeleton-nodes

Tip:

Use --kubeconfig ~/.kube/eksctl/clusters/skeleton flag to use AWS EKS with kubectl or helm.

Build

Minikube

Use the minikube docker deamon to build the image:

eval $(minikube docker-env)

Build images:

  • docker build -t skeleton/api --target production-api .
  • docker build -t skeleton/micro --target production-micro .

AWS ECR

Deploy

Minikube

helm upgrade nats ./build-deploy/helm/nats --install --wait
helm upgrade micro ./build-deploy/helm/micro --install --wait
helm upgrade api ./build-deploy/helm/api --install --wait

Explose API:

minikube service api-service

AWS ECR

Rollback

Minikube

helm rollback nats --wait
helm rollback micro --wait
helm rollback api --wait

AWS ECR

Destroy

Minikube

helm uninstall api
helm uninstall micro
helm uninstall nats

AWS ECR

helm uninstall api --kubeconfig ~/.kube/eksctl/clusters/skeleton
helm uninstall micro --kubeconfig ~/.kube/eksctl/clusters/skeleton
helm uninstall nats --kubeconfig ~/.kube/eksctl/clusters/skeleton

Destroy AWS EKS Cluster:

eksctl delete cluster --name skeleton

Cheatsheet

https://kubernetes.io/docs/reference/kubectl/cheatsheet/

Make commands

To check the command list:

make help

Output:

Usage: make <command>

command              description
------               -----------
help                 Help dialog.
pull                 Pull docker images.
build                Build docker images based on docker-compose.yml file.
up                   Start docker containers.
upd                  Start docker containers in daemon mode.
upp                  Rebuild and start docker containers.
main                 Enter the 'main' docker container.
stop                 Stop docker containers.
down                 Destroy docker containers and volumes.
clean                Destroy docker containers, local images and volumes.
ci                   Run tests in CI mode.

Debug

Listen for logs:

kubectl logs -f -l app=api --all-containers [ --kubeconfig ~/.kube/eksctl/clusters/skeleton ]
kubectl logs -f -l app=micro --all-containers [ --kubeconfig ~/.kube/eksctl/clusters/skeleton ]

Enter pods:

kubectl exec --stdin --tty <pod-name> -- /bin/sh

About

Skeleton of a NodeJS backend, using NestJS + GraphQL + NATS + Microservices + Docker + CI/CD + automated deployments with GitHub Actions using Kubernetes, Helm and AWS EKS.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published