AWS Create 3 EC2 instances Step 1 - We will push the code the github Step 2 - Pull the code through jenkins Step 3 - Test the code via sonarqube - scans Step 4 - Deploy in Docker
Create an EC2 Instance for Jenkins with a key pair
Create an EC2 Instance for SonarQube and use the same key pair generated
Create an EC2 Instance for Docker and use the same key pair generated
SSH this cmd to get access to the Jenkins server(Use the instance public Ip as per intance generated)
ssh -i SSH-Key-Jenkins.pem ubuntu@52.23.182.224
sudo apt update
Then follow jenkins installation for Debian Ubuntu
sudo apt install openjdk-11-jre
curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key | sudo tee
/usr/share/keyrings/jenkins-keyring.asc > /dev/null
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 -y
sudo apt-get install jenkins -y
sudo systemctl enable jenkins
sudo systemctl start jenkins
sudo systemctl status jenkins
Now expose the port 8080 on jenkins ec2 instance -> Go to Security and edit inbound rules
Now open the public ip with port - http://52.23.182.224:8080/ - and enter the token copied
Add the Git repo URL in the Configuration
Also select GITScm to automatically triger the pipeline whenver we make changes in the repository
Add the Github Webhook in the github rep settings - Add the Jenkins url ip and port (http://34.224.39.140:8080/) and select ind events - pull reqs and pushes
We have automated the process till the Jenkins whenever we change or add the code in github repository it will trigger the jenkins automatically and Jenkins will pull automatically from the github
Log into the ssh for the SonarQube Instance
SSH this cmd to get access to the SonarQube server(Use the instance public Ip as per intance generated) - PublicIP - 3.84.220.33
ssh -i SSH-Key-Jenkins.pem ubuntu@54.221.137.114
sudo apt update
sudo apt install openjdk-17-jre
Download SonarQube using wget method and paste the download link
wget https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-10.1.0.73491.zip
sudo apt install unzip
unzip sonarqube-10.1.0.73491.zip
Open the sonarqube instance with its public ip and its port- Use admin and admin for username and pass
Go to Jenkins manage Plugins and install SonarQube Scanner and SSH2 Easy plugin
Now in the configure tools add the SonarQube Scanner
Go to configure systems and add the sonarqube server and paste the sonarqube url - http://54.221.137.114:9000/
Configure the project key in the sonarqube build steps
Add the token in the secret text dropdown under secret
Build and check the sonarqube report
Log into the docker ec2 instance
Install the docker from documention and add the credentials created and add the Docker group in jenkins
Add the docker Server in jenkins
Under the build steps chose the remote shell build step - and add a text file just to verify
Now build the pipeline and verify if the text file is created in the docker server
Create a dockerfile with Nginx image and store in repository also create a folder in docker
Add a build step execute shell - copy the contents to a location created in docker folder (scp ./* ubuntu@54.81.5.217:~/website/)
Make sure the docker is given permissions to run the cmds
Now in Jenkins in the build step add the remote shell content
Configure the ports 8085 and website is deployed with docker container - http://54.81.5.217:8085/