Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Setting Up a CI/CD Pipeline with Jenkins, Docker, and AWS, Assignments of Computer Science

A comprehensive guide on setting up a ci/cd pipeline using jenkins, docker, and aws. It covers the essential steps involved in creating an ec2 instance, installing jenkins and maven, and configuring the pipeline to automate code integration, testing, and deployment. Particularly useful for students and professionals interested in devops practices and cloud-based infrastructure.

Typology: Assignments

2023/2024

Uploaded on 11/16/2024

ganeshmalyala
ganeshmalyala 🇮🇳

5 documents

1 / 20

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Introduction
The CI/CD (Continuous Integration Continuous Delivery/Deployment) Cycle – Code Build Test
Deploy is what we are going to do in the project today. We are going to build a CI/CD Pipeline
as a project today. The App will be built upon Node JS today.
Primary objective of the task that we are going to do that we want to accomplish the following
things in the project: -
Prerequisites for this project- Idea on Jenkins, Docker, AWS
Scenario – The Developer will give the code to GitHub. The Devops engineer needs to take the
code from the GitHub. The Devops engineer responsibility is to ensure that the code runs in
the AWS Environment. The code should be continuously integrated – This code should be
able to run on any cloud environment (CI will make sure this – the code should be integrated
(running) in any environment). The developer may have written the code in
Windows/Linux/MacOS, etc but the Devops engineer should ensure that the code runs on
any environment. Docker is the tool that will be used a virtualised environment. – Docker
helps regarding creating Virtualized container – Using docker we will confirm prove that this
code in running in multiple environments – Windows, Linux, MacOS.
The First tool is Docker
The code will be brought from GitHub
This code will be run on AWS EC2 Instance.
Our goal is to make a pipeline to ensure that this code runs properly integrated manner. This
pipeline should make sure that whatever developer is keeping the new code in GitHub, the
code should be brought from the github, docker needs to build the code using container
mechanism, and then this pipline should deliver the code on the AWS EC2 Instance
continuously. The tool to build this pipeline will be Jenkins.
1. After creating AWS Account, login to the account and then go to create an EC2 Instance
2. Click on “Launch a virtual machine”.
3. We have selected the EC2 Instance (server) as we need computing service for our project.
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14

Partial preview of the text

Download Setting Up a CI/CD Pipeline with Jenkins, Docker, and AWS and more Assignments Computer Science in PDF only on Docsity!

Introduction The CI/CD (Continuous Integration Continuous Delivery/Deployment) Cycle – Code Build Test Deploy is what we are going to do in the project today. We are going to build a CI/CD Pipeline as a project today. The App will be built upon Node JS today. Primary objective of the task that we are going to do that we want to accomplish the following things in the project: - Prerequisites for this project- Idea on Jenkins, Docker, AWS Scenario – The Developer will give the code to GitHub. The Devops engineer needs to take the code from the GitHub. The Devops engineer responsibility is to ensure that the code runs in the AWS Environment. The code should be continuously integrated – This code should be able to run on any cloud environment (CI will make sure this – the code should be integrated (running) in any environment). The developer may have written the code in Windows/Linux/MacOS, etc but the Devops engineer should ensure that the code runs on any environment. Docker is the tool that will be used a virtualised environment. – Docker helps regarding creating Virtualized container – Using docker we will confirm prove that this code in running in multiple environments – Windows, Linux, MacOS. The First tool is Docker The code will be brought from GitHub This code will be run on AWS EC2 Instance. Our goal is to make a pipeline to ensure that this code runs properly integrated manner. This pipeline should make sure that whatever developer is keeping the new code in GitHub, the code should be brought from the github, docker needs to build the code using container mechanism, and then this pipline should deliver the code on the AWS EC2 Instance continuously. The tool to build this pipeline will be Jenkins.

  1. After creating AWS Account, login to the account and then go to create an EC2 Instance
  2. Click on “Launch a virtual machine”.
  3. We have selected the EC2 Instance (server) as we need computing service for our project.
  1. Clicking on “Launch a virtual machine” will give the dialog box “Launch an instance” as below. Our whole project is going to run a. on Linux Server so select “Ubuntu” as the Amazon Machine Image. b. The CI/CD Pipeline will be made on Jenkins so give the name of the Instance as “Jenkins-master” c. Instance Type – select t3.micro – It is free tier - free for 750 hours per year.

