> For the complete documentation index, see [llms.txt](https://devops-maestro.gitbook.io/cicd-pipeline-using-jenkins-and-argocd/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://devops-maestro.gitbook.io/cicd-pipeline-using-jenkins-and-argocd/configure-ec2-instance-to-setup-the-ci-pipeline.md).

# Configure EC2 instance to setup the CI pipeline

To setup Docker, Jenkins and SonarQube (in next section) server, create a t2.large Ubuntu EC2 instance on AWS and use the below startup shell script to install the pre-requisites:

```sh
#!/bin/bash

sudo apt update

#Install JDK
sudo apt install openjdk-17-jre -y

#Install Jenkins
curl -fsSL https://pkg.jenkins.io/debian/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 binary/ | sudo tee \
  /etc/apt/sources.list.d/jenkins.list > /dev/null
sudo apt-get update
sudo apt-get install jenkins -y

# Install Docker
sudo apt install docker.io -y

# Grant Jenkins and Ubuntu user permission to access Docker daemon
sudo usermod -aG docker jenkins
sudo usermod -aG docker ubuntu
sudo systemctl restart docker
```

<figure><img src="https://3157512683-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSdKCeOdDbFafu1TTNFV5%2Fuploads%2FULyLn7Ep62rbK2KJbszg%2Fimage.png?alt=media&amp;token=d6d523a0-8f41-4a79-bd80-bcdd5f08b4e6" alt=""><figcaption><p>EC2 instance configuration to setup the CI server</p></figcaption></figure>

<figure><img src="https://3157512683-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSdKCeOdDbFafu1TTNFV5%2Fuploads%2FQ8FDesmoy3jATgaB04Qm%2Fimage.png?alt=media&amp;token=0e9c9600-a110-4c70-b445-46e66110d4c8" alt=""><figcaption><p>Adding the startup script to install the prerequisites</p></figcaption></figure>

#### Create a Security Group and allow the below ports under Inbound rules

| Type | Port | Used For            |
| ---- | ---- | ------------------- |
| SSH  | 22   | SSH to the instance |
| TCP  | 8010 | Application port    |
| TCP  | 8080 | Jenkins port        |
| TCP  | 9000 | SonarQube port      |

<figure><img src="https://3157512683-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSdKCeOdDbFafu1TTNFV5%2Fuploads%2FKblFpvSbXs9hqBISzinK%2Fimage.png?alt=media&amp;token=a6676340-385f-4794-9146-e62dbff0241d" alt=""><figcaption><p>Setting inbound rules for the instance</p></figcaption></figure>

After connecting to the EC2 instance verify whether JDK, Docker and Jenkins is properly installed using the following commands:

```sh
# Check java version
java --version

# Check Docker version
docker --version

# Check whether Jenkins is running
ps -ef | grep jenkins
```

<figure><img src="https://3157512683-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSdKCeOdDbFafu1TTNFV5%2Fuploads%2Fk3JrPsGzOmI9Moxvq2Lk%2Fimage.png?alt=media&amp;token=0c6fcbd5-d377-4797-8f8b-15866f76e68d" alt=""><figcaption></figcaption></figure>
