- For backend, I used the resources given in the task pdf.
- I created the service images by separate dockerfile for each service with
alpineas base image and installednodejsandnpmto run services. - The whole setup is dockerised and can be deployed or restarted with latest images by running
bash deploy.shNote :
deploy.shscript usesdocker compose(v2) notdocker-compose(v1).
- This application requires
Rabbitmqfor transmitting messages between containers (i.e. product service and order service) andRedisfor 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
nginxreverse proxy for directing requests to containers based on url path. - Port
3000is used for listening and accepting requests.
- To setup locally without docker, you have to install
RabbitmqandRedisand change the hostname in js files fromrabbitmqorredistolocalhost. - Start the
RabbitmqandRedisby
sudo systemctl start [service_name]- Dependencies can be installed by
npm installand 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":"test@example.com", "password":"1234"}'- To login
curl -X POST http://localhost:3000/users/login -H "Content-Type: application/json" -d '{ "email":"test@example.com", "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":"test@example.com", "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,
Dockerfileis configuration file. - For running multiple containers at same time as cluster,
docker composeis used withcompose.yamlas configuration file. - To persist data of
RabbitmqandRedis, volumes namedrabbitmq_dbandredis_dbis created and mounted at respective directories of containers. - Since services depend on
RabbitmqandRedis,healthcheckis 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@v6action. - 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@v3action using PAT(Personal Accesss Token) stored in Github secrets. - Instead of installing
nodejsandnpmfor each services, they are installed inalpine_nodeimage and it is used for building service images.
