100% found this document useful (1 vote)
193 views20 pages

CI - CD With Dockers and Jenkins. CI - Continuous Integration - Involves - by Kubernetes Advocate - FAUN - Medium

This document provides steps for setting up continuous integration and continuous delivery (CI/CD) using Docker and Jenkins. It begins by defining CI as continuous integration, which involves automatically building and testing code whenever it is committed. It defines CD as continuous delivery, which involves automatically deploying new builds. It then provides steps for installing Git and creating a local Git repository. It describes adding files, tracking changes, staging files, and making commits. It concludes by explaining how to create a new branch in Git to develop features separately from the main codebase.

Uploaded by

satish
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
193 views20 pages

CI - CD With Dockers and Jenkins. CI - Continuous Integration - Involves - by Kubernetes Advocate - FAUN - Medium

This document provides steps for setting up continuous integration and continuous delivery (CI/CD) using Docker and Jenkins. It begins by defining CI as continuous integration, which involves automatically building and testing code whenever it is committed. It defines CD as continuous delivery, which involves automatically deploying new builds. It then provides steps for installing Git and creating a local Git repository. It describes adding files, tracking changes, staging files, and making commits. It concludes by explaining how to create a new branch in Git to develop features separately from the main codebase.

Uploaded by

satish
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

9/21/2020 CI/CD with Dockers and Jenkins.

CI — Continuous Integration: involves… | by Kubernetes Advocate | FAUN | Medium

CI/CD with Dockers and Jenkins


Kubernetes Advocate Follow
Jun 14 · 10 min read

CI — Continuous Integration: involves beginning an automatic build (and presumably


running tests) whenever new code is committed to or checked into the team project’s
supply management repository.

This gives you immediate feedback that the code builds and may doubtless be deployed.

CI/CD

CD — Continuous Deployment/Delivery:: involves beginning an automatic preparation


method whenever a brand new palmy build is out there
https://medium.com/faun/ci-cd-with-dockers-and-jenkins-70b6f801f9f7 1/20
9/21/2020 CI/CD with Dockers and Jenkins. CI — Continuous Integration: involves… | by Kubernetes Advocate | FAUN | Medium

. . .

Cloud Environments
The deployment environments for a cloud application can be summarized as follows:

Staging

Production

Deployment Flow Process :


Git Hub +Jenkins +Tomcat server

. . .

GIT installation step by step

Step 0: Install git and create a GitHub account


The rst two things you’ll want to do are install git and create a free GitHub account.

Follow the directions here to put in lowlife (if it’s not already installed).

Note that for this tutorial we’ll be victimization lowlife on the instruction solely.

While there are some nice lowlife GUIs (graphical user interfaces), I believe it’s easier to
nd out lowlife victimization lowlife-speci c commands 1st and so to undertake out a git
GUI

Once you’ve done that, produce a GitHub account here. (Accounts are free for public
repositories, but there’s a charge for private repositories.)

Step 1: Create a local git repository


When creating a new project on your local machine using git, you’ll rst create a new
repository (or often, ‘repo’, for short).

https://medium.com/faun/ci-cd-with-dockers-and-jenkins-70b6f801f9f7 2/20
9/21/2020 CI/CD with Dockers and Jenkins. CI — Continuous Integration: involves… | by Kubernetes Advocate | FAUN | Medium

If you don’t have abundant expertise with the terminal and basic commands, scrutinize
this tutorial (especially the ‘Navigating the Filesystem’ and ‘Moving Around’ sections).

To begin, open up a terminal and move to wherever you wish to put the project on your
native machine victimization the cd (change directory) command. For example, if you
have a ‘projects’ folder on your desktop, you’d do something like:

vineet@vineet-ndi-lap-688:~$ cd Desktop/Projects/maven-project/
vineet@vineet-ndi-lap-688:~/Desktop/Projects/maven-project$ ls
Jenkinsfile pom.xml server webapp

To initialize a git repository in the root of the folder, run the git init command:

vineet@vineet-ndi-lap-688:~/Desktop/Projects/maven-project$ git init


Reinitialized existing Git repository in
/home/vineet/Desktop/Projects/maven-project/.git/

Step 2: Add a new le to the repo


Go ahead and add a new le to the project, using any text editor you like or running a
touch command.

Once you’ve added additional or changed les during a folder containing a git repo, git
can notice that changes are created within the repo.

But, git won’t formally keep track of the le (that is, place it during a commit — we’ll
speak a lot of regarding commits next) unless you expressly tell it to.

