# Automating Tetris Deployments: DevSecOps with ArgoCD, Terraform, and Jenkins for Two Game Versions

<figure><img src="/files/ZzGHdWPNulQ6SmAhsYMS" alt="" width="563"><figcaption></figcaption></figure>

<figure><img src="/files/QAvwSDH6kYCYX6odixUQ" alt=""><figcaption></figcaption></figure>

## What is the argo CD ?

Argo CD is an open-source declarative continuous delivery (CD) tool for Kubernetes applications. It is designed to automate the deployment and continuous delivery of applications running on Kubernetes clusters. Argo CD helps manage the configuration of applications, ensuring that they are deployed and maintained consistently across different environments.

## **Prerequisites:**

1. **AWS Account:** To get started, you'll need an active AWS account. Ensure that you have access and permission to create and manage AWS resources.
2. **AWS CLI:** Install the AWS Command Line Interface (CLI) on your local machine and configure it with your AWS credentials. This is essential for managing your AWS resources.
3. **IAM User and Key Pair:** Create an IAM (Identity and Access Management) user with the necessary permissions to provision resources on AWS. Additionally, generate an IAM Access Key and Secret Access Key for programmatic access. Ensure that you securely manage these credentials.
4. **S3 Bucket:** Set up an S3 bucket to store your Terraform state files. This bucket is crucial for maintaining the state of your infrastructure and enabling collaboration.
5. **Terraform:** Install Terraform on your local machine. Terraform is used for provisioning infrastructure as code and managing AWS resources. Make sure to configure Terraform to work with your AWS credentials and your S3 bucket for state storage.

<figure><img src="/files/29lTAz6h0GL9ZUyHlHy3" alt=""><figcaption></figcaption></figure>

## **Step1: How to install and setup Terraform on Windows** <a href="#heading-step1-how-to-install-and-setup-terraform-on-windows" id="heading-step1-how-to-install-and-setup-terraform-on-windows"></a>

### **Download Terraform:**

