Week #09: DevOps Learning Journey - Full Stack CICD DevOps Project | Virtual Browser DevOps Project

Week #09: DevOps Learning Journey - Full Stack CICD DevOps Project | Virtual Browser DevOps Project

This week, I embarked on an exciting full-stack DevOps project focusing on a Virtual Browser setup. Below is a step-by-step breakdown of the process, from setting up an AWS instance to deploying a fully functional virtual browser application using Jenkins, Docker, and SonarQube.


Step 1: AWS Free Tier Account

Begin by creating an AWS Free Tier account if you don’t already have one. This will provide the necessary computing resources, such as EC2 instances, to host our DevOps project.

  1. Go to AWS Free Tier.

  2. Sign up and configure your account.

  3. Launch an EC2 instance with Ubuntu 22.04 LTS.


Step 2: Connect to Your EC2 Instance

Access your EC2 instance using SSH or AWS Connect.

Using SSH:

  1. Download the key pair provided during instance creation.

  2. Connect using:

     ssh -i "keypair.pem" ubuntu@<EC2_Public_IP>
    

Using AWS Connect:

  1. Navigate to the EC2 dashboard.

  2. Use the "Connect" feature to access the terminal directly in the AWS console.


Step 3: Update System Packages

Update all system packages to their latest versions:

sudo apt update && sudo apt upgrade -y

Step 4: Install Java 17

Jenkins requires Java. Install OpenJDK 17:

sudo apt install openjdk-17-jdk -y

Verify the installation:

java -version

Step 5: Install Jenkins

Add the Jenkins repository and install Jenkins:

curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key | sudo tee "/usr/share/keyrings/jenkins-keyring.asc" > /dev/null
sudo sh -c 'echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] https://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
sudo apt update
sudo apt install jenkins -y

Step 6: Run Jenkins in Detached Mode

Start Jenkins in detached mode:

sudo systemctl start jenkins
sudo systemctl enable jenkins

Step 7: Configure Jenkins

  1. Access Jenkins at http://<EC2_Public_IP>:8080.

  2. Unlock Jenkins using the password in:

     sudo cat /var/lib/jenkins/secrets/initialAdminPassword
    
  3. Install the suggested plugins.


Step 8: Install Necessary Plugins

Install the following plugins in Jenkins:

  • Docker

  • SonarQube

  • Pipeline Stage View

  • OWASP Dependency-Check

  • Docker Pipeline

  • Git


Step 9: Install Docker

Install Docker to run containers:

sudo apt install docker.io -y

Verify the installation:

docker --version

Step 10: Install Docker Compose

Install Docker Compose for managing multi-container applications:

sudo apt install docker-compose -y

Step 11: Change Docker Socket Permissions

Allow Jenkins to access the Docker socket:

sudo chmod 777 /var/run/docker.sock

Step 12: Run SonarQube Container

Run a SonarQube container in detached mode:

docker run -d -p 9000:9000 sonarqube

Step 13: Configure Jenkins Tools

  1. SonarQube:

    • Add SonarQube credentials as a secret text.

    • Configure SonarQube in "Manage Jenkins" > "Global Tool Configuration."

  2. OWASP Dependency-Check:

    • Install and configure the OWASP Dependency-Check tool.
  3. Docker:

    • Ensure Jenkins has access to Docker.

Step 14: Create a Pipeline Job

  1. In Jenkins, create a new pipeline job.

  2. Use the following repository: GitHub Repo.


Step 15: Write the Pipeline Code

Add the following pipeline code to automate the CI/CD process:

pipeline {
    agent any
    tools {
        jdk 'Java17'
        sonarQube 'SonarQube'
    }
    stages {
        stage('Checkout Code') {
            steps {
                git url: 'https://github.com/MuneebProblemSolver/Virtual-Browser', branch: 'main'
            }
        }
        stage('Dependency Check') {
            steps {
                sh 'dependency-check.sh'
            }
        }
        stage('SonarQube Analysis') {
            steps {
                withSonarQubeEnv('SonarQube') {
                    sh 'mvn sonar:sonar'
                }
            }
        }
        stage('Docker Build and Tag') {
            steps {
                sh 'docker build -t virtual-browser:latest .'
                sh 'docker tag virtual-browser:latest <your-docker-repo>/virtual-browser:latest'
            }
        }
        stage('Trivy Scan') {
            steps {
                sh 'trivy image virtual-browser:latest'
            }
        }
        stage('Deploy with Docker Compose') {
            steps {
                sh 'docker-compose up -d'
            }
        }
    }
}

Step 16: Execute and Build the Pipeline

  1. Save the pipeline and execute the build.

  2. Monitor the stages to ensure they are completed successfully.


Step 17: Access the Application

  1. Use the EC2 public IP and navigate to:

     http://<EC2_Public_IP>:8080/
    
  2. The Virtual Browser application (Neko) should now be running.


This project combines essential DevOps tools and practices, offering a hands-on approach to continuous integration and deployment. By completing it, you will solidify your understanding of a full-stack DevOps workflow.