vineet-ndi-lap-688:~/Desktop/Projects/maven-project$ touch
website.txt
vineet-ndi-lap-688:~/Desktop/Projects/maven-project$ ls
Jenkinsfile pom.xml server webapp website website.txt

After creating the new le, you can use the git status command to see which les git
knows to exist.

https://medium.com/faun/ci-cd-with-dockers-and-jenkins-70b6f801f9f7 3/20
9/21/2020 CI/CD with Dockers and Jenkins. CI — Continuous Integration: involves… | by Kubernetes Advocate | FAUN | Medium

vineet@vineet-ndi-lap-688:~/Desktop/Projects/maven-project$ git
status
On branch master
Untracked files:
(use "git add <file>..." to include in what will be committed)

Jenkinsfile
website
website.txt

nothing added to commit but untracked files present (use "git add" to
track)

What this primarily says is, “Hey, we tend to notice you created a brand new le known
as mnelson.txt, however, unless you employ the ‘git add’ command we tend to are not
reaching to do something

An interlude: The staging environment, the commit, and you


One in all the foremost confusing components, when you’re initially learning GIT, is the
conception of the staging surroundings and the way it relates to a commit.

A commit could be a record of what les you’ve got modi ed since the last time you
created a commit.

Essentially, you create changes to your repo (for example, adding a le or modifying
one) so tell GIT to place those les into a commit.

Commits structure the essence of your project and permit you to travel back to the state
of a project at any purpose.

So, however, does one tell GIT the les to place into a commit?

This is wherever the staging surroundings or index are available.

As seen in Step two, after you build changes to your repo, GIT notices that a le has
modi ed however won’t do something with it (like adding it in a very commit).

To add a le to a commit, you initially ought to add it to the staging surroundings.

https://medium.com/faun/ci-cd-with-dockers-and-jenkins-70b6f801f9f7 4/20
9/21/2020 CI/CD with Dockers and Jenkins. CI — Continuous Integration: involves… | by Kubernetes Advocate | FAUN | Medium

To do this, you’ll be able to use the GIT add the command (see Step three below).

Once you’ve used the git add a command to feature all the les you wish to the staging
surroundings, you’ll be able to then tell GIT to package them into a commit

Note: The staging surroundings, additionally known as ‘staging’, is that the new most
popular term for this, however, you’ll be able to additionally see it spoken because of the
‘index’.

Step 3: Add a le to the staging environment


Add a le to the staging surroundings victimization the GIT add command.

If you rerun the GIT status command, you’ll see that GIT has another the le to the
staging surroundings (notice the “Changes to be committed” line).

devops-ndi-lap-688:~/Desktop/Projects/maven-project$ git add .


devops-ndi-lap-688:~/Desktop/Projects/maven-project$ git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)

new file: Jenkinsfile


new file: website
new file: website.txt

To repeat, the le has not nonetheless been another to a commit, however, it is close to
being.

Step 4: Create a commit


It’s time to create your rst commit!

Run the command git commit -m "Jenkins File created"

devops-ndi-lap-688:~/Desktop/Projects/maven-project$ git commit -m


"Jenkins file created "
[master 9e50b6e] Jenkins file created
3 files changed, 32 insertions(+)
create mode 100644 Jenkinsfile

https://medium.com/faun/ci-cd-with-dockers-and-jenkins-70b6f801f9f7 5/20
9/21/2020 CI/CD with Dockers and Jenkins. CI — Continuous Integration: involves… | by Kubernetes Advocate | FAUN | Medium

create mode 100644 website


create mode 100644 website.txt

Run the command skunk commit -m “Jenkins File created” The message at the top of the
commit ought to be one thing associated with what the commit contains — perhaps it’s

a new feature, perhaps it’s a bug x, perhaps it’s simply xing a mistake. Don’t place a
message like “asdfadsf” or “foobar”.

Step 5: Create a new branch


Now that you’ve created a brand new commit, let’s strive one thing a touch additional
advanced.

Say you wish to create a brand new feature however square measure disquieted
concerning creating changes to the most project whereas developing the feature.

Branches allow you to move back and forth between the ‘states’ of a project.

For instance, if you wish to feature a brand new page to your web site you’ll be able to
produce a brand new branch only for that page while not touching the most a part of the
project.

Once you’re nished the page, you’ll be able to merge your changes from your branch
into the master branch. After running the above command, you can use the git branch

the command to con rm that your branch was created:

devops-ndi-lap-688:~/Desktop/Projects/maven-project$ git Branch


master
* Development

