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:
- Kubernetes Tutorial
- AWS EKS - Create Kubernetes cluster on Amazon EKS
- Concept, Pros & Cons of Domain Driven Design
What has been done to the default app:
npm i -g @nestjs/clinest new node-skeletoncd node-skeletonnest generate app micronpm i nestjs/platform-fastifynpm remove @nestjs/platform-express @types/express supertest @types/supertestnpm i @nestjs/microservicesnpm i natsnpm i sinonnpm i @nestjs/confignpm i @nestjs/graphql graphql-tools graphql apollo-server-fastify @moonwalker/graphql-nats-subscriptionsnpm i winston colors
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 | base64Using Docker:
docker-compose upYou can build & deploy out of the box to local minikube or to AWS EKS using Kubernetes.
Install kubectl;
Install Helm;
Install minikube;
Start minikube:
minikube startInstall and configure AWS CLI;
Install eksctl;
Create AWS Cluster:
eksctl create cluster -f ./build-deploy/cluster/skeleton.yaml --auto-kubeconfigScale Cluster if needed:
eksctl scale nodegroup --cluster=skeleton --nodes=4 --name=skeleton-nodesTip:
Use
--kubeconfig ~/.kube/eksctl/clusters/skeletonflag to use AWS EKS withkubectlorhelm.
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 .
- Run GitHub Action: Build Api;
- Run GitHub Action: Build Micro.
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 --waitExplose API:
minikube service api-service- Run GitHub Action Deploy NATS;
- Run GitHub Action Deploy Micro;
- Run GitHub Action Deploy Api.
helm rollback nats --wait
helm rollback micro --wait
helm rollback api --wait- Run GitHub Action Rollback NATS;
- Run GitHub Action Rollback Micro;
- Run GitHub Action Rollback Api.
helm uninstall api
helm uninstall micro
helm uninstall natshelm uninstall api --kubeconfig ~/.kube/eksctl/clusters/skeleton
helm uninstall micro --kubeconfig ~/.kube/eksctl/clusters/skeleton
helm uninstall nats --kubeconfig ~/.kube/eksctl/clusters/skeletonDestroy AWS EKS Cluster:
eksctl delete cluster --name skeletonhttps://kubernetes.io/docs/reference/kubectl/cheatsheet/
To check the command list:
make helpOutput:
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.
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