software engineering Chapter 5 System modeling.pptx
GIT training - advanced for software projects
1. lundi 13 mars 2023
GIT TRAINING - Advanced
Thierry GAYET
2. The purpose of this training will be to:
Reminder on git commands
Devops / devsecops
Gitlab
Advanced usage of GIT
CI and CD
Have a good training
GOAL
2
scan me
4. After the two first modules of the git training, we will continue step
by step in command line for the nerds/geeks or using a graphical tool
such as Visual code studio from Microsoft that can be run on
gnu/linux, Ms Windows or Mac OS X.
We will use this gitlab project :
https://gitlab.enensys.com/training/git/first-project
You must have an access to gitlab (and your public ssh (rsa) key
declared : ~/.ssh/id_rsa.pub)
GIT / PURPOSE
4
37. Upgrade your ~/.bashrc usefull for all commands :
(...)
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* (.*)/(1)/’
}
export PS1="u@h [e[32m]w [e[91m]$(parse_git_branch)[e[00m]$ "
(...)
It will colorize the prompt command line and display the name of the git
repo and the branch’s name :
linux@des126 ~/Workspaces/training/first-project (feature/ttsp-1234/my-first-
files)$
GIT / CONFIG
37
38. You can add/change the git user in the Extension Git Graph easily.
Go to the Extensions tab and install Git Graph.
Go to the Source Control tab
Click on the View Git Graph
Click on the Repository Settings
In the User Details section, click
Edit and change the Git Username
and Email.
38
GIT / CONFIG
39. Several videos on VS CODE and GIT :
https://code.visualstudio.com/docs/sourcecontrol/overview
https://www.youtube.com/watch?v=i_23KUAEtUM&embeds_euri=https%3A
%2F%2Fcode.visualstudio.com%2F&feature=emb_imp_woyt
https://www.youtube.com/watch?v=E6ADS2k8oNQ&embeds_euri=https%3A
%2F%2Fcode.visualstudio.com%2F&feature=emb_imp_woyt
https://www.youtube.com/watch?v=b9LTz6joMf8&embeds_euri=https%3A%
2F%2Fcode.visualstudio.com%2F&feature=emb_imp_woyt
https://www.youtube.com/watch?v=HosPml1qkrg&embeds_euri=https%3A
%2F%2Fcode.visualstudio.com%2F&feature=emb_imp_woyt
39
GIT / CONFIG
49. GIT / CLONE
49
Clone your GIT repo :
$ mkdir –p ~/Workspace && cd ~/Workspace
$ git clone git@gitlab.enensys.com:training/git/first-project.git
(Needs to have uploaded his ssh key (~/.ssh/id_rsa.pub) in his gitlab profile)
Cloning into 'test’...
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (3/3), done.
OR
$ git clone https://gitlab.enensys.com/training/git/first-project.git
Cloning into 'first-project’...
Username for 'https://gitlab.enensys.com': gayett
Password for 'https://gayett@gitlab.enensys.com’:
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (3/3), done.
50. By default a git repo take the repo from the server but can be change
if we provide a name at the clone time :
$ git clone git@gitlab.enensys.com:training/git/first-project.git first-projet-2
Cloning into ‘first-project-2’...
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (3/3), done.
50
GIT / CLONE
51. We can now check branches :
$ cd first-project/
~/Workspaces/first-project (main)$
~/Workspaces/first-project (main)$ git branch
* main
~/Workspaces/first-project (main)$ git branch –a
* main
remotes/origin/HEAD -> origin/main
remotes/origin/main
GIT / CLONE
51
Local branch(es)
Local and remotes branches
Name of the current branch : main
Name of the git repo just cloned
52. Now, using visual
code :
GIT / CLONE
52
Select that we want to clone
a git repo.
53. 53
GIT / CLONE
Just copy/paste the
url of the git repo to
clone
Valid by
clicking on
the « Clone
from url »
54. 54
GIT / CLONE
VS code will ask you to
choose a folder where
you want to clone your
git repo :
Confirm by clicking
on that button
55. Finally, we can open the repo just cloned :
We can also confirm that we trust the git repo :
55
GIT / CLONE
Say that we want to open the source
of the git repo just cloned
Check that this repo is trusted
And validate by clicking on the button
"Yes, i trust the authors ...."
56. 56
GIT / CLONE
The project is
now available
using visual
code.
This is an
empty repo so
this is normal if
there is nothing
inside !
Default’s branch
(main)
71. The goal is to apply the NN6 gitflow that must be apply on all git repo :
main : the stable branch similar to the production
integration : the branch used for intermediate integration is the equivalent of
a preproduction
development : the unstable branch used to merge the developments to be
integrated
71
GIT / BRANCHES
72. GITFLOW
72
❑ The official GITFLOW to be use is the following one :
main/stable/production
preprod/integration
Development/unstable
HOTFIX / ID-JIRA / DESCRIPTION
BUGFIX / ID-JIRA / DESCRIPTION
FEATURE / ID-JIRA / DESCRIPTION
TAG1 TAG2
rebase
rebase
rebase
Merge
request
Merge
request
Merge
request
Merge
request
MR
Merge
request
Push
+
merge
request
Push
+
merge
request
Push
+
merge
request
73. 73
GITFLOW
Main
(stable’s branch)
Integration’s branch
Develop
(unstable’s branch)
HOTFIX
branch
branch
branch
Push on
the bugfix
branch
BUGFIX
FEATURE
Rebase
branch
branch
Rebase
Push + Merge
Request
Push + Merge
Request
All branches merged into this
integration branch should reflect
what will be described in the final
release note.
RC
9.1.0
RC
9.1.1
HOTFIX
branch
Merge
Request
Merge
Request
Merge
Request
Merge
Request
9.0.0 9.1.1
Merge
Request
Push on
the bugfix
branch
Merge
Request
Merge
Request
CI : linters (gitlab)
Hotfix
release
Official
release
Hotfix
release
If the
hotfix is
clean!
If the
hotfix is
clean!
Jenkins nightly build +
sanity tests
Jenkins build +
focus test on
the hotfix
Jenkins build +
focus test on
the hotfix
Jenkins build + complete tests
Jenkins nightly build +
sanity tests
75. 75
Create branches (in two time) :
~/Workspaces/first-project (main)$ git branch
* main
~/Workspaces/first-project (main)$ git branch integration
~/Workspaces/first-project (main)$ git branch
integration
* main
~/Workspaces/first-project (main)$ git checkout integration
Switched to branch 'integration’
~/Workspaces/first-project (integration)$ git branch
* integration
main
~/Workspaces/first-project (integration)$ git branch develop
~/Workspaces/first-project (integration)$ git branch
develop
* integration
main
~/Workspaces/first-project (integration)$ git checkout develop
Switched to branch
~/Workspaces/first-project (develop)$ git branch
* develop
integration
main
Git branch <branch_name>
create a new branch
Git checkout <branch_name>
switch to an existing branch
GIT / BRANCHES
76. Create branches and switch (with the same command) :
~/Workspaces/first-project (main)$ git branch
* main
~/Workspaces/first-project (main)$ git checkout -b integration
Switched to a new branch 'integration’
~/Workspaces/first-project (integration)$ git branch
* integration
main
~/Workspaces/first-project (integration)$ git checkout -b develop
Switched to a new branch 'develop’
~/Workspaces/first-project (develop)$ git branch
* develop
integration
main
76
GIT / BRANCHES
Git checkout –b <branch_name>
create and switch to the new branch
77. After the creation all branches are just local and must be pushed to the remote (called origin by default) :
~/Workspaces/first-project (hotfix/ttsp-1245/Fix-database-problem)$ git branch -a
develop
feature/TTSP-27-37/launch-a-vmaf-analysis
* hotfix/ttsp-1245/Fix-database-problem
integration
main
remotes/origin/HEAD -> origin/main
remotes/origin/main
~/Workspaces/first-project (hotfix/ttsp-1245/Fix-database-problem)$ git checkout integration
Switched to branch 'integration’
~/Workspaces/first-project (integration)$ git push origin integration
Total 0 (delta 0), reused 0 (delta 0), pack-reused 0
remote:
remote: To create a merge request for integration, visit:
remote: https://gitlab.enensys.com/training/git/first-project/-/merge_requests/new?merge_request%5Bsource_branch%5D=integration
remote:
To gitlab.enensys.com:training/git/first-project.git
* [new branch] integration -> integration
77
GIT / BRANCHES
The main’s branch is the default branch juste clone, so we don’t have to create or push it !
78. 78
GIT / BRANCHES
~/Workspaces/first-project (integration)$ git branch -a
develop
feature/TTSP-27-37/launch-a-vmaf-analysis
hotfix/ttsp-1245/Fix-database-problem
* integration
main
remotes/origin/HEAD -> origin/main
remotes/origin/integration
remotes/origin/main
~/Workspaces/first-project (integration)$ git checkout develop
Switched to branch 'develop’
~/Workspaces/first-project (develop)$ git branch
* develop
feature/TTSP-27-37/launch-a-vmaf-analysis
hotfix/ttsp-1245/Fix-database-problem
integration
main
The integration’s branch is now pushed on the remote origin server !
79. 79
GIT / BRANCHES
~/Workspaces/first-project (develop)$ git push origin develop
Total 0 (delta 0), reused 0 (delta 0), pack-reused 0
remote:
remote: To create a merge request for develop, visit:
remote: https://gitlab.enensys.com/training/git/first-project/-/merge_requests/new?merge_request%5Bsource_branch%5D=develop
remote:
To gitlab.enensys.com:training/git/first-project.git
* [new branch] develop -> develop
~/Workspaces/first-project (develop)$ git branch -a
* develop
feature/TTSP-27-37/launch-a-vmaf-analysis
hotfix/ttsp-1245/Fix-database-problem
integration
main
remotes/origin/HEAD -> origin/main
remotes/origin/develop
remotes/origin/integration
remotes/origin/main
The develop’s branch is now pushed on the remote origin server !
85. 85
GIT / BRANCHES
By clicking on
the branch’s
name it will
display all one
Here is a summary of the branches created localy
We will see how to push them to the gitlab server
89. 89
GIT / BRANCHES
The Intégration branch is now
on Gitlab
We can also push the develop’s branch as well !
90. Create the following branches (from main) :
main-USERNAME
integration-USERNAME
develop-USERNAME
Push your all your branches to GITLAB (origin)
90
GIT / BRANCHES
All branches’s name must be in lowercase
just replace USERNAME by your nn6 one !
92. Now that we are on the develop’s branch, we can create feature branch :
~/Workspaces/first-project (develop)$ git branch –a
* develop
integration
main
remotes/origin/HEAD -> origin/main
remotes/origin/main
~/Workspaces/first-project (develop)$ git checkout -b feature/ttsp-2737/launch-a-vmaf-analysis
Switched to a new branch 'feature/ttsp-2737/launch-a-vmaf-analysis’
~/Workspaces/first-project (feature/ttsp-2737/launch-a-vmaf-analysis)$ git branch
develop
* feature/TTSP-27-37/launch-a-vmaf-analysis
integration
main
The workflow is similar with bugfix eg: bugfix/ttsp-1245/Fix-a-memory-leak
92
GIT / BRANCHES
93. We can create a hotfix branch from the main’s branch :
~/Workspaces/first-project (feature/TTSP-27-37/launch-a-vmaf-analysis)$ git checkout main
Switched to branch 'main'
Your branch is up to date with 'origin/main’.
~/Workspaces/first-project (main)$ git checkout -b hotfix/ttsp-1245/Fix-database-problem
Switched to a new branch 'hotfix/ttsp-1245/Fix-database-problem'
~/Workspaces/first-project (hotfix/ttsp-1245/Fix-database-problem)$ git branch
develop
feature/TTSP-27-37/launch-a-vmaf-analysis
* hotfix/ttsp-1245/Fix-database-problem
integration
main
93
GIT / BRANCHES
94. 94
GIT / BRANCHES
We are on
the develop’s
branch
Select « Create new branch from »
Because we are already on the develop’s
branch this is possible to select « create new
branch’s name (from the current’s one. We
already experiment that way so we will use
another one.
Now with
vscode
FEATURE
/ BUGFIX
99. 99
GIT / BRANCHES
Now we can fill the right branch’s pattern
hotfix/id-jira/description
and valid with ENTER
100. 100
GIT / BRANCHES
The hotfix
branch’s name
is correct
We can also push the feature/bugfix/hotfix branches to gitlab !
101. Create one branch (from main-USERNAME) :
hotfix/ttsp-1234/USERNAME/memory-leak
Create the two branches (from develop-
USERNAME) :
feature/ttsp-4567/USERNAME/vmaf-sampling
bugfix/ttsp-7890/USERNAME/database-issue
Push your all your branches to GITLAB (origin)
101
GIT / BRANCHES
All branches’s name must be in lowercase
just replace USERNAME by your nn6 one !
105. First of all, create a working branch for your new feature (from
develop) :
~/Workspaces/first-project (develop)$ git checkout -b feature/ttsp-
1234/my-first-files
Switched to a new branch 'feature/ttsp-1234/my-first-files'
105
GIT / FILES
106. We can now add the two files :
~/Workspaces/first-project (feature/ttsp-1234/my-first-files)$ git status
On branch main
Your branch is up to date with 'origin/main'.
Untracked files:
(use "git add <file>..." to include in what will be committed)
Makefile
hello.c
nothing added to commit but untracked files present (use "git add" to track)
~/Workspaces/first-project (feature/ttsp-1234/my-first-files)$ git add Makefile hello.c
~/Workspaces/first-project (feature/ttsp-1234/my-first-files)$ git status
On branch main
Your branch is up to date with 'origin/main'.
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
new file: Makefile
new file: hello.c
106
GIT / FILES
Adding files
107. Commit them localy :
~/Workspaces/first-project (feature/ttsp-1234/my-first-files)$ git log
commit a97b5e2610097529801eec5a4798f688ed227e5b (HEAD -> main, origin/main, origin/HEAD, integration, hotfix/ttsp-1245/Fix-database-
problem, feature/TTSP-27-37/launch-a-vmaf-analysis, develop)
Author: Thierry GAYET <thierry.gayet@enensys.com>
Date: Thu Apr 13 09:34:27 2023 +0000
Initial commit
~/Workspaces/first-project (feature/ttsp-1234/my-first-files)$ git commit -m "Add the two files"
[main d8bc333] Add the two files
2 files changed, 16 insertions(+)
create mode 100644 Makefile
create mode 100644 hello.c
~/Workspaces/first-project (feature/ttsp-1234/my-first-files)$ git status
On branch main
Your branch is ahead of 'origin/main' by 1 commit.
(use "git push" to publish your local commits)
nothing to commit, working tree clean
107
GIT / FILES
Commit files
108. ~/Workspaces/first-project (main)$ git log
commit d8bc333b8557ab15cd088f7250ebb1f4da31aaa9 (HEAD -> main)
Author: Thierry GAYET <Thierry.Gayet@enensys.com>
Date: Fri Apr 14 16:36:57 2023 +0200
Add the two files
commit a97b5e2610097529801eec5a4798f688ed227e5b (origin/main, origin/HEAD, integration, hotfix/ttsp-1245/Fix-database-problem,
feature/TTSP-27-37/launch-a-vmaf-analysis, develop)
Author: Thierry GAYET <thierry.gayet@enensys.com>
Date: Thu Apr 13 09:34:27 2023 +0000
Initial commit
~/Workspaces/first-project (main)$ git push origin main
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 8 threads
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 460 bytes | 460.00 KiB/s, done.
Total 4 (delta 0), reused 0 (delta 0), pack-reused 0
To gitlab.enensys.com:training/git/first-project.git
a97b5e2..d8bc333 main -> main 108
GIT / FILES
Push to the gitlab server (aka origin)
109. ~/Workspaces/first-project (feature/ttsp-1234/my-first-files)$ git status
On branch main
Your branch is up to date with 'origin/main'.
nothing to commit, working tree clean
~/Workspaces/first-project (feature/ttsp-1234/my-first-files)$ git rebase main
Successfully rebased and updated refs/heads/feature/ttsp-1234/my-first-files.
OR
~/Workspaces/first-project (feature/ttsp-1234/my-first-files)$ git rebase main feature/ttsp-1234/my-first-files
Current branch feature/ttsp-1234/my-first-files is up to date.
~/Workspaces/training/first-project (feature/ttsp-1234/my-first-files)$ git checkout main
Switched to branch 'main'
Your branch is up to date with 'origin/main’.
~/Workspaces/training/first-project (main)$ git merge feature/ttsp-1234/my-first-files
Already up to date.
~/Workspaces/first-project (main)$ git push origin main
109
GIT / FILES
We need to switch to the main branch !
We resynchronize the main branch wit the current one
We can resynchronize the main branch with the other one given
On the main branch, we merge our feature branch to main
Finaly we push the local main branch to gitlab
115. 115
GIT / FILES
hello.c is already added
Makefile is not added yet
We can add it using this icon
A mean Added
116. 116
GIT / FILES
The two files are added
Now we can commit and/or push to the gitlab server
117. Then we can create Merge request on GITLAB but we will see that
later.
117
GIT / FILES
118. On your develop-USERNAME, add hello.c +
Makefile to the project to the GIT project
Commit the files
Push your branch to GITLAB (origin)
118
GIT / FILES
All branches’s name must be in lowercase
just replace USERNAME by your nn6 one !
120. Worldwide, interest and adoption of DevOps is growing rapidly. But what
is DevOps ?
1. DevOps is a set of practices that emphasizes collaboration and
communication between software developers and IT operations
professionals, automating the process of software delivery and
infrastructure changes.
2. The term DevOps was born from the union of “development” and
“operations” whose objective is to promote better communication between
the two teams.
3. DevOps aims to create a culture and environment in which the design,
testing and release of software can be done quickly, frequently and
efficiently. DevOps is not just a methodology, it is a real philosophy of work.
DEVOPS
120
121. Benefits of adopting the DevOps approach :
1. Improved quality of code, products and services (reduced bugs, higher change
success rate, etc.)
2. Increased efficiency (eg optimization of time spent on activities that create
added value: unprecedented added value for the customer)
3. Improved time to market
4. Better alignment between IT and business
5. Smaller versions delivered very quickly and very frequently
6. Improved productivity, customer satisfaction, staff satisfaction
7. Less risk and less backtracking
8. Long-term cost reduction
DEVOPS
121
123. The DevSecOps (Development - Security - Operations) approach is an approach that
allows data security to be integrated from the start of a project. The security of these
is considered a prerequisite before starting. The goal is to be able to integrate it into
the entire project life cycle, from development to implementation, using flexible
methods and the DevOps approach.
Integrated into the DevOps process, DevSecOps allows you to configure security test
automation every time your application, software, website is tested and deployed.
This allows anomalies to be detected and corrected quickly.
The DevSecOps approach involves thinking about the security of your project's
applications and infrastructures from the design stage. It is also recommended to
automate some tasks regarding data security to avoid slowing down DevOps workflow.
To achieve these goals, it is necessary to start by selecting tools that can ensure the
continuous integration of security issues, for example, with a common integrated
development environment that provides security functionality. However, for DevOps
security to be effective, it requires more than new tools. It is necessary to culturally
integrate the new security procedures within your teams so that this is implemented
and applied as quickly as possible.
DEVSECOPS / DEFINITION
123
124. Benefits of adopting the DevSecOps approach :
1. Security must be integrated from the start of a project (data protection by design) and into the development and
implementation processes. In the same way that DevOps automates application deployments, DevSecOps automates
security testing. These must be carried out immediately after the first delivery of your project (application, software, etc.).
This applies to development, demo, test and pre-production environments. Automated monitoring of the results of these
tests will alert relevant teams to vulnerabilities in real time long before the final product reaches the production environment.
This process enables early detection of data security gaps and gaps. This allows you to react quickly so that you can deploy
a final product that will have far fewer privacy and data security issues.
2. Develop a culture of safety among your employees
3. For the DevSecOps approach to be effective, close cooperation is required between Dev Ops, Operations teams, IT and
project stakeholders. Therefore, in order to develop a culture of safety, it is necessary to create an atmosphere of trust
between the groups.
4. In order for everyone to feel involved in the cooperation, training and security awareness sessions can be planned. The CIO
plays an important role because he has an overview of the project and the teams and allows him to play a transverse role,
necessary for the proper functioning of the project.
5. Use of computer security automation tools
6. An effective DevSecOps process is only possible with the right tools. The use of a vulnerability scanner, for example, allows
automatic analysis of web applications. This type of tool can be integrated very well into your current operational processes
DEVSECOPS
124
130. The interface of GitLab remains very similar to that of GitHub. However,
GitLab offers options that are less practical :
Project management
Planning / prioritization
Build
Software testing
Application Security
Configuration Management
Monitoring
Continuous integration and deployment, etc.
GITLAB / INTRODUCTION
130
131. Structure of GITLAB :
GITLAB /
131
GIT REPO
Package registry
.deb
.rpm
.tar.gz
Docker registry
Infrastructure registry
(for the deploy using Terraform)
GITLAB
https://gitlab.enensys.com/help/user/packag
es/package_registry/index
https://gitlab.enensys.com/help/user/infrast
ructure/index
git / ssh
https
RUNNERS
CI
.gitlabci.yml
133. GitLab and Docker
Free software Docker launches applications in software containers. For the
use of GitLab, its integration makes it possible to automate certain
functionalities when sending your source code.
For example, it can perform unit tests, send notifications and install "npm
install" type dependencies.
GitLab also has a GitLab agent for the Kubernetes container orchestrator,
which allows it to apply its CI/CD pipeline to Kubernetes clusters.
GITLAB / DOCKER
133
134. GitLab API
To benefit from the GitLab API documentation, the company offers online
documentation, as well as a search engine to find answers to more specific
technical questions.
https://docs.gitlab.com/ee/api/
https://docs.gitlab.com/search/
External build require API TOKENS !
GITLAB / API
134
135. What is GitLab CI?
GitLab CI/CD is a GitLab tool designed to manage the continuous
integration and deployment of application code and revisions. GitLab CI/CD
goes through the configuration of a file called .gitlab-ci.yml placed in the
root directory. A file that generates a pipeline executing code changes
within the code repository.
GITLAB / CI
135
136. GIT WORKFLOW :
136
REMOTE / ORIGIN
GITLAB’S SERVER
LOCAL
YOUR COMPUTER
+ fetch
138. What is a GitLab Runner?
Gitlab-runner is the application for running
tasks in a GitLab CI/CD pipeline.
If installing Gitlab-runner locally, it is recommended
to deploy it on a separate machine from the one
hosting the GitLab instance, both for performance
and security reasons.
Each must be equipped with its own software
stack: OS, Kubernetes, Docker...
GITLAB / RUNNER
138
142. Some of the specific actions that the Developer permission role is able to take
include:
Create new branches
Remove certain branches
Lock merge request threads
Create, manage, accept, and label merge requests
Create or update a commit status
Delete images from a container registry
Add tags to the issue tracker
Create and edit Wiki pages
Apply code change suggestions
Create, edit, and delete project milestones
142
GITLAB / PERMISSIONS
144. The Maintainer role can take all the actions allowed in the Developer role, as
well as actions including:
Add new members to the project
Determine write protection status for branches
Determine write protection status for pushes to branches
Edit the settings for the project
Configure project hooks
Manage job triggers
Manage runners
Manage environmental variables
Manage domains
Manage certificates
Manage and delete GitLab Pages
Edit comments that any user posts
Delete Wiki pages 144
GITLAB / PERMISSIONS
147. To create a new git repo, we need to be in the right group
Each git repo have its own :
Docker registry
Package registry
Infrastructure registry
CI / CD pipeline (.gitlabci.yml file)
WIKI
Settings
147
GITLAB / CREATE
150. GITLAB / CREATE
150
Name of the new GIT repo
NN6 base URL
Option for the repo
Visibility
Namespace Name of the repo
Validate with create project
For the new repo :
Base URL : https://gitlab.enensys.com/
Namespace : training/gitlab
Project’s name : my-second-project
Final GIT url : GIT git@gitlab.enensys.com:training/gitlab/my-second-project.git
Final https url : https://gitlab.enensys.com/training/gitlab/my-second-project.git
151. When we have always the same namespace, we can set/use groups :
151
GITLAB / CREATE
152. 152
GITLAB / CREATE
If you don’t have access to some groups, you can send an email to helpdesk@enensys.com
154. GITLAB / CREATE
154
Identity
Last commit message / SHA1
URLs for the clone
Links to open in VS code
or others IDE
First file
Quick shortcuts
Default’s branch
Summary
155. 155
Create a private git repo called « myrepo-
USERNAME » inside the traning/gitlab
namespace
(https://gitlab.enensys.com/training/gitlab)
Create all the branches according to the
gitflow (using VSCODE and/or GITLAB)
Check that the default’s branch is main
Restrict any direct push to main, intégration
and develop
Add one hello.c and Makefile files
Add a .gitignore file (filled with
https://www.toptal.com/developers/gitignore)
Add, commit and push all to GITLAB
All branches’s name must be in lowercase
just replace USERNAME by your nn6 one !
GITLAB / CREATE
157. The following slides will be usefull to customize a new repo but also
an existing one.
We will see step by step what is to customize…
157
GITLAB / INFO
161. GITLAB / REPO.
161
The following files or directories can only be modified by the user who locked them.
To see what's changed or create a merge request, choose a branch or tag (like main ), or enter a commit (like 4eedf23 ).
Changes are shown as if the source revision was being merged into the target revision.
Display a graph of the commits by branch
Stats of commits by users
Create/List/Delete Tags for the releases
List of the files per branch
List of the commits per branch
Create/List/Branches
162. GITLAB / REPO. / GRAPH
162
Example ot GIT repository with no branches (very flat) !
168. Merge request can be used for :
Code review
Share code between team members
Validate modification from one branch to another one
feature or bugfix branches develop’s branch
develop’s branch integration’s branch
integration’s branch main’s branch
Only if the hotfix is cleaned :
hotfix’s branch integration’s branch
Integration’s branch to develop’s branch
MR workflow :
168
GITLAB / Merge Request
Creation Validation Merge Destroy source’s branch
169. GITLAB / Merge Request
169
Workflow :
A developer has finished developing a feature / a bugfix and asks to merge his code to the develop branch
He makes a merge request to one or more of his colleagues
One of his colleagues makes a remark to him that he must take into account
After modification resulting from the remark, a new push is carried out with the same Merge Request
This time, the MR is validated
Then, the code can be merged
If the branch’s destruction request has been selected, it will be destroyed
170. 170
GITLAB / Merge Request
Name of
the repo
Branch’s source
Destination’s branch
Select this button to compare
the two branches
171. 171
GITLAB / Merge Request
One or more reviewer
Just a comment on
what i am merging
Name of the
merge (feature’s
name, what is
fixed, …)
172. 172
GITLAB / Merge Request
Delete the (feature/bugfix/hotfix/…) branch after the merge request
Proceed to the MR
Each reviewer will receive an email that will notify them about the MR
Commit(s) impact with this merge request
173. 173
GITLAB / Merge Request
Checkout, edit
the branch from
gitlab
Number of
merge
request
associated
to me
We can valid the MR or not
We can add a comment for
the develop that describe
why we cannot valid the MR
If we are okay with the
MR we can launch the
Merge
174. 174
Create new feature branch (from develop)
using the gitflow (idJIRA=TTSP-1235 /
Description=« Mys first feature »)
Add new test.c + test.h (fake) file to the repo.
Add+commit them to the branch
Push to your branch
(GITLAB) Make a MR from the feature’s branch
to the develop’s branch
Add comment to your MR
Accept and merge your MR
Watch the result on gitlab
All branches’s name must be in lowercase
just replace USERNAME by your nn6 one !
GITLAB / SETTINGS
175. CI - Continuous Integration : this is useful for …
Launching linters (coding style checkerker : cppchecker, pylint, … )
Building the service/component
Launching unit tests (with address sanatizer in c++)
Generating automatic documentation (eg: doxygen)
Creating docker, deb/rpm/… packages, tarballs, ...
Building a buildroot firmware
Creating a VM using Hashicorp packer
175
GITLAB / CI/CD
176. CD – Continuous Delivery : this is useful for …
Adding tag to a docker
Pushing a docker to a docker’s registry according to the branch (one
registry per branch : develop, integration, main)
Pushing a rpm/deb/tarball to the package’s registry
Pushing helm charts to a kubernetes (k8s)
Deploying images created with packer using Hashicorp Terraform
176
GITLAB / CI/CD
177. 177
GITLAB / CI/CD
Gitlab bring a lot of templates
… / …
The goal of those template will be to add
a ..gitlab-ci.yml adapt to a language
179. 179
GITLAB / CI/CD
# This file is a template, and might need editing before it works on your project.
# You can copy and paste this template into a new `.gitlab-ci.yml` file.
# You should not add this template to an existing `.gitlab-ci.yml` file by using the `include:` keyword.
#
# To contribute improvements to CI/CD templates, please follow the Development guide at:
# https://docs.gitlab.com/ee/development/cicd/templates.html
# This specific template is located at:
# https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/C++.gitlab-ci.yml
# use the official gcc image, based on debian
# can use versions as well, like gcc:5.2
# see https://hub.docker.com/_/gcc/
image: gcc
build:
stage: build
# instead of calling g++ directly you can also use some build toolkit like make
# install the necessary build tools when needed
# before_script:
# - apt update && apt -y install make autoconf
script:
- g++ helloworld.cpp -o mybinary
Docker image that include gcc
Because the image is a docker file, we can use our image or customize the origginal’s one !
180. 180
artifacts:
paths:
- mybinary
# depending on your build setup it's most likely a good idea to cache
outputs to reduce the build time
# cache:
# paths:
# - "*.o"
# run tests using the binary built before
test:
stage: test
script:
- ./runmytests.sh
deploy:
stage: deploy
script: echo "Define your deployment script!"
environment: production
GITLAB / CI/CD
188. Example of pipeline (ci) will do what you want it to do :
188
LINTERS :
cppcheck,
pylint,
dockerlint,
…
BUILD UNITTEST
API
DOCUMENTATION
(doxygen)
If one step is wrong, the pipeline will stop and send one email.
GITLAB / CI/CD
Create docker
image
…
The earlier a test is carried out, the faster the problems are handled because it tells the developer that
something is not compliant and thus avoids waiting for functional integration tests
189. Example of pipeline (cd) will do what you want it to do :
189
Tag a docker
image
Login to the
registry
Push a docker
image to t he
registry
Launch automatic
tests
If one step is wrong, the pipeline will stop and send one email.
For security purpose, all push in production (main branch) MUST be manual !
GITLAB / CI/CD
…
190. 190
Running (now or
previously) can be
viewed here
We can see the exécution’s trace of the pipeline
(see on, next slide)
GITLAB / CI/CD
191. 191
If one pipeline failled, the
traces are very usefull to know
the origin of the problem.
192. 192
GITLAB / CI/CD
This is possible to launch CI pipeline every nigtht, in order to have a sanity check on one repo, on a specific branch, …
193. We can work (update) the dockers launch for the pipelines :
$ docker login gitlab.enensys.com:4567
Username: gayett
Password:
WARNING! Your password will be stored unencrypted in
/home/ubuntu/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Login Succeeded
Now we can pull / update and push our docker image that host binaries useful for our
unit test, linters and co ….
193
GITLAB / CI/CD
194. 194
GITLAB / Packages and registries
Gitlab can manage :
Container registry :
o Docker images
Package registry :
o debian (deb)
o redhat packages (RPM)
o tarballs (ZIP, tar.gz, ….)
Infractructure registry :
o final images or firwmwares (to deploy)
and more …
196. At any time this is possible to modify the settings of a specify repo
For security purpose, only maintainers or owners can modify it.
196
GITLAB / Settings
198. Settings / General / Advanced / Change path
Usefull to rename a project or to move it from one namespace to
another one :
198
199. Settings / Integration
Gitlab can be linked with external tools :
199
GITLAB / Settings
200. Settings / Repository
Define main branch at the clone time :
200
GITLAB / Settings
201. Settings / Repository / branch default
Specify a pattern as a regexp for branch’s name
201
GITLAB / Settings
202. Settings / Repository / protected branches
Avoid any direct push to
main/integration/develop (must use MR)
202
GITLAB / Settings
203. Integration with JIRA in order to push SHA1 commit to User Story :
https://about.gitlab.com/blog/2021/04/12/gitlab-jira-integration-
selfmanaged/
203
GITLAB / Settings
204. 204
Create a .gitlabci.yaml file from scrach or
using a template)
Make it work and run it
If you have time, customize a docker image,
add tools and push it back to the gitlab
docker’s registry.
All branches’s name must be in lowercase
just replace USERNAME by your nn6 one !
GITLAB / SETTINGS
207. Because it is not possible to switch to another branch until the
current branch has committed everything, git proposes the use of an
area called stash which allows to save modifications which can be re-
imported by the following :
$ git stash We backup our current work (on branch XXX)
$ git checkout main
(do something here)
$ git add files …
$ git commit –m “urgent modification”
$ git push origin main
$ git checkout XXX
$ git stash list
$ git stash pop here we can continue on our previous work
GIT / STASH
207
209. 209
Add several files (as you want)
Try to swicth to another branch
(You should have a problem here)
Now, stash your current work
Switch to a branch
(Here we can make something urgent)
Got back to you previous branch
List the stash wor
Pop your last work
(Now we can continue to work)
All branches’s name must be in lowercase
just replace USERNAME by your nn6 one !
GITLAB / STASH
211. In order to avoid overloading a git repo with large files which would
ultimately take a long time to clone, git lfs is very useful because it
allows large files to be separated into a separate channel from the
usual clone.
For that purpose, you must have the git-lfs client installed on your
system.
https://docs.gitlab.com/ee/topics/git/lfs/
https://docs.gitlab.com/ee/user/project/settings/index.html#configur
e-project-visibility-features-and-permissions
GIT / LFS
211
GITLAB (GIT)
LFS
212. Your gitlab projet must be enabled for that feature :
212
GIT / LFS
213. Add filter to git repo for some extension to be managed by git lfs :
Download and install the Git command line extension.
Once downloaded and installed, set up Git LFS for your user account by running:
$ git lfs install
You only need to run this once per user git user account.
In each Git repository where you want to use Git LFS, select the file types you'd like Git
LFS to manage (or directly edit your .gitattributes).
You can configure additional file extensions at anytime.
$ git lfs track "*.psd"
Now make sure .gitattributes is tracked:
$ git add .gitattributes
$ git commit –m “add lfs filtering for psd files”
$ git push origin main
213
GIT / LFS
214. Note that defining the file types Git LFS should track will not, by itself,
convert any pre-existing files to Git LFS, such as files on other branches
or in your prior commit history. To do that, use the git lfs migrate
command, which has a range of options designed to suit various
potential use cases.
As a test, just commit and push to gitlab as you normally would ; for
instance, if your current branch is named main:
$ git add file.psd
$ git commit -m "Add photoshop design file"
$ git push origin main
A “git lfs status” command will show you all files managed by git and that
will be pushed to gitlab by this way.
214
GIT / LFS
215. For existing git repo, this is possible to cleanup using bfg :
First clone a fresh copy of your repo, using the --mirror flag :
$ git clone --mirror git@gitlab.enensys.com:training/git/some-big-repo.git
This is a bare repo, which means your normal files won't be visible, but it is a full copy of the Git database
of your repository, and at this point you should make a backup of it to ensure you don't lose anything.
Now you can run the BFG to clean your repository up:
$ wget https://repo1.maven.org/maven2/com/madgag/bfg/1.14.0/bfg-1.14.0.jar
$ java -jar ./bfg-1.14.0.jar --strip-blobs-bigger-than 100M some-big-repo.git
The BFG will update your commits and all branches and tags so they are clean, but it doesn't physically
delete the unwanted stuff. Examine the repo to make sure your history has been updated, and then use the
standard git gc command to strip out the unwanted dirty data, which Git will now recognise as surplus to
requirements:
$ cd some-big-repo.git && git reflog expire --expire=now --all && git gc --prune=now --aggressive
Finally, once you're happy with the updated state of your repo, push it back up (note that because your
clone command used the --mirror flag, this push will update all refs on your remote server) :
$ git push
Official repo : https://rtyley.github.io/bfg-repo-cleaner/
215
GIT / LFS
216. 216
GIT / LFS
Now with
vscode
https://github.com/microsoft/vscode-dev-containers/blob/main/script-
library/docs/git-lfs.md
217. 217
Enable LFS setting on your git repo (GITLAB)
Check you have git lfs install on your system
Add GIT lfs support to your repo
Check the .gitattributes file and add/commit it
Add a filter with *.mp4 and *.ts files
Add a ts file and check the file is well tracked
using git-lfs status
Push all to gitlab and check what is managed
over LFS
Try to clone you repo in a /tmp directory, just
to check everything.
All branches’s name must be in lowercase
just replace USERNAME by your nn6 one !
GITLAB / LFS
219. Imagine a part of git repo that could be factored between several other
repos such as a submodule that would be attached.
To do this, git sub-modules were invented to allow you to link a repo
Create a git repo that will be linked
Add the repo to each repo that will need to be linked
Commit and push the .gitmodules file and the folder of the submodule itself
GIT / SUBMODULE
219
GIT REPO
FACTORIZED
GIT
REPO A
GIT
REPO B
220. Immagine you are inside a repo git already cloned. You can add the fatorized repo
like this :
~/Workspaces/first-project (develop)$ git submodule add
git@gitlab.enensys.com:training/git/DbConnector
Cloning into 'DbConnector'...
remote: Counting objects: 11, done.
remote: Compressing objects: 100% (10/10), done.
remote: Total 11 (delta 0), reused 11 (delta 0)
Unpacking objects: 100% (11/11), done.
Checking connectivity... done.
By default, submodules will add the subproject into a directory named the same as the
repository, in this case “DbConnector”.
GIT / SUBMODULE
220
221. If you run git status at this point, you’ll notice a few things.
~/Workspaces/first-project (develop)$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
new file: .gitmodules
new file: DbConnector
First you should notice the new .gitmodules file. This is a configuration file that stores the mapping between the project’s
URL and the local subdirectory you’ve pulled it into:
[submodule "DbConnector"]
path = DbConnector
url = git@gitlab.enensys.com:training/git/DbConnector
If you have multiple submodules, you’ll have multiple entries in this file. It’s important to note that this file is version-
controlled with your other files, like your .gitignore file.
It’s pushed and pulled with the rest of your project. This is how other people who clone this project know where to get the
submodule projects from.
221
GIT / SUBMODULE
222. Don’t forget to commit and push the .gitmodules file and the repo that host the factorized git repo :
~/Workspaces/first-project (develop)$ git commit -am 'Add DbConnector module'
[master fb9093c] Add DbConnector module
2 files changed, 4 insertions(+)
create mode 100644 .gitmodules
create mode 160000 DbConnector
Notice the 160000 mode for the DbConnector entry. That is a special mode in Git that basically means you’re
recording a commit as a directory entry rather than a subdirectory or a file.
To update the revision of a submodule within a git repo, you can just enter into the submodule folder, then
switch to a new sha1, tag or branch of the submodule. Then got back at the root path of the repo that host
the git submodule and just commit the folder.
Lastly, push these changes:
~/Workspaces/first-project (develop)$ git push origin master
222
GIT / SUBMODULE
223. When cloning a repo, the .gitmodules is pull with the other files but the
folder of each submodule are empty.
To initialise the folder we can use the following commands :
~/Workspaces/first-project (develop)$ git submodule init
~/Workspaces/first-project (develop)$ git submodule update
To clone and initialize each submodule, you can do it that way :
~/Workspaces/first-project (develop)$ git clone --recurse-submodules
git@gitlab.enensys.com:training/git/first-project.git
223
GIT / SUBMODULE
224. GIT / SUBMODULE
224
Now with
vscode
https://marketplace.visualstudio.com/items?itemName=ivanhofer.git-
assistant#:~:text='Git%20(Submodule)%20Assistant',and%20assists%20yo
u%20with%20fixes.
225. 225
Clone the repo « my-first-project » from the
HEAD as a submodule
https://gitlab.enensys.com/training/git/first-
project
Watch the .gitmodules file
Add the .gitmodules file and the folder of the
repo cloned
Commit and push all to gitlab
All branches’s name must be in lowercase
just replace USERNAME by your nn6 one !
GITLAB / SUBMODULES
227. LINKS :
o https://git-scm.com/doc
o https://git-scm.com/docs
o https://git-scm.com/book/en/v2
o https://git-scm.com/doc/ext
o https://git-scm.com/docs/gittutorial
o https://gitimmersion.com/
o https://github.com/sensorflo/git-draw/wiki
o http://www-cs-students.stanford.edu/~blynn/gitmagic/
o https://git-scm.com/docs/giteveryday
o https://nulab.com/learn/software-development/git-tutorial/git-basics/
o https://github.com/progit/progit2-fr/releases/download/2.1.70/progit.pdf
o https://github.com/progit/progit2/releases/download/2.1.360/progit.pdf
https://www.amazon.fr/s?k=git&i=stripbooks&__mk_fr_FR=%C3%85M%C3%85%C5%BD%C3%95%C3%91&crid=424VPI44G9P
5&sprefix=git%2Cstripbooks%2C105&ref=nb_sb_noss_1
GIT / HELP
227
(Official printed documentation)
229. If you want to go more in detail about dev(sec)ops automations, I can
do a third training specific to CI/CI chain-oriented CI, to build a docker
image, push a helm chart into a kubernetes, build a buildroot image /
yocto, ...... gitlab can do everything :-)!
MORE
229
230. Next part, the NN6 official :
gitflow, versionning and svn
migration.
230
231. ENENSYS
4A rue des Buttes
CS 37734
35 577 Cesson-Sévigné – France
Phone (+33) 1 70 72 51 70
Email contact@test-tree.com
www.enensys.com
231