# Project 2: Implementation.

### Deploying web app using Jenkins CI/CD declarative pipeline.

**Follow the steps:**

1.     First of all, go to the AWS portal, and create a new instance. As

·       Name: jenkins-server

·       AMI: ubuntu.

·       Instance type: t2.micro (free tier).

·       Key pair login: Create &gt; docker.pem.

·       Allow HTTP.

·       Allow HTTPS.

·       (Download the .pem file.)

·       Click on Launch Instance.

2.    Now, we will allow ports 8080 and 8001 for this machine from a security group. We can find the security group in the VM description. Now, here we need to allow “Inbound Rule”

3.     Now, connect to the EC2 instance that you have created. Copy the SSH from server:

![No alt text provided for this image](https://media.licdn.com/dms/image/D4D12AQGUR9xE1rksMg/article-inline_image-shrink_1500_2232/0/1672492833940?e=1710374400&v=beta&t=LaCIqgBjUA8TNQvzUMlaUteiNwPwBreXJs8qCSkpEks align="left")

4.     Go to the download folder, where the .pem file is placed and open the terminal in the same location, and paste the SSH.

5.     Install Jenkins from following link:

[https://www.jenkins.io/doc/book/installing/linux/](https://www.jenkins.io/doc/book/installing/linux/)

6.     Install Docker by running:

“Sudo apt-install [docker.io](https://www.jenkins.io/doc/book/installing/linux/)”

7.     Now check if it got installed by running “jenkins --version” and “docker --version”

![No alt text provided for this image](https://media.licdn.com/dms/image/D4D12AQGU6sQQTFXCtA/article-inline_image-shrink_1500_2232/0/1672492884406?e=1710374400&v=beta&t=GhPpAF4ZIXT3wVy2sJfaEtZTojqWvPMDRqko2VhH0BU align="left")

8.     Goto Jenkins Dashboard and Click on “New Item”

·       Name: declarative\_pipeline

·       Select: Pipeline

Description: This is a demo pipeline project.

9.     Pipeline Script:

```bash
pipeline{

  agent any

    stages{

    stage{

    steps{

git branch: 'main', url: 'https://github.com/chxtan/react_django_demo_app.git'

          }

     }

 stage{

steps{

echo "Testing"

        }

    }

    stage{

      steps{

           script{

              sh "docker build --no-cache -t react_django_demo_app ."

                   }

            }

    }

stage{

        steps{

             script{

                  sh "docker run -p 8001:8001 -d react_django_demo_app"

                    }

               }

       }

  }

}
```

![No alt text provided for this image](https://media.licdn.com/dms/image/D4D12AQGIU-ySidwZ_w/article-inline_image-shrink_1500_2232/0/1672492924341?e=1710374400&v=beta&t=LZYKV2hxLsCnpVJE-rsL6E3k4FUKxtY-VCK7l3lZydI align="left")

10.  Click on “Save”.

11.  Click on “Build Now”.

![No alt text provided for this image](https://media.licdn.com/dms/image/D4D12AQFzJGGGU2gmSQ/article-inline_image-shrink_1000_1488/0/1672492968208?e=1710374400&v=beta&t=5gLHmyCJmTfrny8TfIo4Z14NthBhmQT8UNfDwKERjwk align="left")

12.  We can click on “Stage View” to check the results if it is still under process.

![No alt text provided for this image](https://media.licdn.com/dms/image/D4D12AQHR3-P6z7Hilg/article-inline_image-shrink_1500_2232/0/1672493015361?e=1710374400&v=beta&t=tQYbt9T_sdE73bB1RrjjJuC49xLQYc8L72Y9aoOvhMI align="left")

13.  Once it will be completed, It will return as “Success”.

![No alt text provided for this image](https://media.licdn.com/dms/image/D4D12AQEAjQXQxSsToA/article-inline_image-shrink_1000_1488/0/1672493031199?e=1710374400&v=beta&t=v6frO7mfWbOUvQ95l047NSV_NVbbEirkbtX2E_7XgRg align="left")

14.  Now, Search for the Public IP with port 8001 in the browser,

![No alt text provided for this image](https://media.licdn.com/dms/image/D4D12AQENQLeIdOX9Kg/article-inline_image-shrink_1500_2232/0/1672493056434?e=1710374400&v=beta&t=JuURrwo0VjY7n771hjTDNgpKSSKL3xj6lJ0WXsBDhzM align="left")

We have built the image of a Web app source code, and deployed that image as a container, using Jenkins Pipelines.