The branch name with the asterisk next to it indicates which branch you’re pointed to at
that given time.

Now, if you switch back to the master branch and make some more commits, This
command can mechanically produce a brand new branch so mechanically you out’ on
that, which means GIT can move you merge a branch, o of the master branch.
https://medium.com/faun/ci-cd-with-dockers-and-jenkins-70b6f801f9f7 6/20
9/21/2020 CI/CD with Dockers and Jenkins. CI — Continuous Integration: involves… | by Kubernetes Advocate | FAUN | Medium

Step 6: Create a new repository on GitHub


If you merely wish to stay track of your code regionally, you oughtn’t to use GitHub.

But if you wish to gure with a team, you’ll be able to use GitHub to collaboratively
modify the project’s code.

To create a brand new repo on GitHub, log in and move to the GitHub home page.

You should see an inexperienced ‘ New repository’ button: when clicking the button,
GitHub can raise you to call your repo and supply a quick description:

Step 6 New repository is created (maven-project)

Step 7 Let’s push the Git code to the repository (Maven -Project)

Step 8 we can see that code has been successfully pushed to Github Repository

https://medium.com/faun/ci-cd-with-dockers-and-jenkins-70b6f801f9f7 7/20
9/21/2020 CI/CD with Dockers and Jenkins. CI — Continuous Integration: involves… | by Kubernetes Advocate | FAUN | Medium

. . .

Tomcat 8 Installation step by step:


1 java -version
2 sudo apt install OpenJDK-8-JDK-headless
3 sudo apt-get update
4 sudo add-apt-repository ppa:webupd8team/java
5 java -version
6 sudo apt-get update
7 sudo apt-get install tomcat8
8 sudo apt-get install tomcat8-docs tomcat8-admin tomcat8-examples
9 systemctl start tomcat 8
10 systemctl start tomcat 8

You need to make changes in Tomcat-users.xml le after tomcat is successfully installed

https://medium.com/faun/ci-cd-with-dockers-and-jenkins-70b6f801f9f7 8/20
9/21/2020 CI/CD with Dockers and Jenkins. CI — Continuous Integration: involves… | by Kubernetes Advocate | FAUN | Medium

sudo vi /etc/tomcat8/tomcat-users.xml

. . .

Jenkins Installation
Follow the below steps:

Step 1: First install Java, using the following command.

$ sudo apt-get install openjdk-8-jre-headless -y

Step 2: Add the key and source list to apt for Jenkins.

$ wget -q -O - https://pkg.jenkins.io/debian/jenkins-ci.org.key |
sudo apt-key add -

Step 3: Now create source list for Jenkins, using the below commands

$ sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ >


/etc/apt/sources.list.d/jenkins.list'

Step 4: Update the packages

https://medium.com/faun/ci-cd-with-dockers-and-jenkins-70b6f801f9f7 9/20
9/21/2020 CI/CD with Dockers and Jenkins. CI — Continuous Integration: involves… | by Kubernetes Advocate | FAUN | Medium

$ sudo apt-get update

Step 5: Now install Jenkins.

$ sudo apt-get install jenkins

Step 6: After installing Jenkins. Go to: http://your_ip_address:8080 and run the


following commands to get the admin password.

$ sudo nano /var/lib/jenkins/secrets/initialAdminPassword

Step 7: Now copy the password and paste it into the browser.

When nished, you should see a screen similar to the below one.

https://medium.com/faun/ci-cd-with-dockers-and-jenkins-70b6f801f9f7 10/20
9/21/2020 CI/CD with Dockers and Jenkins. CI — Continuous Integration: involves… | by Kubernetes Advocate | FAUN | Medium

. . .

Integrating GitHub with Jenkins


The integration of GitHub with Jenkins automates deployment, testing, and improves
product quality while saving a signi cant amount of time for developers. Follow the
below steps to integrate GitHub with Jenkins:

Prerequisite: Install GitHub Jenkins plugin.

Step 1 Go to Manage Jenkins -> Manager Plugin.

Step 2 Search Github Plugin in the Available tab then click on Download now and install
after the restart.

https://medium.com/faun/ci-cd-with-dockers-and-jenkins-70b6f801f9f7 11/20
9/21/2020 CI/CD with Dockers and Jenkins. CI — Continuous Integration: involves… | by Kubernetes Advocate | FAUN | Medium

Step 3 Install Maven Plugin. Go to Jenkins- Manage Jenkins- Global Tool Con guration,
Click OK

. . .

