diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..89df1ef --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,54 @@ +pipeline { + agent any + environment { + SONARQUBE_SCANNER_HOME = tool 'SonarQubeScanner' + + } + + stages { + stage('Clone') { + steps { + git url: 'https://github.com/Lokendram10/Indore-Route-Pathfinder-cicd.git', branch: 'main' + } + } + stage('SonarQube Scan') { + steps { + withSonarQubeEnv('SonarQubeServer') { + sh ''' ${SONARQUBE_SCANNER_HOME}/bin/sonar-scanner \ + -Dsonar.projectName=Indore-Route-Pathfinder-cicd \ + -Dsonar.projectKey=Indore-Route-Pathfinder-cicd + ''' + } + + } + } + stage('OWASP Dependency Check') { + steps { + echo "OWASP Dependency Check" + dependencyCheck ( + additionalArguments: '--scan ./' + , odcInstallation: 'owasp' + ) + echo "OWASP Dependency Check" + dependencyCheckPublisher pattern: '**/dependency-check-report.xml' + } + } + stage('Trivy Scan') { + steps { + sh 'trivy fs --severity HIGH,CRITICAL -f json -o trivy-report.json . ' + } + } + stage('Quality Gate') { + steps { + timeout(time: 1, unit: 'HOURS') { + waitForQualityGate abortPipeline: true + } + } + } + stage('Docker Build') { + steps { + sh 'docker compose up --build -d' + } + } + } +} \ No newline at end of file diff --git a/README.md b/README.md index d798585..d64356d 100644 --- a/README.md +++ b/README.md @@ -2,11 +2,13 @@
-![React](https://img.shields.io/badge/React-20232A?style=for-the-badge&logo=react&logoColor=61DAFB) -![Node.js](https://img.shields.io/badge/Node.js-43853D?style=for-the-badge&logo=node.js&logoColor=white) -![MongoDB](https://img.shields.io/badge/MongoDB-4EA94B?style=for-the-badge&logo=mongodb&logoColor=white) +![React](https://img.shields.io/badge/React-20232A?style=for-the-badge\&logo=react\&logoColor=61DAFB) +![Node.js](https://img.shields.io/badge/Node.js-43853D?style=for-the-badge\&logo=node.js\&logoColor=white) +![MongoDB](https://img.shields.io/badge/MongoDB-4EA94B?style=for-the-badge\&logo=mongodb\&logoColor=white) +![Docker](https://img.shields.io/badge/Docker-2496ED?style=for-the-badge\&logo=docker\&logoColor=white) +![Jenkins](https://img.shields.io/badge/Jenkins-D24939?style=for-the-badge\&logo=jenkins\&logoColor=white) -**A simple web application to plan routes between stations in Indore using Dijkstra's Algorithm** +**A web application to plan routes between stations in Indore using Dijkstra's Algorithm** [🚀 Live Demo](https://indore-route.vercel.app) @@ -14,62 +16,79 @@ --- -## ✨ What it does +> **Note**: This project was originally created by Harshit Singh. I forked the repository and made additional changes (Docker, Docker Compose, and Jenkins pipeline) in the **main** branch. The **master** branch contains the original code. -- 📍 **Add Stations**: Create new stations/locations -- 🔗 **Connect Stations**: Link stations with distance and cost -- 🧭 **Find Routes**: Calculate shortest path by distance OR cheapest path by cost -- 📊 **View All**: See all stations and connections in one place +--- + +## ✨ Features + +* 📍 **Add Stations**: Create new stations/locations +* 🔗 **Connect Stations**: Link stations with distance and cost +* 🧭 **Find Routes**: Calculate shortest path by distance or cheapest path by cost +* 📊 **View All**: See all stations and connections at a glance +* 🐳 **Dockerized**: Run frontend and backend with Docker & Docker Compose +* 🤖 **CI/CD**: Automated deployment pipeline with Jenkins --- ## 🛠️ Tech Stack -- **Frontend**: React.js, Tailwind CSS -- **Backend**: Node.js, Express.js -- **Database**: MongoDB -- **Algorithm**: Dijkstra's Shortest Path +* **Frontend**: React.js, Tailwind CSS +* **Backend**: Node.js, Express.js +* **Database**: MongoDB +* **Algorithm**: Dijkstra's Shortest Path +* **Containerization**: Docker, Docker Compose +* **CI/CD**: Jenkins --- ## 🏃‍♂️ Quick Start -### 1. Clone & Install +### 1. Clone Repository + ```bash -git clone https://github.com/harshitsingh4321/indore-route-planner.git -cd indore-route-planner +git clone https://github.com/Lokendram10/Indore-Route-Pathfinder-cicd +cd Indore-Route-Pathfinder-cicd +``` -# Backend -cd backend && npm install +### 2. Install Docker & Docker Compose (Linux) -# Frontend -cd ../frontend && npm install -``` +```bash +sudo apt-get update +sudo apt-get install docker.io -y +sudo apt-get install docker-compose -y -### 2. Setup Environment -Create `.env` in backend folder: -```env -MONGO_URI=your_mongodb_connection_string -PORT=5000 +# Give permission to current user to run docker without sudo +sudo usermod -aG docker $USER && newgrp docker ``` -### 3. Run Application -```bash -# Start backend (Terminal 1) -cd backend && npm run dev +>⚠️ Logout and login again for group changes to take effect if newgrp docker does not work. -# Start frontend (Terminal 2) -cd frontend && npm run dev +### 3. Docker Setup + +```bash +# Build and run containers +docker-compose up -d --build ``` -Open `http://localhost:3000` 🎉 +* Backend API: `http://localhost:5000` +* Frontend App: `http://localhost:3000` + +### 4. Environment Variables + +Create a `.env` file inside the `backend` folder: + +```env +MONGO_URI=your_mongodb_connection_string +PORT=5000 +``` --- ## 🎯 How to Use 1. **Add Stations**: Enter station name and click "Add Station" -2. **Connect Stations**: Select two stations, enter distance (km) and cost (₹), click "Add Connection" +2. **Connect Stations**: Select two stations, enter distance (km) and cost (₹), click "Add Connection" 3. **Find Route**: Choose start/end stations, select "Distance" or "Cost" optimization, click "Find Route" 4. **View Results**: See the optimal path with total distance and cost @@ -79,15 +98,18 @@ Open `http://localhost:3000` 🎉 ``` indore-route-planner/ -├── frontend/ # React app +├── frontend/ # React app +│ ├── Dockerfile # Dockerfile for frontend │ ├── src/ -│ │ └── App.jsx # Main component │ └── package.json -├── backend/ # Express API -│ ├── models/ # MongoDB schemas -│ ├── routes/ # API routes -│ ├── utils/ # Dijkstra algorithm -│ └── server.js # Main server +├── backend/ # Express API +│ ├── Dockerfile # Dockerfile for backend +│ ├── models/ # MongoDB schemas +│ ├── routes/ # API routes +│ ├── utils/ # Dijkstra algorithm +│ └── server.js +├── docker-compose.yml # Docker Compose setup +├── Jenkinsfile # CI/CD pipeline configuration └── README.md ``` @@ -96,11 +118,11 @@ indore-route-planner/ ## 🔌 API Endpoints ```bash -GET /api/stations # Get all stations -POST /api/stations # Add new station -GET /api/connections # Get all connections -POST /api/connections # Add new connection -POST /api/route # Calculate optimal route +GET /api/stations # Get all stations +POST /api/stations # Add new station +GET /api/connections # Get all connections +POST /api/connections # Add new connection +POST /api/route # Calculate optimal route ``` --- @@ -108,16 +130,19 @@ POST /api/route # Calculate optimal route ## 🧮 Algorithm Uses **Dijkstra's Algorithm** to find: -- **Shortest Distance**: Minimum total kilometers -- **Cheapest Cost**: Minimum total rupees + +* **Shortest Distance**: Minimum total kilometers +* **Cheapest Cost**: Minimum total rupees --- ## 🚀 Deployment -- **Frontend**: Deploy to Vercel : https://indore-metro.vercel.app -- **Backend**: Deploy to Render : https://indore-metro.onrender.com -- Set environment variables in deployment platforms +* **Docker**: Run frontend and backend via Docker Compose +* **CI/CD**: Jenkins pipeline automates building, testing, and deployment +* **Frontend**: Vercel - [https://indore-metro.vercel.app](https://indore-metro.vercel.app) +* **Backend**: Render - [https://indore-metro.onrender.com](https://indore-metro.onrender.com) +* Configure `.env` in deployment environments --- @@ -135,11 +160,12 @@ Uses **Dijkstra's Algorithm** to find: **Made by Harshit Singh** -- 📧 Email: harshitsingh789123@gmail.com -- 💻 GitHub: [harshitsingh4321](https://github.com/harshitsingh4321) +* 📧 Email: [harshitsingh789123@gmail.com](mailto:harshitsingh789123@gmail.com) +* 💻 GitHub: [harshitsingh4321](https://github.com/harshitsingh4321) --- ## 📄 License MIT License - feel free to use this project! + diff --git a/backend/Dockerfile b/backend/Dockerfile new file mode 100644 index 0000000..0a2e4a0 --- /dev/null +++ b/backend/Dockerfile @@ -0,0 +1,7 @@ +FROM node:18 +WORKDIR /app +COPY package.json . +RUN npm install +COPY . . +EXPOSE 5000 +CMD [ "npm", "start" ] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..00ae023 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,39 @@ +services: + mongo: + image: mongo:latest + container_name: mongodb + ports: + - "27017:27017" + volumes: + - my-mongo-data:/data/db + networks: + - mern + backend: + build: + context: ./backend + ports: + - "5000:5000" + volumes: + - ./backend:/usr/src/app + networks: + - mern + depends_on: + - mongo + + + frontend: + build: + context: ./frontend + container_name: frontend + ports: + - "5173:5173" + networks: + - mern + depends_on: + - backend + +networks: + mern: + driver: bridge +volumes: + my-mongo-data: diff --git a/frontend/Dockerfile b/frontend/Dockerfile new file mode 100644 index 0000000..1340985 --- /dev/null +++ b/frontend/Dockerfile @@ -0,0 +1,7 @@ +FROM node:18 +WORKDIR /app +COPY package.json . +RUN npm install +COPY . . +EXPOSE 5173 +CMD ["npm", "run", "dev"] \ No newline at end of file diff --git a/frontend/package.json b/frontend/package.json index b4be167..1bbed15 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -4,7 +4,7 @@ "version": "0.0.0", "type": "module", "scripts": { - "dev": "vite", + "dev": "vite --host 0.0.0.0", "build": "vite build", "lint": "eslint .", "preview": "vite preview"