- For backend, I used the resources given in the task pdf.
- I created the service images by separate dockerfile for each service with
alpine
as base image and installednodejs
andnpm
to run services. - The whole setup is dockerised and can be deployed or restarted with latest images by running
bash deploy.sh
Note :
deploy.sh
script usesdocker compose
(v2) notdocker-compose
(v1).
- This application requires
Rabbitmq
for transmitting messages between containers (i.e. product service and order service) andRedis
for temporary db (or cache). Images are pulled automatically during setup. - To see errors encountered or deployment details during setup, see
deploy.log
- I also used
nginx
reverse proxy for directing requests to containers based on url path. - Port
3000
is used for listening and accepting requests.
- To setup locally without docker, you have to install
Rabbitmq
andRedis
and change the hostname in js files fromrabbitmq
orredis
tolocalhost
. - Start the
Rabbitmq
andRedis
by
sudo systemctl start [service_name]
- Dependencies can be installed by
npm install
and service is started bynpm start
- To create new user
curl -X POST http://localhost:3000/users/register -H "Content-Type: application/json" -d '{"name":"test", "email":"[email protected]", "password":"1234"}'
- To login
curl -X POST http://localhost:3000/users/login -H "Content-Type: application/json" -d '{ "email":"[email protected]", "password":"1234"}'
- To see user details
curl -X GET http://localhost:3000/users/profile?name=test
- To delete a user
curl -X DELETE http://localhost:3000/users/profile -H "Content-Type: application/json" -d '{ "email":"[email protected]", "name":"test" }'
- To create new product
curl -X POST http://localhost:3000/product/create -H "Content-Type: application/json" -d '{ "name" : "eraser", "description" : "used to erase", "price" : "10"}'
- To order a product
curl -X POST http://localhost:3000/product/buy -H "Content-Type: application/json" -d '{ "ids" : "669ba919f0b262660130ef58"}'
- To build the images,
Dockerfile
is configuration file. - For running multiple containers at same time as cluster,
docker compose
is used withcompose.yaml
as configuration file. - To persist data of
Rabbitmq
andRedis
, volumes namedrabbitmq_db
andredis_db
is created and mounted at respective directories of containers. - Since services depend on
Rabbitmq
andRedis
,healthcheck
is performed on them to ensure status before starting servcies.
- Using Github workflow and actions, Docker images are built and pushed to Dockerhub using
docker/build-push-action@v6
action. - Workflow consists of jobs and job is defined with steps.
- This workflow is triggered whenever there is commit on repo.
- To upload the images, login is needed which is done by
docker/login-action@v3
action using PAT(Personal Accesss Token) stored in Github secrets. - Instead of installing
nodejs
andnpm
for each services, they are installed inalpine_node
image and it is used for building service images.