Automated-To-Do-List-Deployment-with-Monitoring-Excellence

Automated-To-Do-List-Deployment-with-Monitoring-Excellence

CI/CD Pipeline and Monitoring

Successfully deployed a single-node todo app using Docker, while implementing a robust CI/CD pipeline via Jenkins to automate code integration, building, testing, and deployment. Enhanced monitoring capabilities through the integration of Grafana and Prometheus for comprehensive performance monitoring and analysis.

Perequisites:

  • Launch AWS ec2 instance

  • Install Git:

      sudo apt update
      sudo apt install git
    
  • Install Docker

      sudo apt update
      sudo apt install docker.io
      sudo chown $USER:docker /var/run/docker.sock
    
  • Install Docker-Compose

      sudo apt update
      sudo apt install docker-compose
    
  • Install Jenkins

      sudo apt update
      sudo apt install fontconfig openjdk-17-jre
      sudo wget -O /usr/share/keyrings/jenkins-keyring.asc \
        https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key
      echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \
        https://pkg.jenkins.io/debian-stable binary/ | sudo tee \
        /etc/apt/sources.list.d/jenkins.list > /dev/null
      sudo apt-get update
      sudo apt-get install jenkins
    
  • Install Grafana

      sudo apt-get install -y apt-transport-https
      sudo apt-get install -y software-properties-common wget
      sudo wget -q -O /usr/share/keyrings/grafana.key https://apt.grafana.com/gpg.key
      sudo apt-get update
      sudo apt-get install grafana
      sudo systemctl start grafana-server
    
  • Install Prometheus Config file

      Wget https://raw.githubusercontent.com/prometheus/prometheus/main/documentation/examples/prometheus.yml
    
  • create on docker-compose.yml file

      version: '3.2'
    
      services:
        prometheus:
          image: prom/prometheus:latest
          container_name: prometheus
          ports:
            - 9090:9090
          command:
            - --config.file=/etc/prometheus/prometheus.yml
          volumes:
            - ./prometheus.yml:/etc/prometheus/prometheus.yml:ro
          depends_on:
            - cadvisor
    
        cadvisor:
          image: gcr.io/cadvisor/cadvisor:latest
          container_name: cadvisor
          ports:
            - 8080:8080
          volumes:
            - /:/rootfs:ro
            - /var/run:/var/run:rw
            - /sys:/sys:ro
            - /var/lib/docker/:/var/lib/docker:ro
          depends_on:
            - redis
    
        redis:
          image: redis:latest
          container_name: redis
          ports:
            - 6379:6379
    

Now our installation is done, lets start:

Pull code from git

ubuntu@ip-172-31-33-17:~/project/node-todo-cicd$ git clone https://github.com/LondheShubham153/node-todo-cicd.git

Create docker.yml file

command: vim docker

#to build the use command
docker build -t node-app .
#to run the image use command
docker run -d -p 8000:8000 node-app:latest

#to check is container is running or not use
docker ps

You can see on port 8000 our project is running

Now lets use Docker-Compose to run the project

Command: vim docker-compose.yml

Here:

  • version: It's version Docker Compose file format being used.

  • services: This section defines the services that make up your application.

  • app: This is the name of the service.

  • build: This section is used to configure the build process for the Docker image

  • context: This sets the build context to the current directory (.), meaning that Docker will look for the Dockerfile and related files in the current directory.

  • ports: This section defines the ports that should be exposed by the container.

Note:

  • if you want to pull the image from the docker-hub you can do this just do one change in docker-compose file

  • image: This line specifies the Docker image to use for the app service. In this case, the Docker image is "sumit9730/node-app".

  • if we pulling the image from docker-hub we not need to write docker file

#to run docker-compose file use
docker-compose up

#you can check on 8000 port our app is running

#to stop the container use
docker-compose down

Lets add some volume to our app so app data will not lost

Open docker-compose file and do change

now run the app

you can see our app running and we have add some data also that will add in app_data

Lets create a jenkins CI/CD pipeline

Open Jenkins on port no 8080

steps:

  • click on new item & select pipeline

  • add discription

  • select github project and add the github app URL

  • write pipeline script

  • save the file

  • Click on build now button

  • you can see pipeline is created

  • Our app also running

Lets do monitoring for our app through

grafana and Prometheus

  • our installation is already done

  • open grafana on 3000 port

  • default id is admin, pass is admin

  • then you can set password

Note:

  • make sure you stoped the jenkins server because cAdvisor also running on 8080 port

What is monitoring:

Grafana is an open-source analytics and monitoring platform that integrates with various data sources, including time-series databases, log data, and more. It is commonly used for monitoring and visualizing the performance of applications, systems, and infrastructure. Monitoring by Grafana involves using Grafana to create dashboards that display real-time or historical data in a visually appealing and easily understandable format.

Steps:

  • click on datasource

  • click on prometheus

  • give me name, link and save this

  • search the grafana dashboards on google

  • search docker container and host metrics and copy the dashboards id

  • you can now monitor your containers

Note:

  • you have to add a job in prometheus.yml file

        - job_name: "Docker"
          static_configs:
            - targets:
              - "cadvisor: 8080"
    
  • restart the prometheus by

      docker-compose up -d
    
  • Ports that must be added in AWS instance security group (Inbound rules)

    - Port 8000 for Node-App

    - Port 3000 for Grafana

    - Port 8080 for Jenkins & cAdvisor

    - Port 9090 for Prometheus

Finally our project is done. I hope you liked this blog. If you want more project you can comment for it. We successfully deployed app also we created CI/CD Pipeline through jenkins and monitoring by grafana

GitHub Project Link