Visit the official Terraform website: [**terraform.io/downloads.html**](https://www.terraform.io/downloads.html)

**Extract the ZIP Archive**:

Once the download is complete, extract the contents of the ZIP archive to a directory on your computer. You can use a tool like 7-Zip or the built-in Windows extraction tool. Ensure that you extract it to a directory that's part of your system's PATH.

Remember that I created a Terraform Directory in C drive

Extracted to C drive  ->   Copy the path

**Add Terraform to Your System's PATH**:

To make Terraform easily accessible from the command prompt, add the directory where Terraform is extracted to your system's PATH environment variable. Follow these steps:

Search for "Environment Variables" in your Windows search bar and click "Edit the system environment variables."

In the "System Properties" window, click the "Environment Variables" button.

Under "User variables for Admin," find the "Path" variable and click "Edit."

Click on New paste the copied path and click on OK

Under "System variables," find the "Path" variable and click "Edit."

Click "New" and add the path to the directory where you extracted Terraform (e.g., C:\path\to\terraform)

Click "OK" to close the Environment Variables windows.

Click "OK" again to close the System Properties window.

**Verify the Installation:**

Open a new Command Prompt or PowerShell window.

Type terraform --version and press Enter. This command should display the Terraform version, confirming that Terraform is installed and in your PATH.

<figure><img src="/files/tGbjaeu30KI524WCknAU" alt=""><figcaption></figcaption></figure>

## Step2: Download the AWS CLI Installer: <a href="#heading-step2-download-the-aws-cli-installer" id="heading-step2-download-the-aws-cli-installer"></a>

Visit the AWS CLI Downloads page: [**aws.amazon.com/cli**](https://aws.amazon.com/cli/)

Under "Install the AWS CLI," click on the "64-bit" link to download the AWS CLI installer for Windows.

### **Run the Installer: - >** Click on install ->  Click Finish Aws cli is installed

<figure><img src="/files/c3rD40duswGHq5pr9kao" alt="" width="430"><figcaption></figcaption></figure>

**Verify the Installation:**

Open a Command Prompt or PowerShell window.

Type **aws --version** and press Enter. This command should display the AWS CLI version, confirming that the installation was successful.

<figure><img src="/files/mZSoq6nl4qwJsP1klPMD" alt=""><figcaption></figcaption></figure>

## Step3: create an IAM user <a href="#heading-step3-create-an-iam-user" id="heading-step3-create-an-iam-user"></a>

Navigate to the **AWS console**

Click the "Search" field. ->  Search for IAM   ->  Click "Users  ->  Click "Add users"  ->   Click the "User name" field.   ->  Type "Terraform" or as you wish about the name ->  Click Next  ->  Click "Attach policies directly"    ->  Click "Attach policies directly"   ->  Click "Next"  \
&#x20;

<figure><img src="/files/yY0vJ7Ji5M3wtEjAs6MR" alt=""><figcaption></figcaption></figure>

goto security Credentials  ->  Create access & secreate acccess key  -> Click this  button with the CLI  ->  Agree to terms  ->  Click "Create access key"  -> Download .csv file&#x20;

<figure><img src="/files/YUGfshqdRutwJlbnGW5L" alt=""><figcaption></figcaption></figure>

## Step4: Aws Configure <a href="#heading-step4-aws-configure" id="heading-step4-aws-configure"></a>

Go to vs code or Cmd your wish

<figure><img src="/files/aoNUwXBtTpv5TYjTXdC7" alt=""><figcaption></figcaption></figure>

## Step5: Terraform files and Provision <a href="#heading-step5-terraform-files-and-provision" id="heading-step5-terraform-files-and-provision"></a>

CHANGE YOUR S3 BUCKET NAME IN THE  BACKEND.TF

Clone the repository to your local file explorer

```
https://github.com/Bhushan0151/Tetris-V1.git
cd Tetris-V1
cd Jenkins-terraform
ls #to see files
```

<figure><img src="/files/NGhH2Syfuw7rLnN43Rbm" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/kchRzoi7rNEZMQ5H0gaM" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/3xjEIfJ7MPZ5MvMioBLa" alt=""><figcaption></figcaption></figure>

Now you can see the terraform files to provision the AWS Ec2 with Jenkins installed,sonarqube container and Trivy, Aws cli,Kubectl and terraform

<figure><img src="/files/OxQbb844YDQUGP8fARrg" alt=""><figcaption></figcaption></figure>

#### install.sh

**Shell script**

````
```shellscript

#!/bin/bash
sudo apt update -y
sudo apt install fontconfig openjdk-17-jre -y
sudo wget -O /usr/share/keyrings/jenkins-keyring.asc \
  https://pkg.jenkins.io/debian/jenkins.io-2023.key
echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] https://pkg.jenkins.io/debian 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 start jenkins
sudo systemctl status jenkins
sudo systemctl enable jenkins

#install docker
sudo apt-get update
sudo apt-get install docker.io -y
sudo usermod -aG docker ubuntu  
newgrp docker
sudo chmod 777 /var/run/docker.sock
docker run -d --name sonar -p 9000:9000 sonarqube:lts-community

#install trivy
sudo apt-get install wget apt-transport-https gnupg lsb-release -y
wget -qO - https://aquasecurity.github.io/trivy-repo/deb/public.key | gpg --dearmor | sudo tee /usr/share/keyrings/trivy.gpg > /dev/null
echo "deb [signed-by=/usr/share/keyrings/trivy.gpg] https://aquasecurity.github.io/trivy-repo/deb $(lsb_release -sc) main" | sudo tee -a /etc/apt/sources.list.d/trivy.list
sudo apt-get update
sudo apt-get install trivy -y


#install terraform
sudo apt install wget -y
wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list
sudo apt update && sudo apt install terraform

#install Kubectl on Jenkins
sudo apt update
sudo apt install curl -y
curl -LO https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
kubectl version --client

#install Aws cli 
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
sudo apt-get install unzip -y
unzip awscliv2.zip
sudo ./aws/install


```
````

Now inside the Jenkins-terraform directory

## Open the terminal and provide the below commands

```
terraform init
terraform validate
terraform plan
terraform apply --auto-approve

```

<figure><img src="/files/Ju1BQDE4ngsViFH53Af4" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/ryuVXJB4OqnGXSewbeq3" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/UDCCBcI38rKPAKu0NKah" alt=""><figcaption></figcaption></figure>

## Apply completed you can see Ec2 is created in the Aws console

<figure><img src="/files/fKRt9Z3kCKoMDOzaGlVl" alt=""><figcaption></figcaption></figure>

### Now copy the public IP address of ec2 and paste it into the browser

```
<Ec2-ip:8080> #you will Jenkins login page
```

<figure><img src="/files/joVEX08s3tyqPnYF2t2m" alt=""><figcaption></figcaption></figure>

```
    sudo cat /var/lib/jenkins/secrets/initialAdminPassword
```

<figure><img src="/files/9ooxMneAEozfZeQ9TywI" alt=""><figcaption></figcaption></figure>

**Jenkins Console -**

<figure><img src="/files/2xG2rNNhJMmSQEm5Zm7c" alt=""><figcaption></figcaption></figure>

### Now Copy the public IP again and paste it into a new tab in the browser with 9000

```
<ec2-ip:9000>  #runs sonar container
```

<figure><img src="/files/gCzxqIr05LKFBQ8R20ze" alt=""><figcaption></figcaption></figure>

```
username admin
password admin
```

<figure><img src="/files/Paik4rJKost8BgNlMHbc" alt=""><figcaption></figcaption></figure>

### Now go to Putty and see whether it's installed Trivy, Terraform, Aws cli, Kubectl or not.

```
trivy --version 
aws --version
terraform --version
kubectl version

```

<figure><img src="/files/jGOO3oPBlkbqmdtdhmy2" alt=""><figcaption></figcaption></figure>

That is done now go to Jenkins and add a terraform plugin to provision the AWS EKS using the Pipeline Job.

Go to Jenkins dashboard --> Manage Jenkins --> Plugins

Available Plugins, Search for Terraform and install it.

<figure><img src="/files/KCTLEkU5lTx6bWLZlLhO" alt=""><figcaption></figcaption></figure>

Go to Putty and use the below command

let's find the path to our Terraform (we will use it in the tools section of Terraform)

```
which terraform

```

<figure><img src="/files/ihl8VzONhEuRaYg3yq1a" alt=""><figcaption></figcaption></figure>

Now come back to Manage Jenkins --> Tools

Add the terraform in Tools

<figure><img src="/files/3iGRe4v0831OBUo12Sso" alt=""><figcaption></figcaption></figure>

Apply and save.

CHANGE YOUR S3 BUCKET NAME IN THE BACKEND.TF

## Step 6 : Now create a new job for the Eks provision

```
pipeline{
    agent any
    stages {
        stage('Checkout from Git'){
            steps{
                git branch: 'main', url: 'https://github.com/Bhushan0151/Tetris-V1.git'
            }
        }
        stage('Terraform version'){
             steps{
                 sh 'terraform --version'
             }
        }
        stage('Terraform init'){
             steps{
                 dir('Eks-terraform') {
                      sh 'terraform init'
                   }      
             }
        }
        stage('Terraform validate'){
             steps{
                 dir('Eks-terraform') {
                      sh 'terraform validate'
                   }      
             }
        }
        stage('Terraform plan'){
             steps{
                 dir('Eks-terraform') {
                      sh 'terraform plan'
                   }      
             }
        }
        stage('Terraform apply/destroy'){
             steps{
                 dir('Eks-terraform') {
                      sh 'terraform ${action} --auto-approve'
                   }      
             }
        }
    }
}

```

<figure><img src="/files/b2g7nssG3uFzli7uHLw4" alt=""><figcaption></figcaption></figure>

Check in Your Aws console whether it created EKS or not.

<figure><img src="/files/NJzYh3GwEYkS0jnieOQF" alt=""><figcaption></figcaption></figure>

Ec2 instance is created for the Node group

<figure><img src="/files/TdKsleqVLlNRITBAdbhE" alt=""><figcaption></figcaption></figure>

Now let's build Tetris version 1

We need some plugins to complete this process

Go to Jenkins dashboard

Manage Jenkins --> Plugins --> Available Plugins

Search for the Below Plugins

`Eclipse Temurin installer`

`Sonarqube Scanner`

`NodeJs`

`Owasp Dependency-Check`

`Docker`

`Docker Commons`

`Docker Pipeline`

`Docker API`

`Docker-build-step`

<figure><img src="/files/YFcczbj1gOfI50vdYD2b" alt=""><figcaption></figcaption></figure>

### **Configure in Global Tool Configuration** <a href="#heading-configure-in-global-tool-configuration" id="heading-configure-in-global-tool-configuration"></a>

Goto Manage Jenkins → Tools → Install JDK(17) and NodeJs(16)→ Click on Apply and Save

<figure><img src="/files/makcws1Vnk0E48RGuOT4" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/qGnsd6rBSFMZmZHcGYGF" alt=""><figcaption></figcaption></figure>

For Sonarqube use the latest version

<figure><img src="/files/4Xe6nPOM7Rax1U1JBWHp" alt=""><figcaption></figcaption></figure>

For Owasp use the 6.5.1 version

<figure><img src="/files/my9miHuLOF4Lf3bdQ4Ab" alt=""><figcaption></figcaption></figure>

Use the latest version of Docker

<figure><img src="/files/uZsms7IKSFxh4MImne79" alt=""><figcaption></figcaption></figure>

Click apply and save.

### **Configure Sonar Server in Manage Jenkins** <a href="#heading-configure-sonar-server-in-manage-jenkins" id="heading-configure-sonar-server-in-manage-jenkins"></a>

Grab the Public IP Address of your EC2 Instance, Sonarqube works on Port 9000, so \<Public IP>:9000.&#x20;

Goto your Sonarqube Server. Click on Administration → Security → Users → Click on Tokens and Update Token → Give it a name → and click on Generate Token -> click on update Token

<figure><img src="/files/t2ieYC1WtfvoXZjZK6TJ" alt=""><figcaption></figcaption></figure>

Create a token with a name and generate

<figure><img src="/files/y0RfsoS6YBaLOKItKvHA" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/zcbsK43e48uKvukWSB6b" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/FyonDqaTBbS0CDkwAnpf" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/nN6LMeXYCh9xtDZopG2e" alt=""><figcaption></figcaption></figure>

&#x20;  <br>

<figure><img src="/files/iKfesrpQbphO8cjAkYUY" alt="" width="394"><figcaption></figcaption></figure>

<figure><img src="/files/1HmtwhTFTuVL0kcrjzPb" alt=""><figcaption></figcaption></figure>

Now add Docker credentials to the Jenkins to log in and push the image

Manage Jenkins --> Credentials --> global --> add credential

Add DockerHub Username and Password under Global Credentials

<figure><img src="/files/SBCmvWnOLk98DaJO1QmE" alt=""><figcaption></figcaption></figure>

## <mark style="color:orange;">Version 1.0</mark> <a href="#heading-version-10" id="heading-version-10"></a>

<figure><img src="/files/IzPH39BpS7NKVyqC8jPa" alt="" width="300"><figcaption></figcaption></figure>

## Task 1 : Now let's create a new job for our pipeline

<figure><img src="/files/gh9cQWCAT2qCpVnegJ5u" alt=""><figcaption></figcaption></figure>

```
pipeline{
    agent any
    tools{
        jdk 'jdk17'
        nodejs 'node16'
    }
    environment {
        SCANNER_HOME=tool 'sonar-scanner'
    }
    stages {
        stage('clean workspace'){
            steps{
                cleanWs()
            }
        }
        stage('Checkout from Git'){
            steps{
                git branch: 'main', url: 'https://github.com/Bhushan0151/Tetris-V1.git'
            }
        }
        stage("Sonarqube Analysis "){
            steps{
                withSonarQubeEnv('sonar-server') {
                    sh ''' $SCANNER_HOME/bin/sonar-scanner -Dsonar.projectName=TetrisVersion1.0 \
                    -Dsonar.projectKey=TetrisVersion1.0 '''
                }
            }
        }
        stage("quality gate"){
           steps {
                script {
                    waitForQualityGate abortPipeline: false, credentialsId: 'Sonar-token' 
                }
            } 
        }
        stage('Install Dependencies') {
            steps {
                sh "npm install"
            }
        }
        stage('OWASP FS SCAN') {
            steps {
                dependencyCheck additionalArguments: '--scan ./ --disableYarnAudit --disableNodeAudit', odcInstallation: 'DP-Check'
                dependencyCheckPublisher pattern: '**/dependency-check-report.xml'
            }
        }
        stage('TRIVY FS SCAN') {
            steps {
                sh "trivy fs . > trivyfs.txt"
            }
        }
        stage("Docker Build & Push"){
            steps{
                script{
                   withDockerRegistry(credentialsId: 'docker', toolName: 'docker'){   
                       sh "docker build -t tetrisv1 ."
                       sh "docker tag tetrisv1 bhushann11/tetrisv1:latest "
                       sh "docker push bhushann11/tetrisv1:latest "
                    }
                }
            }
        }
        stage("TRIVY"){
            steps{
                sh "trivy image bhushann11/tetrisv1:latest > trivyimage.txt" 
            }
        }
    }
}

```

Click on Apply and save.

Build now

### Stage view

<figure><img src="/files/yT2jBKzqdbnoVEYZIOkU" alt=""><figcaption></figcaption></figure>

### To see the report, you can go to Sonarqube Server and go to Projects.

<figure><img src="/files/cUhFOgjTypr531PnfkJu" alt=""><figcaption></figcaption></figure>

### When you log in to Dockerhub, you will see a new image is created

<figure><img src="/files/84QwIMyPPKrOKhwW2Jji" alt=""><figcaption></figcaption></figure>

## Task 2 : Let's create a GitHub Token. Go to GitHub

Click on Your Profile on the top right  ->   Now go down and search for Developer settings and click on it  ->  Now click on Personal Access tokens  ->  Click on Tokens (Classic)  ->  Click on Generate New token --> Generate new token (classic)  ->  Now it asks for access provide your GitHub password -> Now provide a name for the token  ->  Click on all check box  ->  Now click on Generate token ->  Now copy the token&#x20;

<figure><img src="/files/Ce0BmfuPWDkT4sY2JXdv" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/CAWQ1xyHVaCqVHfK1pXh" alt="" width="563"><figcaption></figcaption></figure>

<figure><img src="/files/GvPECs9u5p1yrsutkwbR" alt="" width="399"><figcaption></figcaption></figure>

<figure><img src="/files/eEzNsvjnvl3ZVb7vRlWU" alt="" width="374"><figcaption></figcaption></figure>

<figure><img src="/files/MRPq9YKGBfT37VoQIxY1" alt="" width="563"><figcaption></figcaption></figure>

<figure><img src="/files/vRff1HiVkSjPtY7ynGLd" alt="" width="563"><figcaption></figcaption></figure>

<figure><img src="/files/p30rtBeNByylsy3Ep32j" alt="" width="563"><figcaption></figcaption></figure>

### Now go to the Jenkins dashboard

Manage Jenkins --> credentials --> Global

Add credential

<figure><img src="/files/ZHw07kt4pZyFOD79U0kx" alt=""><figcaption></figcaption></figure>

### Let's add the Image Updater stage to the Pipeline

```
#add inside environment

 environment {
    GIT_REPO_NAME = "Tetris-manifest"
    GIT_USER_NAME = "Bhushan0151"      // change your  Github Username here
  }

# add these stages after trivy image scan 
        stage('Checkout Code') {
            steps {
                git branch: 'main', url: 'https://github.com/Bhushan0151/Tetris-manifest.git'
            }
        }
        stage('Update Deployment File') {
            steps {
                script {
                    withCredentials([string(credentialsId: 'github', variable: 'GITHUB_TOKEN')]) {
                       NEW_IMAGE_NAME = "bhushann11/tetrisv1:latest"   #update your image here
                       sh "sed -i 's|image: .*|image: $NEW_IMAGE_NAME|' deployment.yml"
                       sh 'git add deployment.yml'
                       sh "git commit -m 'Update deployment image to $NEW_IMAGE_NAME'"
                       sh "git push https://${GITHUB_TOKEN}@github.com/${GIT_USER_NAME}/${GIT_REPO_NAME} HEAD:main"
                    }
                }
            }
        }

```

<figure><img src="/files/JJFtpWeK4pcfrKCYW0B1" alt=""><figcaption></figcaption></figure>

### All Whole Pipeline - till here

```
pipeline{
    agent any
    tools{
        jdk 'jdk17'
        nodejs 'node16'
    }
    environment {
        SCANNER_HOME=tool 'sonar-scanner'
        GIT_REPO_NAME = "Tetris-manifest"
        GIT_USER_NAME = "Bhushan0151"      // change your  Github Username here
    }
    stages {
        stage('clean workspace'){
            steps{
                cleanWs()
            }
        }
        stage('Checkout from Git'){
            steps{
                git branch: 'main', url: 'https://github.com/Bhushan0151/Tetris-V1.git'
            }
        }
        stage("Sonarqube Analysis "){
            steps{
                withSonarQubeEnv('sonar-server') {
                    sh ''' $SCANNER_HOME/bin/sonar-scanner -Dsonar.projectName=TetrisVersion1.0 \
                    -Dsonar.projectKey=TetrisVersion1.0 '''
                }
            }
        }
        stage("quality gate"){
           steps {
                script {
                    waitForQualityGate abortPipeline: false, credentialsId: 'Sonar-token' 
                }
            } 
        }
        stage('Install Dependencies') {
            steps {
                sh "npm install"
            }
        }
        stage('OWASP FS SCAN') {
            steps {
                dependencyCheck additionalArguments: '--scan ./ --disableYarnAudit --disableNodeAudit', odcInstallation: 'DP-Check'
                dependencyCheckPublisher pattern: '**/dependency-check-report.xml'
            }
        }
        stage('TRIVY FS SCAN') {
            steps {
                sh "trivy fs . > trivyfs.txt"
            }
        }
        stage("Docker Build & Push"){
            steps{
                script{
                   withDockerRegistry(credentialsId: 'docker', toolName: 'docker'){   
                       sh "docker build -t tetrisv1 ."
                       sh "docker tag tetrisv1 bhushann11/tetrisv1:latest "
                       sh "docker push bhushann11/tetrisv1:latest "
                    }
                }
            }
        }
        stage("TRIVY"){
            steps{
                sh "trivy image bhushann11/tetrisv1:latest > trivyimage.txt" 
            }
        }
        
        stage('Manifest Checkout Code') {
            steps {
                git branch: 'main', url: 'https://github.com/Bhushan0151/Tetris-manifest.git'
            }
        }
        stage('Update Deployment File') {
            steps {
                script {
                    withCredentials([string(credentialsId: 'github', variable: 'GITHUB_TOKEN')]) {
                       NEW_IMAGE_NAME = "bhushann11/tetrisv1:latest"   //update your image here
                       sh "sed -i 's|image: .*|image: $NEW_IMAGE_NAME|' deployment.yml"
                       sh 'git add deployment.yml'
                       sh "git commit -m 'Update deployment image to $NEW_IMAGE_NAME'"
                       sh "git push https://${GITHUB_TOKEN}@github.com/${GIT_USER_NAME}/${GIT_REPO_NAME} HEAD:main"
                    }
                }
            }
        }
    }
}

```

<figure><img src="/files/q8yosUWEytcUYJ7QTEuP" alt=""><figcaption></figcaption></figure>

**SonarQube -**

<figure><img src="/files/4OEjh9ydNG4pS3cMbmrT" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/r3x00xsQQXJvJ4YCg3aj" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/UrwWbG8hVEJedSpcUAae" alt=""><figcaption></figcaption></figure>

## Task 3 : Let's Update the kubeconfig

Go to Putty of your Jenkins instance SSH and enter the below command

```
aws eks update-kubeconfig --name <CLUSTER NAME> --region <CLUSTER REGION>
aws eks update-kubeconfig --name EKS_CLOUD --region us-east-2

```

#### **Let's see the nodes**

```
kubectl get nodes
```

<figure><img src="/files/wCXUwvMJbpBWcsEUQxin" alt=""><figcaption></figcaption></figure>

## Task 4 : ARGO CD SETUP <a href="#heading-argo-cd-setup" id="heading-argo-cd-setup"></a>

Let's install ArgoCD

[**ARGOCD INSTALLATION LINK**](https://archive.eksworkshop.com/intermediate/290_argocd/install/)

You will redirected to this page

<figure><img src="/files/cT9jUTmz4GjgZM2Mmzn8" alt=""><figcaption></figcaption></figure>

All those components could be installed using a manifest provided by the Argo Project: use the below commands

```
kubectl create namespace argocd
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/v2.4.7/manifests/install.yaml

```

<figure><img src="/files/dbA8nFpGTAaFmhT4RENo" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/y4nP1t4BzKSEGrGiMK88" alt="" width="446"><figcaption></figcaption></figure>

### COMMANDS ARGOCD

By default, argocd-server is not publicly exposed. For this project, we will use a Load Balancer to make it usable:

```
kubectl patch svc argocd-server -n argocd -p '{"spec": {"type": "LoadBalancer"}}'

```

One load balancer will created in the AWS

<figure><img src="/files/CMkcQuwgOFgrs80Ngaqh" alt=""><figcaption></figcaption></figure>

Wait about 2 minutes for the LoadBalancer creation

```
sudo apt install jq -y
```

```
export ARGOCD_SERVER=`kubectl get svc argocd-server -n argocd -o json | jq --raw-output '.status.loadBalancer.ingress[0].hostname'`
```

when you run this command, it will export the hostname of the ArgoCD server's load balancer and store it in the `ARGOCD_SERVER` environment variable, which you can then use in other commands or scripts to interact with the ArgoCD server. This can be useful when you need to access the ArgoCD web UI or interact with the server programmatically.

<figure><img src="/files/FjMWcdEZlMR0fyGKiGaZ" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/Dx18nB5KiXB87anHm75z" alt=""><figcaption></figcaption></figure>

## Task 5 : Login <a href="#heading-login" id="heading-login"></a>

The command you provided is used to extract the password for the initial admin user of ArgoCD, decode it from base64 encoding, and store it in an environment variable named `ARGO_PWD`.

```
export ARGO_PWD=`kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath="{.data.password}" | base64 -d`
```

If you want to see your password provide the below command

```
echo $ARGO_PWD
```

<figure><img src="/files/BfcvL5wqufVwK2naoXtP" alt=""><figcaption></figcaption></figure>

Now copy the load balancer IP/dns name  and paste it into the browser

```
echo $ARGOCD_SERVER
```

Now you will see this page. if you get an error click on advanced and click on proceed.

<figure><img src="/files/EzRtyehnnTgIE8P1v6oN" alt=""><figcaption></figcaption></figure>

### Now you will see this page and log in to ArgoCD

<figure><img src="/files/maxgcT1zQDMyx3wuo4vb" alt=""><figcaption></figcaption></figure>

**Username is admin**

For the password, you have to provide the below command and copy it

```
echo $ARGO_PWD
```

<figure><img src="/files/Pg5vHDRGXaweNCpbd9or" alt="" width="401"><figcaption></figcaption></figure>

Er4iPybjOhKYnlvq

#### Click on Sign in and you will see this page.

<figure><img src="/files/w3G110Ld5UrUaUaLt251" alt=""><figcaption></figcaption></figure>

Now click on the Setting gear icon in the left side panel

<figure><img src="/files/LZ7ZSqO7iLqhqw8AATro" alt=""><figcaption></figcaption></figure>

Click on Repositories

<figure><img src="/files/HmwwOr8HRnqKddrymiKV" alt=""><figcaption></figcaption></figure>

Now click on Connect Repo Using HTTPS

<figure><img src="/files/XU9BYgbMzWf3PLn8WzC4" alt=""><figcaption></figcaption></figure>

Add Github details, Type as git, Project as default and provide the GitHub URL of this manifest and click on connect

<figure><img src="/files/wv9jOaLsVvTJnzdOcvuy" alt=""><figcaption></figcaption></figure>

You will get Connection Status as Successful

<figure><img src="/files/6TOh9D09qFYuZNfpcMc7" alt=""><figcaption></figcaption></figure>

Click on Manage Your application

<figure><img src="/files/aEsAP644TiQMyjv0uUX0" alt=""><figcaption></figcaption></figure>

### You will see this page and click on New App

Now provide the following details as in the image

<figure><img src="/files/7Wk8hvyqpZ3hm6DZ954M" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/hOxXmW1HvK6uewochlLL" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/1rKzsiC6wHTkBiQLqm3v" alt=""><figcaption></figcaption></figure>

Click on Create.

### You can see our app is created in Argo-cd

<figure><img src="/files/4KMSLK4bcsc9L04wTIzS" alt=""><figcaption></figcaption></figure>

### Click on tetris and it will create another load balancer in AWS

<figure><img src="/files/JxvU0SHiOlmLv6sj0SW4" alt=""><figcaption></figcaption></figure>

Now click on three dots beside tetris-service and click on the details

<figure><img src="/files/gf8HteZIi4uC1CjpdXbY" alt=""><figcaption></figcaption></figure>

Now copy the hostname address

<figure><img src="/files/KM1jHmgDdU1OzKvrMuwJ" alt=""><figcaption></figcaption></figure>

### Paste it in a browser you will see this page

<figure><img src="/files/VqPQdng6PRejkuRRDWzO" alt=""><figcaption></figcaption></figure>

## <mark style="color:green;">Output - Version 1.0</mark>

<figure><img src="/files/CPpQSnIaBYI47D6LaYF8" alt=""><figcaption></figcaption></figure>

```
kubectl get all
```

<figure><img src="/files/tLe5hem17DkHI9sTQssC" alt=""><figcaption></figcaption></figure>

## <mark style="color:orange;">Version 2.0</mark> <a href="#heading-version-20" id="heading-version-20"></a>

Let's Build version 2.0 Tetris game

<figure><img src="/files/v7ecyWiIk3eP6nSOyNJx" alt=""><figcaption></figcaption></figure>

## Task 1: Add this pipeline to the Job

```
pipeline{
    agent any
    tools{
        jdk 'jdk17'
        nodejs 'node16'
    }
    environment {
        SCANNER_HOME=tool 'sonar-scanner'
        GIT_REPO_NAME = "Tetris-manifest"
        GIT_USER_NAME = "Bhushan0151"      // change your Github Username here
    }
    stages {
        stage('clean workspace'){
            steps{
                cleanWs()
            }
        }
        stage('V2 - Checkout from Git'){
            steps{
                git branch: 'main', url: 'https://github.com/Bhushan0151/Tetris-V2.git'
            }
        }
        stage("Sonarqube Analysis "){
            steps{
                withSonarQubeEnv('sonar-server') {
                    sh ''' $SCANNER_HOME/bin/sonar-scanner -Dsonar.projectName=TetrisVersion2.0 \
                    -Dsonar.projectKey=TetrisVersion2.0 '''
                }
            }
        }
        stage("quality gate"){
           steps {
                script {
                    waitForQualityGate abortPipeline: false, credentialsId: 'Sonar-token' 
                }
            } 
        }
        stage('Install Dependencies') {
            steps {
                sh "npm install"
            }
        }
        stage('OWASP FS SCAN') {
            steps {
                dependencyCheck additionalArguments: '--scan ./ --disableYarnAudit --disableNodeAudit', odcInstallation: 'DP-Check'
                dependencyCheckPublisher pattern: '**/dependency-check-report.xml'
            }
        }
        stage('TRIVY FS SCAN') {
            steps {
                sh "trivy fs . > trivyfs.txt"
            }
        }
        stage("Docker Build & Push"){
            steps{
                script{
                   withDockerRegistry(credentialsId: 'docker', toolName: 'docker'){   
                       sh "docker build -t tetrisv2 ."
                       sh "docker tag tetrisv2 bhushann11/tetrisv2:latest "
                       sh "docker push bhushann11/tetrisv2:latest "
                    }
                }
            }
        }
        stage("TRIVY"){
            steps{
                sh "trivy image bhushann11/tetrisv2:latest > trivyimage.txt" 
            }
        }
        stage('Manifest Checkout Code') {
            steps {
                git branch: 'main', url: 'https://github.com/Bhushan0151/Tetris-manifest.git'
            }
        }
        stage('Update Deployment File') {
            steps {
                script {
                    withCredentials([string(credentialsId: 'github', variable: 'GITHUB_TOKEN')]) {
                       NEW_IMAGE_NAME = "bhushann11/tetrisv2:latest"  // update your image here
                       sh "sed -i 's|image: .*|image: $NEW_IMAGE_NAME|' deployment.yml"
                       sh 'git add deployment.yml'
                       sh "git commit -m 'Update deployment image to $NEW_IMAGE_NAME'"
                       sh "git push https://${GITHUB_TOKEN}@github.com/${GIT_USER_NAME}/${GIT_REPO_NAME} HEAD:main"
                    }
                }
            }
        }
    }
}

```

Click on Apply and build

### Stage view

<figure><img src="/files/0ajq22Tfs30GjGnOcQOp" alt=""><figcaption></figcaption></figure>

To see the report, you can go to Sonarqube Server and go to Projects

<figure><img src="/files/Ka9NiDwi9m0BRMTu2fyq" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/2swxtc9ZWaNvRC7ZKykr" alt=""><figcaption></figcaption></figure>

### When you log in to Dockerhub, you will see a new image is created

<figure><img src="/files/HhNVfa3mRKgu8L1ygtZt" alt=""><figcaption></figcaption></figure>

#### If you go to Argo CD Now it will automatically update is available of the version 2 image&#x20;

<figure><img src="/files/YmAyxRbltaYJGg4RybeS" alt=""><figcaption></figcaption></figure>

So we have to sync this, we will get output, with same link- we run the job or play the game with the same link

<figure><img src="/files/t1DvpsWlmfw6jJLHVR36" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/KTgnUL2zeBJeLrSmjUjc" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/9ppM89XqzUTSt4g39RUJ" alt=""><figcaption></figcaption></figure>

## <mark style="color:green;">OUTPUT - Version-2.0</mark> &#x20;

<figure><img src="/files/LJATzLNeJ3VZiI5eOpix" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/6BpOuhQmbfy38X1yLWSb" alt=""><figcaption></figcaption></figure>

## You can play version 2 in the browser now. Just refresh the old link

<figure><img src="/files/ruHTamtxJnPHqUn6ra7q" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://bhushans-devops-organization.gitbook.io/advanced-projects/automating-tetris-deployments-devsecops-with-argocd-terraform-and-jenkins-for-two-game-versions.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
