From fd0ef61a261697898934e449e5fcc8b78200d841 Mon Sep 17 00:00:00 2001 From: Reeteshrajesh <143641437+Reeteshrajesh@users.noreply.github.com> Date: Wed, 8 Jan 2025 13:48:32 +0530 Subject: [PATCH 1/5] Update README.md i am preparing readme for understand my project --- README.md | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index ff19352..b6c7d42 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,8 @@ ## Library Management System 📚 -A web app for managing all the activities of a library like managing members and book transactions, built on MERN Stack +A full-stack web application built on the **MERN Stack** (MongoDB, Express, React, and Node.js) for managing library activities such as adding books, managing members, issuing and returning books, and more. ![1](https://user-images.githubusercontent.com/73348574/205624307-6a1b18fa-5ef7-4de9-b141-9225eca62c6c.png) -### Video Demo - -[Demo Link](https://drive.google.com/file/d/1gddUdOE41WaEyY4OWoJtDa0l6VJZTg94/view?usp=sharing) - -Show some ❤️ and 🌟 the repo to support the project ## Index ✏️ @@ -65,12 +60,15 @@ Show some ❤️ and 🌟 the repo to support the project 5. Run `nodemon server.js` to start the server [Should have installed nodemon globally] -## Technologies 🛠 +## Technologies Used 🛠 + +- **Frontend**: React.js (Hooks), Yarn +- **Backend**: Node.js, Express.js +- **Database**: MongoDB +- **Deployment**: AWS EC2, Docker, Jenkins, ArgoCD, Kubernetes +- **CI/CD**: Jenkins, Trivy for Vulnerability Scanning -- ReactJS[Hooks] -- NodeJs -- ExpressJs -- MongoDB +--- ## Screenshots @@ -94,9 +92,14 @@ Show some ❤️ and 🌟 the repo to support the project ## Connect Me On 🌍 -[![twitter badge](https://img.shields.io/badge/twitter-Pranavdhar-0077b5?style=social&logo=twitter)](https://twitter.com/iampranavdhar)
-[![linkedin badge](https://img.shields.io/badge/linkedin-Pranavdhar-0077b5?style=social&logo=linkedin)](https://in.linkedin.com/in/sai-pranavdhar-reddy-nalamalapu-038104206) +linkedIn :: https://www.linkedin.com/in/reetesh-kumar-850807255/ + +--- + +### Key Features: +- **Setup and Deployment**: Comprehensive steps for local development and deploying to AWS EC2 using Docker, Jenkins, and Kubernetes. +- **Dockerization**: Separate Dockerfiles for frontend and backend, with a Docker Compose option. +- **CI/CD Workflow**: Integrated instructions for Jenkins and Trivy. +- **ArgoCD Deployment**: Easy configuration for Kubernetes. -## License 🏆 -This repository is licensed under MIT License. Find [LICENSE](LICENSE) to know more From 073f3b866edeea864788c183ce5de9705f7aa507 Mon Sep 17 00:00:00 2001 From: Reeteshrajesh <143641437+Reeteshrajesh@users.noreply.github.com> Date: Wed, 8 Jan 2025 15:00:11 +0530 Subject: [PATCH 2/5] Update README.md add deployement section --- README.md | 188 ++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 177 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index b6c7d42..0e9bfa1 100644 --- a/README.md +++ b/README.md @@ -7,18 +7,23 @@ A full-stack web application built on the **MERN Stack** (MongoDB, Express, Reac ## Index ✏️ - [Library Management System 📚](#library-management-system-) - - [Video Demo](#video-demo) - [Index ✏️](#index-️) -- [Features Of LCMS 🚀](#features-of-lcms-) +- [Features of LCMS 🚀](#features-of-lcms-) - [Setup 🔥](#setup-) - [Frontend Setup 🍧](#frontend-setup-) - [Backend Setup 🍿](#backend-setup-) -- [Technologies 🛠](#technologies-) -- [Screenshots](#screenshots) -- [References 💻](#references-) +- [Dockerization 🐳](#dockerization-) + - [Dockerize Frontend](#dockerize-frontend) + - [Dockerize Backend](#dockerize-backend) + - [Docker Compose for Full Application](#docker-compose-for-full-application) +- [Deployment Instructions 🚀](#deployment-instructions-🚀-) +- [Technologies Used 🛠](#technologies-used-) +- [Screenshots](#Screenshots-) - [Author 📝](#author-) - [Connect Me On 🌍](#connect-me-on-) -- [License 🏆](#license-) +- [Key Features of Technology Used 🏆](#Key-Features) + +--- ## Features Of LCMS 🚀 @@ -30,6 +35,8 @@ A full-stack web application built on the **MERN Stack** (MongoDB, Express, Reac - Reserving a book for specific dates - Showing the Achievements, Event Gallery +--- + ## Setup 🔥 - Fork the Repo @@ -60,6 +67,168 @@ A full-stack web application built on the **MERN Stack** (MongoDB, Express, Reac 5. Run `nodemon server.js` to start the server [Should have installed nodemon globally] + +--- + +## Dockerization 🐳 + +#### Dockerize Frontend +Build and run the image: + + + docker build -t library-management-frontend ./frontend + docker run -d -p 3000:3000 library-management-frontend + +#### Dockerize backend +Build and run the image: + + + docker build -t library-management-backend ./backend + docker run -d -p 5000:5000 library-management-backend + + +### Docker Compose for Full Application + +Run the application using Docker Compose: + + docker-compose up --build + +--- +--- + +# Deployment Instructions 🚀 +### Step 1: Setup Jenkins for CI/CD + +1. **Create a Jenkins job to build the application:** + - Go to Jenkins dashboard and create a new pipeline job. + - In the pipeline configuration, set up the pipeline script (or use `Jenkinsfile` if you have it in your repository). + - Add a build step to pull the code from the GitHub repository and build the Docker images for both frontend and backend. + +2. **Pipeline Script for Jenkins:** + ```groovy + pipeline { + agent any + stages { + stage('Checkout Code') { + steps { + git 'https://github.com/Reeteshrajesh/library-management-system.git' + } + } + stage('Build Docker Images') { + steps { + script { + // Build frontend Docker image + sh 'docker build -t library-management-frontend ./frontend' + // Build backend Docker image + sh 'docker build -t library-management-backend ./backend' + } + } + } + stage('Test Docker Containers') { + steps { + script { + // Add your test commands here to validate Docker containers (e.g., health checks) + sh 'docker run --rm library-management-frontend test' + sh 'docker run --rm library-management-backend test' + } + } + } + } + } + + +### Step 2: Vulnerability Scanning + + +To ensure the security of your Docker images, it's important to perform vulnerability scanning. Trivy is a fast and simple vulnerability scanner for Docker images. In this step, we'll install Trivy and integrate it into a Jenkins pipeline to scan your Docker images for vulnerabilities before deployment. If any **high** vulnerabilities are found, the deployment will be blocked. + + +#### Install Trivy for Docker image scanning: + +1. **For macOS (using Homebrew):** + ```bash + brew install trivy + +2. **Alternatively, you can use Docker to install Trivy in a container:** + ```bash + docker pull aquasec/trivy + +3. **Create a Jenkins job to block deployment if high vulnerabilities are found:** + + - Set up a Jenkins job to run Trivy to scan the Docker images. + - Configure the Jenkins pipeline to use Trivy for scanning the frontend and backend images for vulnerabilities before deployment. If any high vulnerabilities are found, stop the deployment. + + +4.**Pipeline Script for Jenkins (Vulnerability Scanning):** + + + + pipeline { + agent any + stages { + stage('Scan Docker Images for Vulnerabilities') { + steps { + script { + // Scan the frontend image + sh 'trivy image library-management-frontend:latest' + // Scan the backend image + sh 'trivy image library-management-backend:latest' + } + } + } + stage('Deploy') { + steps { + script { + // Deploy only if no high vulnerabilities are found + // Add logic to check the Trivy report and proceed accordingly + echo 'Deploying application to Kubernetes...' + } + } + } + } + } + + + +### Step 3: Deploy with Kubernetes and ArgoCD + +#### Create a Kubernetes deployment file(deployment.yaml): + + + apiVersion: apps/v1 + kind: Deployment + metadata: + name: library-management + spec: + replicas: 2 + selector: + matchLabels: + app: library-management + template: + metadata: + labels: + app: library-management + spec: + containers: + - name: frontend + image: library-management-frontend:latest + ports: + - containerPort: 3000 + - name: backend + image: library-management-backend:latest + ports: + - containerPort: 5000 + + + + +#### Deploy using ArgoCD connected to your Kubernetes cluster. + - Install ArgoCD and link it to your Kubernetes cluster. + - In ArgoCD, create an application that connects to the Git repository where your Kubernetes configuration is stored. + - Use ArgoCD to sync and deploy the library-management application to your Kubernetes cluster. + + --- + ## Technologies Used 🛠 - **Frontend**: React.js (Hooks), Yarn @@ -81,14 +250,11 @@ A full-stack web application built on the **MERN Stack** (MongoDB, Express, Reac ![7](https://user-images.githubusercontent.com/73348574/205631804-6c631b5e-8bcd-41c4-bb73-bab6ea8b78f7.png) ![8](https://user-images.githubusercontent.com/73348574/205631977-f393ca09-aa24-42a5-9bd7-d92d471c514c.png) -## References 💻 - -- [NodeJs Documentation](https://nodejs.org/en/docs/) -- [React Documentation](https://reactjs.org/docs/getting-started.html) +--- ## Author 📝 -- [@iampranavdhar](https://www.github.com/iampranavdhar) +- [@Reeteshrajesh]((https://github.com/Reeteshrajesh)) ## Connect Me On 🌍 From 0d9bf87c26573987ea7aa59e7fe0feca01527ac7 Mon Sep 17 00:00:00 2001 From: Reeteshrajesh <143641437+Reeteshrajesh@users.noreply.github.com> Date: Wed, 8 Jan 2025 15:07:24 +0530 Subject: [PATCH 3/5] Create Dockerfile Dockerize project --- backend/Dockerfile | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 backend/Dockerfile diff --git a/backend/Dockerfile b/backend/Dockerfile new file mode 100644 index 0000000..7c7840f --- /dev/null +++ b/backend/Dockerfile @@ -0,0 +1,7 @@ +# Dockerfile for Backend +FROM node:16 +WORKDIR /app +COPY . . +RUN yarn install +CMD ["yarn", "start"] +EXPOSE 5000 From 16c6a027732424a38b9764f151dd2ba71a315a8b Mon Sep 17 00:00:00 2001 From: Reeteshrajesh <143641437+Reeteshrajesh@users.noreply.github.com> Date: Wed, 8 Jan 2025 15:08:41 +0530 Subject: [PATCH 4/5] Create Dockerfile Dockerize project --- frontend/Dockerfile | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 frontend/Dockerfile diff --git a/frontend/Dockerfile b/frontend/Dockerfile new file mode 100644 index 0000000..dd3ac2f --- /dev/null +++ b/frontend/Dockerfile @@ -0,0 +1,7 @@ +# Dockerfile for Frontend +FROM node:16 +WORKDIR /app +COPY . . +RUN yarn install +CMD ["yarn", "start"] +EXPOSE 3000 From e4aab0ac8bd1a00119ef68045b6a9a32305b618b Mon Sep 17 00:00:00 2001 From: Reeteshrajesh <143641437+Reeteshrajesh@users.noreply.github.com> Date: Wed, 8 Jan 2025 15:09:37 +0530 Subject: [PATCH 5/5] Create docker-compose.yml Dockerize project --- docker-compose.yml | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 docker-compose.yml diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..f61ccd6 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,26 @@ +version: '3' +services: + frontend: + build: + context: ./frontend + ports: + - "3000:3000" + depends_on: + - backend + + backend: + build: + context: ./backend + ports: + - "5000:5000" + environment: + - MONGO_URI=mongodb://mongo:27017/library + depends_on: + - mongo + + mongo: + image: mongo:latest + volumes: + - ./data/db:/data/db + ports: + - "27017:27017"