That project will emphasize the different steps to build a basic python app pipeline. We will self-host every product that we are going to use in this tutorial, which will allow us to understand how the different part works and how to use them.
To build that project we will follow these steps
- create a GitLab server
- create a runner to run the pipeline
- create a basic Django app
- create a sonarqube server
- create a docker server to deploy our application
Gitlab
GitLab CI/CD is a tool built into GitLab for software development through the
following:
• Continuous Integration (CI)
• Continuous Delivery (CD)
• Continuous Deployment (CD)
GitLab CI/CD is configured by a file called .gitlab-ci.yml, placed at the repository’s
root. This file creates a pipeline, which runs for changes to the code in the repository.
Pipelines consist of one or more stages that run in a particular order and can each
contain one or more jobs that run in parallel. These jobs (or scripts) get executed by
the GitLab Runner agent.
You can use GitLab as a service by creating an account on the gitlab.com website or you can self-host a GitLab server on your own and manage everything yourself.
We are going to take the second path and install a GitLab server.
- Creating a GitLab server
We are installing GitLab on a ubuntu virtual machine
apt install curl -y
sudo apt-get update
sudo apt-get install -y curl openssh-server ca-certificates tzdata perl
apt update -y
gpg_key_url="https://packages.gitlab.com/gitlab/gitlab-ce/gpgkey"
curl -fsSL $gpg_key_url| sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/gitlab.gpg
sudo tee /etc/apt/sources.list.d/gitlab_gitlab-ce.list<<EOF
deb https://packages.gitlab.com/gitlab/gitlab-ce/ubuntu/ focal main
deb-src https://packages.gitlab.com/gitlab/gitlab-ce/ubuntu/ focal main
EOF
sudo apt update
sudo apt install gitlab-ce
You have to set-up an externat url for your gitlab server, if you are building the la on a virtual machine on your computer, you can just put the virtual machine ip address
sudo nano /etc/gitlab/gitlab.rb
sudo gitlab-ctl reconfigure
Get your root password : cat /etc/gitlab/initial_root_password
- Create the runner
- Install the official Gitlab repository
curl -L "https://packages.gitlab.com/install/official GitLab repository: repositories/runner/gitlab-runner/script.deb.sh" | sudo bash
2. Install the latest version of gitlab runner
sudo apt-get install gitlab-runner
3. To install a specific version of gitlab
apt-cache madison gitlab-runner
sudo apt-get install gitlab-runner=10.0.0
Getting the app
We are going to use a basic Django app for this demonstration. We will not have to create the app, you will just have to download it from the public GitHub repo :
This app is a tiny example of a store webpage, we include some tests for our methods. You can clone the repository on your machine and push it on your own repo. Run the command
git clone https://gitlab.com/emmanuelstevensc/django-project.git
It will clone the project on your computer. You need to have git installed before using this command.
when you get to the project root folder nad run the command :
python3 manage.py runserver
you should have the screens
you can get access to the application by going to the server address on port 8000
http://localhost:8000/montest
Running our first pipeline
Now that we have test the application, we can push it to our gitlab repository with the commands
git add .
git commit -m "our first commit"
git push -uf origin main
To register the runner paste this command in your terminal on the runner server
sudo gitlab-runner register -n \
--url https://YOUR_GITLAB_SERVER/ \
--registration-token REGISTRATION_TOKEN \
--executor shell \
--description "My Runner"
you can find the registration token on your project page on the GitLab server
after following these steps, you will have a functional GitLab running and a runner that allow you to run your pipeline
Now that we finish the set-up, you can go on CI/CD, click on pipeline and run the tour pipeline
If you click on passed you will see the logs of the jobs that you just run
Comments
Post a Comment