---
# System prepended metadata

title: CI/CD Pipeline

---

## Whats is CI/CD pipeline?![](https://hackmd.io/_uploads/r1tkclbs3.jpg)

1. Once developer pushes code on version control(e.g. github, bitbucket), Jenkins tests the committed code and builds it and make a docker images.
2. This image is then pushed to docker hub or aws.
3. All this is autonomous.

**What after jenkins pushes docker images to docker hub?**
When codes are run on robot using Kubernetes, it pull the latest docker images automatically from docker hub or aws. With this new code is deployed on bot.



# CI/CD pipeline is implementation:

## Step 1: AWS setup

Before proceding with AWS and Jenkins setup, go through the following video for better understanding (it is not related to robotics though):  https://www.youtube.com/watch?v=rcZoPygiI8o&t=885s

Login to aws and create new EC2 instance name is CI/CD pipeline 

While creating EC2 instance in aws:

1. Select device as ubuntu. Select instance type, here it shows how many CPU we want and RAM required for the operation. I am using "t3.micro" which comes with 2vCPU and 1GB Memory. "vCPU" stand for virtual CPU. t3.micro is free to use. 

2. In key pair login section. Choose "create new key pair" and go ahead to create new key pair. Pem file will be downloaded in Downloads folder.

3. In Network settings. Go to Firewall, keep it on. Launch instance.
4. Go to instances new instance will appear which is just created. Select that and click on "Connect". A ubuntu terminal will open. 
5. In the terminal **install Jenkins and enable using install guide**
6. **Install docker engine** using Docker installation guide.
7. open -> 
`sudo nano /etc/sudoers` 
8. Add "jenkins ALL = NOPASSWD: ALL" in the above file and save it (jenkins will have access to run code).
9. **IMPORTANT:** All docker images are going to be built in this EC2 instance so we need sufficient RAM and Storage.

## Step 2: Jenkins setup:

To get some idea about pipeline see:
https://medium.com/codex/how-to-push-a-docker-image-to-docker-hub-using-jenkins-487fb1fcbe25

1. Go to EC2 intance created in step 1. 
2. Go to security, you will see inbound rules. Click on "launch-wizard" option
3. Go to "Edit inbound rules" then Add rule. In this inbound rule enter 8080 in port range. In source select "My ip". Jenkins run on port 8080.
4. Save rules
5. Open jenkins with "https://intance-ip:8080", instance-ip is EC2 public ip.
6. It will ask for Administration password.
7. In aws terminal
`cat /var/lib/jenkins/secrets/initialAdminPassword`
8. Above command will give the required password.
9. Install suggested plugins.
10. Create jenkins account.
11. Setup docker credentials as described in the above article.
12. Create new item and add git credentials and select git branch as well.
13. While creating select "GitHub hook trigger for GITcm polling". It will trigger Jenkins every it sees git commit.
14.  

## Step 3: Git setup

1. Go to github repo. Add a webhook.
2. Add ip as instance-ip/github-webhook



## Docker installation

1. Docker needs to be install on EC2 instance, Laptop and on Jetson
2. For installing docker on aws instance, laptop and jetson follow "apt method" from the following link and verify by running "hello world" docker image.
https://docs.docker.com/engine/install/ubuntu/



## Jenkins installation guide:(on aws terminal)
```
sudo apt update
```
Jenkins needs Java, install by following:
```
sudo apt install openjdk-11-jre
```
```
java -version
```
```
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 
```
```
sudo apt-get install jenkins
```
Start Jenkins:
```
sudo systemctl enable jenkins
```

```
sudo systemctl start jenkins
```

```
sudo systemctl status jenkins
```

## **About continous integration (CI):**

1. There will one master branch on git. Where already tested code will be present. 
2. Each develop will have their own git branch. They can do their development on their branch. After they develop some code it will be tested on robot first.
3.  If test is successfull. Their branch will then be merged to master branch. Once master see changes it will automatically deployed master branch code on robots.