A simple Todo app with React + Node.js + MongoDB written in TypeScript.
The frontend, the api server, and the database are all dockerized, and they are combined using Docker-Compose or Kubernetes.
This repository also hosts configuration files for GitHub Actions such as
- run
npm test
for pull-requests - create a preview page in Okteto Cloud
- deploy the stable code in
main
branch on merging pull-requests
Makefile provides shortcuts for development commands.
make
to start a dev environment after building imagesmake down
to stop the dev environmentmake test
to create test containers with hot-reloadmake test_single
to run tests and quit (useful for continuous integration)
After the dev environment starts up, the frontend client listens requests at http://localhost:3000
and the API server accepts requests at http://localhost:4000
.
cp .env.dev .env.prod
vim .env.prod # set secure passwords
docker compose -f docker-compose-prod.yml --env-file .env.prod up --build
After this, please visit https://localhost (self-signed certificate is created by docker-compose-prod.yml
, so don't be surprised if prompted a certificate warning)
docker compose -f docker-compose-prod.yml down
-
Create MongoDB-related secret:
cp .env.dev .env vim .env # set secure passwords kubectl create ns todo kubectl -n todo create secret generic todosecret --from-env-file .env
-
Install NGINX Ingress Controller
helm upgrade --install ingress-nginx ingress-nginx --repo https://kubernetes.github.io/ingress-nginx --namespace ingress-nginx --create-namespace
-
Apply Kubernetes configuration files:
kubectl apply -f k8s/
-
Visit https://localhost and you will be redirected to the login page if success.
-
Cleanup:
kubectl delete ns todo
You can use k6 to test loads.
The official installation manual is here
After installation, please visit https://localhost and create a new user with username loadtester
with the password of your choice.
Examples:
- GET /
k6 run --insecure-skip-tls-verify --vus
100 --duration 2s -e BASE_URL=https://localhost -e SLEEP=0.1 k6/test.js
- POST /api/auth/login
k6 run --insecure-skip-tls-verify --vus
100 --duration 2s -e BASE_URL=https://localhost -e TODOPASS=Pass0 -
e MODE=login -e SLEEP=0.5 k6/test.js
- Start the containers
make
- Get inside
nodejs
container
docker compose -f docker-compose-dev.yml exec -it nodejs sh
- Update
package.json
npx npm-check-updates -u
- Update
package-lock.json
npm i
- Exit from
nodejs
container and run tests
make down
make test_single