git merge
Git cherry-pick:
----------------
Cherry pick used to choose a particular commit from one branch and apply it onto another.
syntax:
$ git cherry-pick <commitID>
--------------------------------------------
Git Reset:
----------
git reset command is used to go to previous version of code
git reset --hard <commitID>
--------------------------------------------------------------
Git Reset
-----------
Git reset is used to undo the commited changes, but commit history will also gets removed
Two important types of git reset are there
1) soft reset:
soft reset is used to move files from local repo to staging area
+ commit history will also gets removed
syntax: git reset --soft <commit_ID>
2) Hard reset:
hard reset will remove file from everywhere ( local repo , staging area & working directory )
+ commit history will also gets removed
syntax: git reset --hard <commit_ID>
Git revert
----------
Git revert is also used to undo the commited changes, but commit history will not get removed,
we can track the reverted changes in the git log
syntax:
git revert HEAD
Note:
git revert is used to rollback only ( go 1 step back- previous version of code)
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Difference between Git Reset & Git Revert:
---------------------------------------------
both reset & revert are used to undo the commited changes
Git reset:
1. if we use git reset commit history will get removed / deleted
2. Reset is destructive, as it will delete that commit & we cannot see the old commit
Git revert:
1. if we use git revert commit history will not get removed / deleted
2. Revert is Non Desrtuctive, as it will create new commit each time.
Git Reset logs:
===============
mkdir project6
cd project6
git init
touch file1 file2
git add .
git commit -m "first commit adding file1 file2 "
touch file3 file4
git add .
git commit -m "second commit adding file3 file4 "
git log --oneline
git status ==> (nothing to commit, working tree clean )
git reset --soft <first_commitID>
git log --oneline ==> ( you will only see first commit second commit got deleted from git log )
git status ==> ( file3 & file4 will in staging area )
---------------
git hard reset
-----------------
git commit -m "second commit adding file3 file4 "
git log --oneline
git status ==> (nothing to commit, working tree clean )
git reset --hard <first_commitID>
git log --oneline ==> ( you will only see first commit and second commit got deleted from git log )
git status ==> ( file3 & file4 deleted from everyehere )
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
git revert logs:
==================
mkdir project7
cd project7
git init
touch file1 file2
git add .
git commit -m "first commit........"
touch file3 file4
git add .
git commit -m "second commit........"
git log --oneline
git revert HEAD ## file3 file4 are deleted due to revert /rollback to last version
*****************************************************************************************************************
WORKING WITH REMOTE REPOSITORIES:
=================================
Repository
----------
repository ==> folder / location ==> where you can store your files
Local Repository
----------------
repository which is there in your laptop/server
Remote repository
-----------------
centralized location where all source code related to project will be kept
remote repo service providers are ==> GitHub( https://github.com) , BitBucket , Gitlab
===============================================================================
Note:
------
Remote repo === central repo ==> same
Public repo ==> visble to everyone ==> you can clone / download my project
Private repo ==> visible to us & we can add anyone who needs access ==> companies
if we create repo ==> Gitbash ==> default branch is master
if we create repo ==> Github ==> default branch is main
To rename branch: git branch -m <old_branch_name> <new_branch_name>
----------------------------------------------------------------------------
================================================================================
jenkins
what are artifacts?
-------------------
We cannot directly use any code written in any programming languages directly, so we have to convert those into machine understable format called as artifacts.
ex: git (gitbash software for windows) is written(developed) using c/c++ language
jenkins software is written(developed) using java language
docker software is written(developed) using golang language
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Note:
----
1. what are other programming languages used ?
Java, python, node js .
2. what all build tools available for java?
Java supports both Maven (or) Gradle
3. For Nodejs build tool is npm & artifacts name will be like package.json
we will work on java based applications with Maven as build tool
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
CI- CD PROCESS:
---------------
<< DIAGRAM >>
CODE:
-----
Here developers need to write code to develop web applications.
once developers done with writing code, code it will be committed using VCS like GIT
& code gets pushed to centralized/Remote repos like GitHUb.
BUILD:
-------
Let’s consider your code is written in java, it needs to be build before usage.
In this build step code gets compiled artifacts (jar or war file) get generated
For build purpose we will use maven
UNIT TEST:
----------
If the build step is completed, then move to testing phase in this step unit test will be done.
- unit test are simpler CODE LEVEL TESTING to test correctness of individual units of code.
- unit testing will be done by developers.
- Junit tool can be used for unit testing.
- if unit test is passed then we can push build artifacts to artifactory
- if unit test is failed then developers will get feedback & then they will fix the code & again cycle begins from start.
ARTIFACTORY:
-----------
- Artifactory is place where we can store our build artifacts (like github for storing code), so that in future we may use/share again.
- JFROG / NEXUS are most used artifactory tools in industry
DEPLOY:
-------
- In this step, you can deploy(install) our application(war file).
- Here, you can see your application output
- optionally, we can deploy our application to different environments & do different types of testing.
Note:
environments means group of servers(will be discussed later).
AUTOMATED TESTING:
-----------------
- after deploying, we will do complete testing of application using Automatedtesting tools.
- Testing team (or QA Team) will use tools like selenium to test
- Testing will be done using scripts given by testing team .
- overall it is APPLICATION LEVEL TESTING
if automated test results are good, then we can deploy in PRODUCTION ENVIRONMENT
DEPLOY TO PRODUCTION ((LIVE ENVIRONMENT)):
---------------------
If all results in AutoMated Testing are ok, then we can deploy your code in production servers. (by taking all approvals)
MONITOR:
--------
After deploying to prod we have to monitor(observe) the applications performance so that end users dont face any issue while accesing applications.
Note:
-----
Deploy to production will not be done automatically.
Earlier above mentioned stages was done seperately, now with tools like jenkins we can automate or execute all stages AUTOMATICALLY.
Because of Jenkins, If we have any error / malfunction is found in our code, it will be reported fast to developers and get rectified so entire development is fast.
Here, Overall SDLC will be automatic using Jenkins
what is jenkins?
---------------
- Jenkins is a open source CI -CD tool written in java.
- The leading open source auttomation tool will do all points mentioned in the diagram
- Jenkins provides hundreds of plugins to support building, deploying and automating any project.
- If we want to use continuous integration first choice is jenkins.
- It consists of plugins. Through plugins we can do whatever we want, without plugins we can’t run anything in jenkins
- It is used to detect the faults in the software development.
- It automates the code whenever developer commits
- It was originally developed by SUN Microsystem in 2004 as HUDSON
- HUDSON was an enterprise edition( i,e it was not open source project earlier), it was paid tool.
- The project was renamed jenkins when oracle brought the microsystems.
- Jenkins default port number is 8080
What is CI-CD?
--------------
- Whenever developers write code pushes code to VCS (Github/gitlab/bitbucket), we integrate all the code of all developers at any point of time and we build, test and deliver/deploy it to the client.
This process is called CI/CD
advantages of CI-CD:
--------------------
With CI-CD, If we have any issue in our code, it will be reported fast to developers, so that they can rectify the issues, so entire SDLC lifecycle will be very fast.
Why only Jenkins?
================
- It has so many plug-ins. You can write your own plug-in.
- We can attach slave servers to Jenkins master.
- It instructs others (slaves) to do Job. If slaves are not available, Jenkins itself does the job.
- Jenkins also works like crontab, i.e it can schedules scripts to run at any time as we need.
Key Terminologies in CI - CD :
==============================
- Integrate: Combine all code written by developers till some point of time
- Build: Take the source code and generate artifacts (war files)
- Test: Run test scripts given by testing teams to check whether application is working properly or not.
- Artifactory: artifactory is a place where we keep our build artifacts (war file), so that in future we may use/deliver again.
Jfrog / nexus are most used artifactory tools in industry
- Deliver : Handingover the product (aritifact i. e war file ) to Client.
- Deploy: Installing product (aritifact i.e war file ) in client’s servers.
===================================================================================
****Jenkins Installation*******
----------------------------------------
Make sure java is installed else install java using below commands
Step1: Install Java
yum install java-11
Step2 : Downloading Jenkins repo
###To list the Jenkins versions
sudo yum --showduplicates list jenkins | expand
##Installing the specific version of Jenkins
sudo yum install jenkins-2.401-1.1
##Start Jenkins
sudo systemctl start jenkins
##Enable the Jenkins
sudo systemctl enable jenkins
## Check the status of Jenkins
sudo systemctl status jenkins
##Access Jenkins Dasbhboard
##To get initial Admin password
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
##Sign up with the username and password
username:admin
password:admin
email:admin@gmail.com