Table of contents
- ULTIMATE CICD PIPELINE PROJECT ๐
ULTIMATE CICD PIPELINE PROJECT ๐
PHASE 1: INFRASTRUCTURE SETUP ๐ ๏ธ
1. Creating 3 Ubuntu 24.04 VM Instances on AWS ๐
Sign in to the AWS Management Console:
Go to AWS Management Console.
Sign in with your AWS account credentials.
Navigate to EC2:
- Type "EC2" in the search bar or select "Services" > "EC2" under the "Compute" section.
Launch Instance:
Click "Instances" in the EC2 dashboard sidebar.
Click the "Launch Instance" button.
Choose an Amazon Machine Image (AMI):
Select "Ubuntu" from the list of available AMIs.
Choose "Ubuntu Server 24.04 LTS".
Click "Select".
Choose an Instance Type:
Select an instance type (e.g., t2.micro for testing).
Click "Next: Configure Instance Details".
Configure Instance Details:
Configure optional settings or leave them as default.
Click "Next: Add Storage".
Add Storage:
Specify the root volume size (default is usually fine).
Click "Next: Add Tags".
Add Tags:
Optionally, add tags for better organization.
Click "Next: Configure Security Group".
Configure Security Group:
Allow SSH access (port 22) from your IP address.
Optionally, allow other ports (e.g., HTTP port 80, HTTPS port 443).
Click "Review and Launch".
Review and Launch:
Review the instance configuration.
Click "Launch".
Select Key Pair:
Select an existing key pair or create a new one.
Check the acknowledgment box.
Click "Launch Instances".
Access Your Instance:
Use an SSH client like MobaXterm:
Open MobaXterm and click "Session" > "SSH".
Enter the public IP address of your instance.
Select "Specify username" and enter "ubuntu".
Under "Advanced SSH settings", select "Use private key" and browse to your key pair file (.pem).
Click "OK" to connect.
2. Install Docker on All 3 VMs ๐ณ
Step-by-Step Installation:
Install prerequisite packages:
sudo apt-get update sudo apt-get install ca-certificates curl
Download and add Docker's official GPG key:
sudo install -m 0755 -d /etc/apt/keyrings sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc sudo chmod a+r /etc/apt/keyrings/docker.asc
Add Docker repository to Apt sources:
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
Update package index:
sudo apt-get update
Install Docker packages:
sudo apt-get install docker-ce docker-ce-cli containerd.io -y
Grant permission to Docker socket (optional, for convenience):
sudo chmod 666 /var/run/docker.sock
By following these steps, you should have successfully installed Docker on your Ubuntu system. You can now start using Docker to containerize and manage your applications.
Setting Up Jenkins on Ubuntu ๐ง
Step-by-Step Installation:
Update the system:
sudo apt-get update sudo apt-get upgrade -y
Install Java (Jenkins requires Java):
sudo apt install -y fontconfig openjdk-17-jre
Add Jenkins repository key:
sudo wget -O /usr/share/keyrings/jenkins-keyring.asc https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key
Add Jenkins repository:
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
Update the package index:
sudo apt-get update
Install Jenkins:
sudo apt-get install -y jenkins
Start and enable Jenkins:
sudo systemctl start jenkins sudo systemctl enable jenkins
Access Jenkins:
Open a web browser and go to http://your_server_ip_or_domain:8080.
You will see a page asking for the initial admin password. Retrieve it using:
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
Enter the password, install suggested plugins, and create your first admin user.
Installing Trivy on Jenkins Server ๐
Step-by-Step Installation:
Install prerequisite packages:
sudo apt-get install wget apt-transport-https gnupg lsb-release
Add Trivy repository key:
wget -qO - https://aquasecurity.github.io/trivy-repo/deb/public.key | sudo apt-key add -
Add Trivy repository to sources:
echo deb https://aquasecurity.github.io/trivy-repo/deb $(lsb_release -sc) main | sudo tee -a /etc/apt/sources.list.d/trivy.list
Update package index:
sudo apt-get update
Install Trivy:
sudo apt-get install trivy
Setting Up Nexus Repository Manager Using Docker ๐ฆ
Step-by-Step Installation:
Pull the Nexus Docker image:
sudo docker pull sonatype/nexus3
Run the Nexus container:
sudo docker run -d -p 8081:8081 --name nexus -v nexus-data:/nexus-data sonatype/nexus3
Access Nexus:
Open a web browser and go to http://your_server_ip_or_domain:8081.
The default username is
admin
. Retrieve the initial admin password from the log:sudo docker logs nexus 2>&1 | grep -i password
Complete the setup wizard.
Setting Up SonarQube Using Docker ๐
Step-by-Step Installation:
Create a network for SonarQube and PostgreSQL:
sudo docker network create sonarnet
Run PostgreSQL container:
sudo docker run -d --name sonarqube_db --network sonarnet -e POSTGRES_USER=sonar -e POSTGRES_PASSWORD=sonar -e POSTGRES_DB=sonarqube -v postgresql:/var/lib/postgresql -v postgresql_data:/var/lib/postgresql/data postgres:latest
Run SonarQube container:
sudo docker run -d --name sonarqube --network sonarnet -p 9000:9000 -e sonar.jdbc.url=jdbc:postgresql://sonarqube_db:5432/sonarqube -e sonar.jdbc.username=sonar -e sonar.jdbc.password=sonar -v sonarqube_data:/opt/sonarqube/data -v sonarqube_extensions:/opt/sonarqube/extensions -v sonarqube_logs:/opt/sonarqube/logs sonarqube:latest
Access SonarQube:
Open a web browser and go to http://your_server_ip_or_domain:9000.
The default username and password are both
admin
.
PHASE 2: SOURCE CODE SETUP ๐
Project Repo: https://github.com/jaiswaladi246/Mission.git
Creating a Private Repository on GitHub and Pushing Source Code Using Git Bash ๐
Part 1: Create a Private Repository on GitHub
Sign in to GitHub:
Go to GitHub.
Sign in with your GitHub account credentials.
Create a New Repository:
Click the "+" icon in the top-right corner and select "New repository".
Name your repository (e.g.,
my-private-repo
).Set the repository to "Private".
Optionally, add a description.
Click "Create repository".
Part 2: Push Source Code Using Git Bash
Clone the existing repository:
git clone https://github.com/jaiswaladi246/Mission.git cd Mission
Add the private repository as a remote:
git remote add private-repo https://github.com/your-username/my-private-repo.git
Push the code to the private repository:
git push private-repo main
Automating Docker Builds and Pushes in Jenkins Pipeline โ๏ธ
Pipeline Script for Jenkinsfile:
pipeline {
agent any
stages {
stage('Checkout') {
steps {
git 'https://github.com/jaiswaladi246/Mission.git'
}
}
stage('Build Docker Image') {
steps {
script {
dockerImage = docker.build("my-image:${env.BUILD_ID}")
}
}
}
stage('Push Docker Image') {
steps {
script {
docker.withRegistry('https://registry.hub.docker.com', 'docker-hub-credentials-id') {
dockerImage.push("${env.BUILD_ID}")
}
}
}
}
}
}
Step-by-Step Guide:
Access Jenkins:
Create a New Pipeline Job:
Click "New Item".
Enter a name (e.g.,
Docker-Pipeline
).Select "Pipeline" and click "OK".
Configure the Pipeline:
Under "Pipeline", select "Pipeline script".
Copy and paste the provided Jenkinsfile script.
Click "Save".
Run the Pipeline:
- Click "Build Now" to start the pipeline.
That's it! You have now set up a complete CI/CD pipeline with Docker, Jenkins, Trivy, Nexus, and SonarQube on Ubuntu VMs. Congratulations on your progress and happy DevOps journey! ๐