This repository was created by Banzai Cloud Pipeline. Spotguides provide automated configuration, logging, monitoring, security, and scaling for your application stacks.
Every time you make changes to the source code and update the master
branch, the CI/CD pipeline will be triggered to test, validate and update the deployment of your application. Check the .pipeline.yaml
file for CI/CD steps.
Requirements:
- Docker
- Docker for Desktop
- skaffold and its dependencies
A local Kubernetes cluster must be running (eg. Docker for Desktop).
# verify the Kubernetes context
$ kubectl config get-contexts
# expected output
CURRENT NAME CLUSTER AUTHINFO NAMESPACE
* docker-for-desktop docker-for-desktop-cluster docker-for-desktop
# build the Docker image and deploy via helm
$ cd .banzaicloud
$ skaffold config set --global local-cluster true
$ skaffold run
This will build the application and install all the components to Kubernetes.
Using installed Node.js:
Requirements:
Commands:
# install dependencies
$ npm ci
$ npm test
Using Docker:
Requirements:
Commands:
docker build . --build-arg NODE_ENV=test -t spotguide-nodejs-mongodb
docker run -it --rm -v $(pwd):/home/node/ spotguide-nodejs-mongodb npm test
Uses nodemon, it is a utility that will monitor for any changes in your source and automatically restart your server.
Using local Node.js and MongoDB:
Requirements:
Commands:
# MongoDB must be running, set environment variables in .env or start dependencies
$ cat > .env <<'EOF'
# Used for local development only, when NODE_ENV=development
MONGODB_USERNAME=username
MONGODB_PASSWORD=password
MONGODB_DATABASE=spotguide-nodejs-mongodb
MONGODB_AUTH_SOURCE=admin
TRACING_DISABLED=true
EOF
$ docker-compose up -d db
$ npm install
$ npm run start:dev
Using Docker and Docker Compose:
Requirements:
Commands:
$ docker-compose up -d
# open http://127.0.0.1:3000/api/v1
Our npm
library provides all the essential features to prepare your Node.js application truly ready for production on Kubernetes, such as:
- graceful error handling & shutdown
- structured JSON logging
- various HTTP middleware
- health checks
- metrics
Read more about it in our blog post.
name | description | default |
---|---|---|
PORT |
Application port | 3000 |
MONGODB_URI |
MongoDB URI, scheme: mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database][?options]] |
|
MONGODB_HOST |
MongoDB host | '127.0.0.1' |
MONGODB_PORT |
MongoDB port | 27017 |
MONGODB_USERNAME |
MongoDB user | |
MONGODB_PASSWORD |
MongoDB user password | |
MONGODB_DATABASE |
MongoDB database name |
These are the implemented REST endpoints in the sample application.
Root endpoint, returns basic Pod information, like name, namespace and image.
Prometheus metrics endpoint.
Health check, liveness probe endpoint. Returns 200
when the application is healthy, can reach the database.
Readiness probe endpoint. Returns 200
when the application is ready to accept requests.
Fetch all users.
Create a new user. The request body has the following schema:
{
"email": "",
"username": "",
"firstName": "",
"lastName": ""
}
Fetch a user.
Update a user. The request body has the same schema as POST /api/v1/users
.
Delete a user.