0% found this document useful (0 votes)
212 views

Git Lab Advanced Uses Seminar Slides

Uploaded by

ravindra mittal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
212 views

Git Lab Advanced Uses Seminar Slides

Uploaded by

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

GitLab Seminar - Advanced

A review of GitLab’s advanced features and


how to utilize them
Sean Vail
Software QA Engineer
GitLab Admin, GitHub Admin, & SWS Admin

August 29, 2019

w w w. e p r i . c o m © 2019 Electric Power Research Institute, Inc. All rights reserved.


Overview

 Continuous Integration (CI) Pipelines


 GitLab Runners
 The .gitlab-ci.yml file
 Building or Compiling from source code
 Git Large File Storage (LFS)
 Q&A

2 www.e pr i .c om © 2019 Electric Power Research Institute, Inc. All rights reserved.
Git & GitLab Basics

 Previous Git/GitLab Seminar – September 2017


– Slides & Recording
 Can be found at swdev.epri.com > News > 2017 > 2017 EPRI GitLab
Software Development Seminar
 Link to slides
 Link to recording
– Covers the basics of version control with Git, setup, and how to get
access to GitLab

3 www.e pr i .c om © 2019 Electric Power Research Institute, Inc. All rights reserved.
GitLab CI Pipelines

 A GitLab pipeline is a series of jobs used to build, test, and/or


deploy code whenever a new commit is pushed to a GitLab
repository.

https://gitlab.epri.com/<project-path>/pipelines

4 www.e pr i .c om © 2019 Electric Power Research Institute, Inc. All rights reserved.
GitLab Runner

 Executes GitLab CI Pipeline jobs


 Can be installed on Windows or Linux systems as a service [1]
 Runners must be registered with GitLab as a shared runner or
locked to a specific project/group [2]
 Each Runner is a specific type of executer (e.g. ssh, shell, docker,
or others) [3]
 Runners tags can be used to describe installed software and
intended use (e.g. Windows, msdeploy, npm)

https://gitlab.epri.com/<project-path>/-/settings/ci_cd
5 www.e pr i .c om © 2019 Electric Power Research Institute, Inc. All rights reserved.
Choosing a Runner

 Shared
– Registered to a GitLab group & can be used by any project in that group
 Dedicated
– Registered to a specific project
 EPRI IT Hosted
– Maintained by SQA
– Project must be managed by SQA
– Required for Subscriber Website (SWS) deployments

6 www.e pr i .c om © 2019 Electric Power Research Institute, Inc. All rights reserved.
GitLab CI Jobs

 A Job is a series of commands that runs on the GitLab Runner


 These commands are run in the Runner host machine’s environment

 Each job generally fulfills one “task” in


the process. For example:
– Build
 Download build dependencies
 Compile the source code
 Create installers (when applicable)
– Config
 Configure database connection
 Insert secret variables
– Deploy
 Deploy build to the web server
 Deploy executable to folder

7 www.e pr i .c om © 2019 Electric Power Research Institute, Inc. All rights reserved.
GitLab CI Jobs continued

 The output from each job


is collected and logged in
the GitLab pipeline logs.
 The Runner counts the job
as failed if a non-zero error
code is returned by any of
your script commands.

https://gitlab.epri.com/<project-path>/-/jobs

8 www.e pr i .c om © 2019 Electric Power Research Institute, Inc. All rights reserved.
The .gitlab-ci.yml file

 A YAML file that defines a series of Variables, Stages, Jobs that get
executed with every new Pipeline.
 A basic job consists of the following elements:
– stage – Determines order in which jobs are executed
– script – Commands that are executed by the runner

Full YAML file:


https://gitlab.epri.com/snippets/37

9 www.e pr i .c om © 2019 Electric Power Research Institute, Inc. All rights reserved.
The .gitlab-ci.yml file continued

 Some jobs may require additional components:


– dependencies – Job won’t run until a specified prior job succeeds [4]
– only – Job only runs when certain refs (e.g. branches or tags) change [5]
– when – Set job to run based on result of prior jobs or by manual trigger
[6]
– tags – Job will only run on Runners that are registered with the specified
tags [7]
– cache – Keep certain files between jobs (build folder is reset when a new
job starts by default) [8]
– artifacts – Upload specific build artifacts to GitLab after job [9]
– environment – Tags the name and URL of the environment that your job
is running on [10]