https://medium.com/faun/ci-cd-with-dockers-and-jenkins-70b6f801f9f7 12/20
9/21/2020 CI/CD with Dockers and Jenkins. CI — Continuous Integration: involves… | by Kubernetes Advocate | FAUN | Medium

How to integrate Jenkins with GitHub so automatically CI/ CD takes place when any
commit made by developers

Step 1 Go to Jenkins- click on System con guration- Go to GitHub section

Step2 Go to Github Repository- click on settings- Go to webhook and add new webhook

Paste the Jenkins Hook URL in the Github webhook

https://medium.com/faun/ci-cd-with-dockers-and-jenkins-70b6f801f9f7 13/20
9/21/2020 CI/CD with Dockers and Jenkins. CI — Continuous Integration: involves… | by Kubernetes Advocate | FAUN | Medium

. . .

Creating a Jenkins job


Step 1 To Create a new task for Jenkins, click on “New Item” then enter an item name
that is suitable for your project and select the Freestyle project. Now click Ok.

Step 2 Select the GitHub project checkbox and set the Project URL to point to your
GitHub Repository.

https://medium.com/faun/ci-cd-with-dockers-and-jenkins-70b6f801f9f7 14/20
9/21/2020 CI/CD with Dockers and Jenkins. CI — Continuous Integration: involves… | by Kubernetes Advocate | FAUN | Medium

Step 3 Under Source Code Management tab, select Git, and then set the Repository URL
to point to your GitHub Repository.

Step 4 Now Under Build Triggers tab, select the “Build when a change is pushed to
GitHub” checkbox.

https://medium.com/faun/ci-cd-with-dockers-and-jenkins-70b6f801f9f7 15/20
9/21/2020 CI/CD with Dockers and Jenkins. CI — Continuous Integration: involves… | by Kubernetes Advocate | FAUN | Medium

Step 5 In the end, execute the Shell script to take a clone from dev. When the
con guration is done, click on the Save button.

Step 6 Click OK and Build a Job and you will see that a war le is created and as soon as
build is successfully triggered, same war le is copied by other projects (Other projects
to build)

https://medium.com/faun/ci-cd-with-dockers-and-jenkins-70b6f801f9f7 16/20
9/21/2020 CI/CD with Dockers and Jenkins. CI — Continuous Integration: involves… | by Kubernetes Advocate | FAUN | Medium

Step7 Create one more project for Deployment into tomcat server hosted on an EC2
machine (Deploy- to -Staging)

You will see that it is copying artifacts from a previous project (Package) and also
mentioning to copy the latest successful build of the previous project

Step 8 Now we will deploy the war le to tomcat 8 server hosted on EC2 machine with IP
172.31.90.150:8080(Port number of Tomcat 8)

https://medium.com/faun/ci-cd-with-dockers-and-jenkins-70b6f801f9f7 17/20
9/21/2020 CI/CD with Dockers and Jenkins. CI — Continuous Integration: involves… | by Kubernetes Advocate | FAUN | Medium

Step 9 As soon as we create a build of this Job we will see that the Java application is
deployed on Tomcat 8 hosted on an EC2 machine

Step 10 we can see our app is deployed on path/var/lib/tomcat8/webapps

ubuntu@ip-172–31–90–150:~$ cd /var/lib/tomcat8/webapps/production/
ubuntu@ip-172–31–90–150:/var/lib/tomcat8/webapps/production$ ls
index.JSP META-INF WEB-INF

Step 11 We can now copy URL and paste on a browser with /Production

https://medium.com/faun/ci-cd-with-dockers-and-jenkins-70b6f801f9f7 18/20
9/21/2020 CI/CD with Dockers and Jenkins. CI — Continuous Integration: involves… | by Kubernetes Advocate | FAUN | Medium

Thanks

Subscribe to FAUN topics and get your weekly curated email of the must-read tech
stories, news, and tutorials 🗞

Follow us on Twitter 🐦 and Facebook 👥 and Instagram 📷 and join our


Facebook and Linkedin Groups 💬

If this post was helpful, please click the clap 👏 button below a few times to
show your support for the author! ⬇

https://medium.com/faun/ci-cd-with-dockers-and-jenkins-70b6f801f9f7 19/20
9/21/2020 CI/CD with Dockers and Jenkins. CI — Continuous Integration: involves… | by Kubernetes Advocate | FAUN | Medium

Startup AWS Tech Architecture Docker

About Help Legal

Get the Medium app

https://medium.com/faun/ci-cd-with-dockers-and-jenkins-70b6f801f9f7 20/20

You might also like