Skip to main content

Create pipeline

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


sudo gitlab-ctl start



Get your root password :  cat /etc/gitlab/initial_root_password

- Create the runner

  1. 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

Popular posts from this blog

Observability with grafana and prometheus (SSO configutation with active directory)

How to Set Up Grafana Single Sign-On (SSO) with Active Directory (AD) Grafana is a powerful tool for monitoring and visualizing data. Integrating it with Active Directory (AD) for Single Sign-On (SSO) can streamline access and enhance security. This tutorial will guide you through the process of configuring Grafana with AD for SSO. Prerequisites Active Directory Domain : Ensure you have an AD domain set up. Domain: bazboutey.local AD Server IP: 192.168.170.212 Users: grafana (for binding AD) user1 (to demonstrate SSO) we will end up with a pattern like this below Grafana Installed : Install Grafana on your server. Grafana Server IP: 192.168.179.185 Administrator Privileges : Access to modify AD settings and Grafana configurations. Step 1: Configure AD for LDAP Integration Create a Service Account in AD: Open Active Directory Users and Computers. Create a user (e.g., grafana ). Assign this user a strong password (e.g., Grafana 123$ ) and ensure it doesn’t expire. Gather Required AD D...

Deploying a Scalable Monitoring Stack Lab on AWS using Terraform and Ansible

Deploying a Scalable Monitoring Stack Lab on AWS using Terraform and Ansible Introduction Effective monitoring is a cornerstone of cloud infrastructure management, ensuring high availability and performance. This guide provides a professional walkthrough on deploying Prometheus , Grafana , and Node Exporter on AWS using Terraform for infrastructure provisioning and Ansible for configuration management. This lab will create a prometheus server and a grafana server, It will install node exporter on both server. You should be able to see the metrics in grafana, we already install a node exporter dashboard for the user. The diagram below will give you an idea of what the architecture will look like If you want to replicate this lab, you can find the complete code repository here: GitHub - MireCloud Terraform Infra .  Infrastructure Setup with Terraform 1. Creating a Dedicated VPC To ensure isolation, we define a VPC named Monitoring with a CIDR block of 10.0.0.0/16 . reso...

Building a Static Website on AWS with Terraform

The Journey to a Fully Automated Website Deployment A few weeks ago, I found myself needing to deploy a simple static website . Manually setting up an S3 bucket, configuring permissions, and linking it to a CloudFront distribution seemed like a tedious process. As someone who loves automation, I decided to leverage Terraform to simplify the entire process. Why Terraform? Infrastructure as Code (IaC) is a game-changer. With Terraform, I could:  Avoid manual setup errors  Easily reproduce and  Automate security best practices Instead of clicking through AWS settings, I wrote a few Terraform scripts and deployed everything in minutes. Let me walk you through how I did it!  Architecture Overview The architecture consists of three main components: User:  The end user accesses the website via a CloudFront URL.  CloudFront Distribution:  Acts as a content delivery network (CDN) to distribute content efficiently, reduce latency, and enhance security. It ...