Code Monkey home page Code Monkey logo

eccomerce-lab's Introduction

About

This project was created to test and refresh my skills wih:

  • Backend node.js
  • Front Vue.js
  • Document Database mongoDB
  • Queue with RabbitMQ
  • Events with Kafka

How it works

Architecture

Front end

It has a simple front-end with Vue.js. The Vue generates a static page who list all products requesting the product-api.

Product API

The product API is a node.js service with:

  • Express to create the API
  • Mongoose to manage the Document Database for Products
  • Redis for Cache the responses

Apache benchmark-test

Apache Benchmark Test is a tool who makes a benchmark to test the time spend on requests.

Verify the README on this folder to run and make your own tests

Buy-api

On the list of products, you can click to buy the product (fake, of course).

When click on it, the buy-api will receive the request and save the information of product bought on a Queue in RabbitMQ.

Buy-job

This project receive the product bought in Queue and process it.

After bought, service generates an Event on Kafka.



Docker compose

To dev and test the applications, I created a docker compose configuration.

The docker compose start the environment with all envs who the apps need.

Dev Environment

docker compose -f docker-compose-dev.yml up

Local tests with image builds

docker compose up

How to test

http://localhost:8080/

Logs

docker compose logs -f

Container Image

Build Image

docker compose build

or

docker compose build [NAME]
ex: docker compose build front-end

Push Image

docker compose push

or

docker compose push [NAME]
ex: docker compose push front-end


Minikube

Start Minikube

minikube start
minikube dashboard

Install Databases

helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo update
kubectl apply -f gitops/databases-helm/mongodb/mongodb-configmap.yml
helm upgrade --install mongo bitnami/mongodb \
  --set auth.username=product-api \
  --set auth.password=product-api-password \
  --set auth.database=products \
  --set persistence.size=1Gi \
  --set initdbScriptsConfigMap=mongo-init-configmap \
  --version 15.6.9

helm upgrade --install redis bitnami/redis \
  --set global.redis.password=your_redis_password \
  --set master.persistence.size=300Mi \
  --set replica.persistence.size=300Mi \
  --set replica.replicaCount=1 \
  --version 19.5.5

helm upgrade --install rabbitmq bitnami/rabbitmq \
  --set auth.username=rabbitmq \
  --set auth.password=rabbitmq-password \
  --set persistence.size=1Gi \
  --version 14.4.4

helm upgrade --install kafka bitnami/kafka \
  --set auth.enabled=false \
  --set controller.persistence.size=1Gi \
  --set zookeeper.persistence.size=1Gi \
  --set controller.replicaCount=1 \
  --set zookeeper.replicaCount=1 \
  --set listeners.client.protocol=PLAINTEXT \
  --version 29.3.4

helm repo add kafka-ui https://provectus.github.io/kafka-ui-charts
helm install kafka-ui kafka-ui/kafka-ui \
  --set kafka.clusters[0].name=kafka \
  --set kafka.clusters[0].bootstrapServers=kafka:9092 \
  --set auth.type=disabled \
  --set management.health.ldap.enabled=false

Install microservices

kubectl apply -f gitops/apps/

Test applications

kubectl port-forward svc/front-end-service 8080 &
kubectl port-forward svc/product-api-service 3000 &
kubectl port-forward svc/buy-api-service 3001 &
kubectl port-forward svc/eccomerce-lab-kafka-ui 9080:80 &

Verify Mongodb Data

kubectl run -i --tty --rm mongo-client --image=mongo --restart=Never -- bash
mongosh "mongodb://product-api:product-api-password@mongo-mongodb:27017/products"
db.products.find().pretty()

Verify Redis Data

kubectl run -i --tty --rm redis-client --image=redis --restart=Never -- bash
redis-cli -h redis-master -a your_redis_password
KEYS *

Clean up

kubectl delete -f gitops/apps/
helm uninstall mongo
helm uninstall redis
helm uninstall rabbitmq
helm uninstall kafka bitnami/kafka
helm uninstall kafka-ui
kubectl delete -f gitops/databases-helm/mongodb/mongodb-configmap.yml


GitOps with ArgoCD

Start Minikube

minikube start
minikube dashboard

Install ArgoCD

kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/v2.5.8/manifests/install.yaml

Acess the UI

kubectl port-forward svc/argocd-server -n argocd 9090:443

Get Admin Password

kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath="{.data.password}" | base64 -d; echo

Install databases

The folder gitops/databases-helm/ have all ArgoCD Application needed to install all databases.

kubectl apply -f gitops/databases-helm/kafka/
kubectl apply -f gitops/databases-helm/kafka-ui/
kubectl apply -f gitops/databases-helm/mongodb/
kubectl apply -f gitops/databases-helm/rabbitmq/
kubectl apply -f gitops/databases-helm/redis/

Install microservices

To install the apps, We will use the ApplicationSet. It will get all configuration from the github automatically

argocd appset create gitops/ArgoCD-apps.yml --port-forward --port-forward-namespace argocd

Clean up

argocd app delete argocd/eccomerce-lab-redis --cascade --port-forward --port-forward-namespace argocd
argocd app delete argocd/eccomerce-lab-rabbitmq --cascade --port-forward --port-forward-namespace argocd
argocd app delete argocd/eccomerce-lab-kafka --cascade --port-forward --port-forward-namespace argocd
argocd app delete argocd/eccomerce-lab-kafka-ui --cascade --port-forward --port-forward-namespace argocd
argocd app delete argocd/eccomerce-lab-mongodb --cascade --port-forward --port-forward-namespace argocd
argocd appset delete eccomerce-lab-apps

eccomerce-lab's People

Contributors

gustavoapolinario avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.