Now that we have selected the server requirements, we have to connect to this server instance. So, create a new key pair.

  1. In the “Create new key pair” dialog box, for Windows, I am giving it a key pair name as “ganesh-live-project”. The key pair type is “RSA” and the Private
  1. Now that the Instance is launched, click on “Instances” on the left side menu -> Then select the checkbox of the Instance that we created i.e. “jenkins- master” -> Then click on the “Connect” button to connect to the Instance.
  2. In the dialog box “Connect to Instance”, select the Connection Type as “Connect using EC2 Instance Connect”
  3. Now for writing the pipeline, we must first install the Jenkins package on this server.
  4. Step - 1 Install Java – Java is required for installation of Jenkins, so we are installing this.

a. Update your system - sudo apt update b. Install java - sudo apt install openjdk-11-jre c. Validate Installation - java -version d. It should look something like this. e. openjdk version "11.0.12" 2021-07-20 OpenJDK Runtime Environment (build 11.0.12+7-post-Debian-2) OpenJDK 64-Bit Server VM (build 11.0.12+7-post-Debian- 2, mixed mode, sharing)

  1. Step - 2 Install Jenkins Just copy these commands and paste them onto your terminal. a. Key Generation – Before installing Jenkins, we need to first generate key from jenkins.io Jenkins uses AES to encrypt and protect secrets, credentials, and their respective encryption keys. curl -fsSL https://pkg.jenkins.io/debian/jenkins.io.key | sudo tee
    /usr/share/keyrings/jenkins-keyring.asc > /dev/null In the above command, we are first using curl to download Jenkins GPG key from the site https://pkg.jenkins.io/debian/jenkins.io.key. Then we are saving the downloaded Jenkins key to /usr/share/keyrings/jenkins- keyring.asc; This will be used for package authenticity verification. With > /dev/null, we are preventing the key from being displayed on the terminal. sudo wget -O /usr/share/keyrings/jenkins-keyring.asc
    https://pkg.jenkins.io/debian/jenkins.io-2023.key
  1. Step - 4 Open port 8080 from AWS Console: So now for accessing Jenkins on port 8080, we have to enable that using the below steps: a. Go to AWS Console and click on Network & Security -> Security Groups -> Then click on the Security Group as below. b. Next in the Inbound Rules page that is displayed, click on “Edit Inbound Rules”

c. Next click on “Add rule” button and Type as “Custom TCP”, Port Range as “8080” and the Source Type as “Anywhere-IPv4” (If we have a static public ip of our own at our home network, then we can give that for more security). Then click on the “Save rules” button. d. Now open the Public IP of the Instance in the browser and you will see Jenkins page as below e. Now copy the password from the location of the sudo cat /var/lib/Jenkins/secrets/initialAdminPassword and paste it

j. Copy and save the URL somewhere and then click on “Save and Finish” k. Then click on “Start using Jenkins” button.

Get Apache Maven package

Git is already installed with the suggested packages at the time of Jenkins installation itself so let us now install Maven. Get the binary with the command line, curl -LO https://dlcdn.apache.org/maven/maven-3/3.9.5/binaries/apache-maven-3.9.5- bin.tar.gz Extract it and do ls you can see the apache-maven-3.9.5 folder: tar xzf apache-maven-3.9.5-bin.tar.gz Set environment variables. Update PATH to include Maven bin: Then check mvn –version Now we see that the Apache Maven has been successfully installed.

Change Default port of Jenkins to 9090

First before making the changes Stop Jenkins sudo systemctl stop jenkins sudo systemctl status jenkins Next go to the file /etc/default/Jenkins using sudo vi /etc/default/jenkins Then scroll down till you see HTTP_PORT=8080 now change it to 9090 and do :wq! And save it. Start jenkins

a. sudo systemctl enable jenkins b. sudo systemctl start jenkins c. sudo systemctl status Jenkins d. sudo /etc/init.d/jenkins start Now change the port in the Security Group Inbound Rules to 9090 and click on “Save Rules”