10 www.e pr i .c om © 2019 Electric Power Research Institute, Inc. All rights reserved.
The .gitlab-ci.yml file continued

 The behavior that determines when each job will run is highly
customizable, jobs can be triggered based on:
– Changes to specific branches [11]
– Variable comparisons [12]
– Changes to specific files [13]
– A full list of .gitlab-ci.yml features can be found here: [14].

 GitLab also injects variables to the runner environment such as:


– Branch names
– Tag names
– Commit SHA values
– CI/CD variables [15]
– Other relevant predefined meta data variables [16]

11 www.e pr i .c om © 2019 Electric Power Research Institute, Inc. All rights reserved.
.gitlab-ci.yml file breakdown

12 www.e pr i .c om © 2019 Electric Power Research Institute, Inc. All rights reserved.
.gitlab-ci.yml file breakdown continued

13 www.e pr i .c om © 2019 Electric Power Research Institute, Inc. All rights reserved.
Code Building Jobs

 Building, Compiling, or Transpiling a project using GitLab CI/CD


Pipelines requires the following:
– GitLab Runner (See slide 6)
– Package management (Recommended)
– Installed Dependencies (Avoid when possible)
– Build tools
– Build script
 Advantages
– Allows better collaboration on you project
– When configured properly, ensures long-term maintainability of project
– No binaries in version control

 Disadvantages
– Upfront time & labor cost of configuring runners and build scripts

14 www.e pr i .c om © 2019 Electric Power Research Institute, Inc. All rights reserved.
Using EPRI IT managed runners for builds

Source code builds on IT managed runners will require:


 Project to be created and managed by SQA
 Developers cannot modify .gitlab-ci.yml
 Default branch will be development
– DEV, TEST, and PROD branches will be protected against direct pushes
– Changes must be merged from development to DEV

15 www.e pr i .c om © 2019 Electric Power Research Institute, Inc. All rights reserved.
Package Management

 Should be used whenever possible


 Minimizes software installations on build servers
 Ensures long-term maintainability of the project
 Tools vary depending on project language and framework
– Node.js – npm (or Yarn)
– Python – pip
– .NET – nuget
– etc…

16 www.e pr i .c om © 2019 Electric Power Research Institute, Inc. All rights reserved.
Installed Dependencies & Build Tools

Installed Dependencies
 Package management may not be viable for specific dependencies
 Installing on the Runner environment may be necessary

Build Tools
 Need to be installed on runner environment
 Tools varies depending on project language and framework
– Node.js – npm
– C – gcc
– .NET – msbuild (and Visual Studio build tools)

17 www.e pr i .c om © 2019 Electric Power Research Institute, Inc. All rights reserved.
Build Script

 An automated series of steps that does the following:


– Installs dependencies from package manager
– Compiles or transpiles your code into build artifacts

 Examples:
– Node.js
npm install
npm run-script build

– .NET
nuget restore
msbuild /t:Build /p:Configuration=Release /p:TargetFramework=v4.5.2

18 www.e pr i .c om © 2019 Electric Power Research Institute, Inc. All rights reserved.
Git Large File Storage

 Checking in binary files to version control should be avoided when


possible.
 Operations on Git repositories become slow and inefficient when
large binary files are present
 When there are no alternatives to large binary files, Git LFS should
be used.

19 www.e pr i .c om © 2019 Electric Power Research Institute, Inc. All rights reserved.
Git LFS Installation and Usage

 Download the Git extension: https://git-lfs.github.com/


 Enable Git LFS in your repository (one time operation)
git lfs install

 Set Git LFS to track your large file’s extension


git lfs track “*.pdf”
 Stage .gitattributes (only required after lfs track is used)

git add .gitattributes


 Stage your large file(s)

git add largeFile.pdf


 Commit and push like normal

git commit –m “Adding large pdf to repo”


git push

20 www.e pr i .c om © 2019 Electric Power Research Institute, Inc. All rights reserved.
Q &A

21 www.e pr i .c om © 2019 Electric Power Research Institute, Inc. All rights reserved.
Together…Shaping the Future of Electricity

22 www.e pr i .c om © 2019 Electric Power Research Institute, Inc. All rights reserved.

You might also like