GitLab CI/CD for Beginners in 1 Hour [FREE Course]
In this GitLab Crash Course, I will teach you everything you need to know to get started with GitLab CI/CD in 1 hour 🚀 😊 This should give you a short overview and introduction.
Overview - What you’ll learn in 1 Hour ✅
What is GitLab CI/CD
GitLab compared to other CI/CD platforms
Overview of GitLab Architecture
Build a full GitLab CI/CD pipeline for a Python demo app that
builds a Docker image,
pushes to a private Docker repository and
deploys the app to a remote server on DigitalOcean
Learn GitLab Basic Concepts on the way:
GitLab Runners and Executors
Variables (Variable and File Type)
Docker in Docker
What is GitLab CI/CD?
First of all, what is Gitlab CI/CD, and why should you even care?
GitLab platform generally is striving to become THE DevOps platform or a one-stop shop for building DevOps processes for your applications. 🚀
So they have exactly this roadmap, and they're working towards that, which means they're actually integrating and creating new features to basically give you everything in one platform to build complete DevOps processes, and a big part of those processes is a CI/CD pipeline.
What is CI/CD in simple words
So, first of all, what is CI/CD in simple words?
CI/CD stands for Continuous Integration and Continuous Deployment or Continuous Delivery, and what it basically means is automatically and continuously testing, building, and releasing code changes to the deployment environment.
So that means when a developer commits a new code into the Gitlab repository, Gitlab will automatically execute a CI/CD pipeline that you have configured for your project to release those code changes to the end environment, where the end users can access them:
But this CI/CD concept is a topic of its own. If you want to understand it on a deeper level, then you can check out my video about DevOps and CI/CD pipeline, where I explain this in more detail here: What is DevOps?
But as I said, in simple terms, CI/CD is to continuously release your code changes to the end environment, and in this crash course, we will be building a simplified version of a CI/CD pipeline using Gitlab CI/CD.
Many CI/CD platforms
Of course, there are many CI/CD tools, one of the most used ones in the industry still being Jenkins. And Gitlab CI/CD is just one of those other CI/CD platforms:
Source Code & CI/CD on the Same Platform
All of them have their advantages and disadvantages. Still, a big advantage of using Gitlab to build CI/CD pipelines for your applications is that you already have your code on Gitlab, so this is an extension of your software development processes in your team, where you can also build CI/CD pipelines on the same platform:
So your team already works with Gitlab, and you have your code there, so this is basically an additional feature that you can extend your workflows on Gitlab with, and you don't need a separate tool for that. 👍
Apart from that, Gitlab makes that extension very seamless by allowing you to get started without any setup effort and also having your pipeline as part of your application code compared to Jenkins, for example, where you have to set up and configure the Jenkins server, create a pipeline and then connect it to the Git project:
With Gitlab, you can start without any of this configuration effort, and we will see that in the demo part. ✅
Now if you don't have to set up anything and configure any servers to run the pipelines, how does it actually work? And this leads us to the topic of Gitlab architecture and how it works.
You have a Gitlab instance or also called Gitlab server, that hosts your application code and your pipelines and basically the whole configuration. So it knows what needs to be done.
And connected to that Gitlab instance, you have multiple GitLab runners, which are separate machines connected to the Gitlab server machine, which are actually the ones executing the pipelines.
So the Gitlab server knows what needs to be done, and the GitLab runner actually does that:
Managed or SaaS
And www.gitlab.com is actually a managed Gitlab instance that offers multiple managed runners already out of the box.
So these are all maintained by Gitlab, and that's why you can start running your pipelines without any setup and configuration effort using this managed setup.
And this is already enough for starting out, but of course, for your own organization, you may want to manage the runners or the whole setup yourself.
So you can create partially or completely self-managed GitLab setup as well:
In this crash course, we will use Gitlab's managed infrastructure and free features to build our release pipeline. So we will not need to configure anything ourselves. 👍
Pipeline Configuration - .gitlab-ci.yml
Now the question is, how do we create a Gitlab CI/CD pipeline? 🤔
Well, following the concept of Configuration as Code or Pipeline as Code, the whole pipeline will be written in code and hosted in the applications git repository itself in a simple YAML file.
And the file has to be called .gitlab-ci.yml, so that Gitlab can automatically detect that pipeline code and execute it without any extra configuration effort from our site:
So in the root of the project's repository, we're going to create this YAML file, and we're going to write all the pipeline configurations inside. We can actually do that directly in the GitLab UI as well, so we don't have to switch back and forth from the editor to Gitlab:
The tasks in the CI/CD pipeline, such as running tests, building an image, deploying to a server, etc., are configured as what's called 'jobs':
So jobs are the most fundamental building block of a .gitlab-ci.yml file. They define what to do.
Each job has a name, and inside the job, we have a couple of parameters or a couple of attributes or things that we want to configure for the job.
The first attribute and the only required attribute of a job is what's called a script. And the script is basically where we list any commands that should be executed for that job:
So, for example, for 'run tests', we need to execute make test for our python demo application. This is the command that needs to be executed in order to run the test, so we're going to write that command:
However, in order for this to run successfully, we need to do a couple of things.
But for the actual demo part, let's continue with the video, so you can follow along more easily: 🤓
▬▬▬▬▬▬ R E F E R E N C E S 🔗▬▬▬▬▬▬ ► Git repo we build the CI/CD pipeline for: https://gitlab.com/nanuchi/gitlab-cicd-crash-course
▬▬▬▬▬▬ Course Pre-Requisites ▬▬▬▬▬▬
Hope you will learn a lot in this beginner tutorial!
Complete GitLab CI/CD course with Docker, Kubernetes and Microservices 🚀
Also if you are serious of learning GitLab CI/CD, be sure to check out our complete GitLab CI/CD course. You will learn how to build production-ready CI/CD pipelines in one comprehensive and practical course!