Introduction
In this article, we are going to explore basic CI-CD workflow with Gitlab CI and going to see the demo for the creation of .gitlab-ci.yml file GitLab and introduction to docker.
Overview
Continuous Integration
It's a practice. When you are using CI means every time you make a change to code that code gets integrated with the work others did.
Continuous Delivery
It ensures that the software can be deployed anytime to production.
For the demo purpose, we are taking the example of a House building application.
While building any house there are few stages that need to be followed as listed below,
- Frame stage
- Lockup stage
- Fixing stage
- Practical completion stage
We are going to create a GitLab pipeline for this requirement.
So, for creating GitLab pipeline you need to create a new file and name it as- .gitlab-ci.yml
The first thing that we need to do is create a job.
What is Job?
Job is nothing but a task that GitLab does for us.
So let's write the below lines in our .gitlab-ci.yml file.
stages
- build
- test
build the house :
stage: build
script:
- mkdir build
- cd build
- touch house.txt
- echo "Frame" >> house.txt
- echo "Lockup" >> house.txt
- echo "Fixing" >> house.txt
- echo "PracticalCompletion" >> house.txt
artifacts:
paths:
- build/
test the house:
stage: test
script:
-ls
- test -f build/house.txt
- cd build
- cat house.txt
- grep "Frame" house.txt
- grep "Lockup" house.txt
- grep "Fixing" house.txt
- grep "PracticalCompletion" house.txt
Now let's get dive into the above commands what that actually means,
touch
This command is a very simple way to create new, empty files,
touch <filename>
echo
This command is used to display line of text/string,
echo [string] > - with greater than operator ">" the output from the echo command will be redirected to a file called house.txt if the file house.txt already exists it will be deleted.
test
This command is used to verify that the file house.txt was created.
The -f flag is needed to check that the specified file exists and is a regular file.
grep
This command is used for searching lines that match a regular expression.
It does a global search with the regular expression and prints all matching lines.
Use below two commands for debugging,
- ls- list content of the folder
- cat- show us the content
In order to specify the order of job runs, we need to specify stages.
The exit code needs to be 0 for a script to be marked as successful by the GitLab runner.
The test has responded with the exit code 1 => job failed!
Observations
Gitlab runner
It is a tool used by GitLab to run your jobs and sends the results back to GitLab
Artifact repository
In order to tell the first job what to save we need to define artifact.
Here, the house.txt artifact file shows only PracticalCompletion because it's the last step in the build.
Continuous Integration (CI)
It is a practice when you are using Continuous Integration means every time you make a change to code that code gets integrated with the work others did.
- The practice of continuously integrating code changes
- Ensures that the project can still build/compiled'
- Ensures that any changes pass all tests, guidelines, and code compliance standards
Continuous delivery
It ensures that the software can be deployed anytime to production.
- Commonly the latest version is deployed to a testing or staging system.
Advantages of CI
- Errors are detected early in the development process
- Reduces integration problem
- Allows the developer to work faster
Advantages of CD
- Ensures that every change is releasable by testing that can be deployed
- Reduced risk of the new deployment
- Delivers value much faster.
Docker
It is technology based on containers that allow virtualization.
Docker images
An image is a file with a set of instructions on how to package up code or utilities and all dependencies.
When the docker executes an image, it becomes a container that is similar to a virtual machine.
docker for deploying applications
dockers allows us to package applications and all necessary dependencies and to easily deploy them.
Summary
In this article we are explored basic CI-CD workflow with Gitlab CI and going to see the demo for the creation of .gitlab-ci.yml file GitLab and introduction to docker.
I hope you liked the article. Until Next Time
Happy Learning Cheers