Devops UNIT 3
Devops UNIT 3
Introduction to project management: The need for source code control, the history of source
code management, Roles and code, source code management system and migrations, shared
authentication, Hosted Git servers, Different Git server implementations, Docker
intermission, Gerrit, The pull request model, GitLab
Repository
• The repository is a Data storage solution where the history is maintained.
• Generally for this versioning is used and along with every version meta data like a reason
for the change is also maintained.
• Generally Repositories also have the option to view differences between versions.
• W.R.T CI/CD Pipelines we have two major repositories
– Source Code Repository
– Package Repository
Git
First Steps into Git
• Installing Git: https://git-scm.com/downloads
• Verifying if the git is installed or not git–version
The first step in Gitis to create a local repository.Createemptyfolder
– Cd into it
– execute init comm and git init
Git Commands
Getting & Creating Projects
Command Description
git init Initialize a local Git repository
git clone ssh://[email protected]/[username]/[repository- Create a local copy of a remote
name].git repository
Basic Snapshotting
Command Description
git status Check status
git add [file-name.txt] Add a file to the staging area
git add -A Add all new and changed files to the staging area
git commit -m "[commit
message]"
Commit changes
Command Description
List branches (the asterisk denotes the current
git branch
branch)
git branch -a List all branches (local and remote)
git branch [branch name] Create a new branch
git branch -d [branch name] Delete a branch
git push origin --delete [branch name] Delete a remote branch
git checkout -b [branch name] Create a new branch and switch to it
git checkout -b [branch name] origin/[branch
name]
Clone a remote branch and switch to it
Command Description
Push a branch to your remote
git push origin [branch name]
repository
Push changes to remote repository
git push -u origin [branch name]
(and remember the branch)
Push changes to remote repository
git push
(remembered branch)
git push origin --delete [branch name] Delete a remote branch
Update local repository to the
git pull
newest commit
Pull changes from remote
git pull origin [branch name]
repository
git remote add origin
ssh://[email protected]/[username]/[repository-name].git Add a remote repository
Command Description
git log View changes
git log --summary View changes (detailed)
git log --oneline View changes (briefly)
git diff [source branch] [target branch] Preview changes before merging
Three Areas of Git
• In the local repo or local system which represents a developer’ssystem, We have three areas
– Working Tree: This is where we make changes
– Staging area: This is intermediate are before sending changes to changes local
repo
– Local Repo: Once the change is in local repo it will have a history
Lets create a new folder and initialize it to be git repository
• Lets create a change
• Add the change to staging area and commit the change
• To commit a Change i.e. to maintain history, git requires
– Cchhaannggeess
– time when commit is done
– author username and email id
• To configure username and email id
– git config --global user.name “M Swetha"
– git config --global user.email “[email protected]"
Roles and code
• From a DevOps point of view,
– It is important to leverage the natural meeting point that the source code
management tool is.
– Many different roles have a use for source code management inits
wider meaning.
– It is easier to do so for technically-minded roles but harder for other roles, such as
project management.
• Developers live and breathe source code management.
• It's their bread and butter.
• Operations personnel also favor managing the descriptions of infrastructure in the form of
code, scripts, and other artifacts.
• Such infrastructural descriptors include network topology, versions of software that should
be installed on particular servers, and soon.
• Quality assurance personnel can store their automated tests in codified form in the source
code repository.
• There is a problem with the documentation of the manual steps needed to perform various
tasks.
• While many organizations employ a wiki solution such as the wiki engine powering
Wikipedia, there is still a lot of documentation floating around in the Word format on shared
drives and in e-mails.
• This makes documentation hard to find and use for some roles and easy for others.
• From a DevOps viewpoint, this is regrettable, and an effort should be made so that all roles
can have good and useful access to the documentation in the organization.
• It is possible to store all documentation in the wiki format in the central source code
repository, depending on the wiki engine used.
• For many organizations, keeping the history is not worth the significant expenditure in time
and effort.
• If an older version is needed at some point, the old source code management system can be
kept online and referenced.
• This includes mirations from Visual SourceSafe and ClearCase.
• Some migrations are trivial though, such as moving from Subversion to Git.
• In these cases, historical accuracy need not be sacrificed.
• The master branch only contains finished work.
• All commits are tagged since they represent releases.
• All releases happen from the master.
• The develop branch is where work on the next release happens.
When work is finished here, develop is merged to the master.
• We use separate feature branches for all new features.
• Feature branches are merged to develop.
• When a devastating bug is revealed in production, a hotfix branch is made where a bug fix
is created.
• The hotfix branch is then merged to master, and a new release for production is made.
Shared authentication
In most organizations, there is some form of a central server for handling
authentication.
An LDAP(Lightweight Directory Access Protocol) server is a fairly common choice.
While it is assumed that your organization has already dealt with this core issue one
way or the other and is already running an LDAP server of some sort, it is
comparatively easy to set up an LDAP server for testing purposes.
One possibility is using 389 Server, named after the port commonly used for the
LDAP server, together with the php LDAP admin web application for
administration of the LDAP server.
We can then use the same LDAP server for all the different servers we are going to
investigate.
Hosted Git servers
Many organizations can't use services hosted within another organization's walls at
all.
These might be government organizations or organizations dealing with money, such
as banks, insurance, and gaming organizations.
The causes might be legal or, simply nervousness about letting critical code leave the
organization's doors, so to speak.
If you have no such qualms, it is quite reasonable to use a hosted service, such as
GitHub or GitLab, that offers private accounts.
Using GitHub or GitLab is, at any rate, a convenient way to get to learn to use Git and
explore its possibilities.
Both vendors are easy to evaluate, given that they offer free accounts where you can
get to know the services and what they offer.
Some of the features offered by both GitLab and GitHub over plain Git are as follows:
–Web interfaces
– A documentation facility with an inbuilt wiki
– Issue trackers
- Commit visualization
– Branch visualization
– The pull request workflow
The distributed nature of Git makes it possible to try out different Git implementations
for various purposes.
• The client-side setup will be similar regardless of how the server is set up.
• You can also have several solutions running in parallel.
• The client side is not unduly complicated by this, since Git is designed to handle several
remotes if need be.
Docker Intermission
• We need to be able to try out a couple of different Git server implementations to see which
one suits our organization best.
• We can use Docker for this, so we will take this opportunity to peek at the possibilities of
simplified deployments that Docker offers us.
• Docker is used to download and run software.
• To get started with Docker, follow these steps:
– To begin with, install Docker according to the particular instructions for your
operating system. For Red Hat derivatives, it's a simple dnf install docker-io
command.
- Then, the dockerservice needs to be running:
Gerrit
• A basic Git server is good enough for many purposes.
• Sometimes, you need precise control over the workflow, though.
• One concrete example is merging changes into configuration code for critical parts of
the infrastructure.
• While my opinion is that it's core to DevOps to not place unnecessary red tape around
infrastructure code, there is no denying that it's sometimes necessary.
• If nothing else, developers might feel nervous about committing changes to the
infrastructure and would like for someone more experienced to review the code changes.
• Gerrit is a Git-based code review tool that can offer a solution in these situations.
• In brief, Gerrit allows you to set up rules to allow developers to review and approve
changes made to a codebase by other developers.
• These might be senior developers reviewing changes made by inexperienced developers
or the more common case, which is simply that more eyeballs on the code is good for
quality in general.
• Gerritis Java-based and uses a Java-based Git implementation under the hood.
• Gerrit can be downloaded as a Java WAR file and has an integrated setup method.
• It needs a relational database as a dependency, but you can opt to use an integrated Java-
based H2 database that is good enough for evaluating Gerrit.
• An even simpler method is using Docker to try out Gerrit.
• There are several Gerrit images on the Docker registry hub to choose from.
• The following one was selected for this evaluation exercise:
https://hub.docker.com/r/openfrontier/gerrit/
• To run a Gerrit instance with Docker, follow these steps:
– Initialize and start Gerrit:
docker run -d -p 8080:8080 -p 29418:29418 openfrontier/gerrit
• Open your browser to http://<docker host url>:8080
• This model has the advantage of being easy to understand, and many developers have
experience in it from the many open-source projects on GitHub.
• Setting up a system capable of handling a pull request model locally will require
something like GitHub or GitLab.
GitLab
• GitLab supports many convenient features on top of Git.
• It's a large and complex software system based on Ruby.
• As such, it can be difficult to install, what with getting all the dependencies right and so
on.
• There is a nice Docker Compose file for GitLab available at
https://registry.hub.docker.com/u/sameersbn/gitlab/.
• If you followed the instructions for Docker, including the installation of docker-compose,
it's now pretty simple to start a local GitLab instance:
– mkdir gitlab
– cd gitlab
– wgethttps://raw.githubusercontent.com/sameersbn/docker-
gitlab/master/docker-compose.yml
– docker-compose up
• The docker-compose command will read the .yml file and start all the required
services in a default demonstration configuration.
• The GitLab container includes the Ruby base web application and Git backend
functionality.
• Redis is a distributed key-value store, and PostgreSQL is a relational database.
• If you are used to setting up complicated serve functionality, you will appreciate that we
have saved a great deal of time with docker-compose.
• The docker-compose.yml file sets up data volumes at /srv/docker/gitlab
• To log in to the web user interface, use the administrator password given with the
installation instructions for the GitLab Docker image.
• They have been replicated here, but beware that they might
• Username: root
• Password: 5iveL!fe