This project demonstrates how to build an automated CI/CD pipeline for a web application using Jenkins, SonarQube, Docker, and AWS. Each push to the GitHub repository automatically triggers the pipeline, which builds, tests, analyzes, and deploys the application to an AWS EC2 instance.
- Project Overview
- Pipeline Workflow
- Prerequisites
- Setup Instructions
- Pipeline Steps
- Usage
- Contributing
- License
This project automates the process of building, testing, analyzing, and deploying a web application every time code is pushed to the specified GitHub branch. The pipeline performs the following:
- Static Code Analysis with SonarQube to catch bugs and vulnerabilities early.
- Deployment using Docker on AWS EC2, making the latest application version accessible to end users.
- GitHub: Pushes code changes to a specified branch.
- Jenkins: Pulls the latest code and initiates the build and test stages.
- SonarQube: Scans code for quality issues.
- Docker: Deploys the application for user access.
- AWS Account with permissions to create and manage EC2 instances.
- GitHub Repository with the web application code.
- Basic Knowledge of Jenkins, SonarQube, Docker, and AWS.
Create three EC2 instances on AWS with a security group that allows all traffic (for demonstration purposes).
- Jenkins Instance
- SonarQube Instance
- Docker Instance
Install the necessary software on each EC2 instance:
- Jenkins on the first EC2 instance.
- SonarQube on the second EC2 instance.
- Docker on the third EC2 instance.
- Generate SSH keys on the Jenkins server:
ssh-keygen -t rsa
- Add the public SSH keys to the authorized_keys files on the SonarQube and Docker instances for password-less authentication.
- Install the SSH2 Easy plugin in Jenkins to manage secure SSH connections.
- Set up server groups and sites for Jenkins, SonarQube, and Docker.
- Create a Jenkins job:
- Add the GitHub repository link.
- Set the branch to build and deploy.
- Add build steps to copy code from Jenkins to SonarQube and Docker instances.
- Code Checkout: Jenkins pulls the latest code from GitHub.
- Static Code Analysis: Jenkins sends the code to SonarQube for bug and vulnerability scanning.
- Build and Test: Jenkins prepares the application for deployment.
- Deployment: If the code passes SonarQube checks, Jenkins deploys it to the Docker container, making it available online.
- Push code to the specified branch in your GitHub repository.
- Jenkins automatically starts the pipeline.
- SonarQube performs a static code analysis.
- If all tests pass, the code is deployed to Docker on AWS EC2.
Feel free to submit issues or pull requests for enhancements or bug fixes.
This project is licensed under the MIT License.