Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Deploying GitLab on CentOS 7 and Implementing Branch Protection

Tech May 16 1

System Preparation and Installation

Begin by disabling the firewall and SELinux to prevent initial connectivity issues. Install the necessary dependencies for the SSH server and script utilities.

sudo systemctl stop firewalld
sudo setenforce 0
sudo yum install -y curl policycoreutils-python openssh-server

Add the GitLab repository and install the Enterprise Edition package.

curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.rpm.sh | sudo bash
sudo yum install -y gitlab-ee

Configure the external URL in the main configuration file. Replace the IP address with your server's FQDN or IP.

sudo vim /etc/gitlab/gitlab.rb
# Update the following line:
external_url 'http://192.168.1.100'
sudo gitlab-ctl reconfigure

Verify that all services are running correctly.

sudo gitlab-ctl status

Initial Configuration and Project Setup

Navigate to the configured URL in a browser to set the root password. Once logged in, create a new Group (e.g., backend-team) and a Project within that group.

To interact with the repository, generate an SSH key pair on your local machine and add the public key to your GitLab user profile.

cat ~/.ssh/id_rsa.pub

Initialize a local repository and link it to the remote GitLab project.

mkdir project-demo && cd project-demo
git init
git remote add origin git@192.168.1.100:backend-team/project-demo.git

Initial Commit and Master Branch

Create a file, stage it, and commit the changes to the local repository. Push the content to the remote master branch.

echo "System setup" > config.yaml
git add .
git commit -m "Initialize repository structure"
git push -u origin master

User Management and Branch Protection

Create a new user account for a developer and add them to the project group with 'Developer' permissions. The developer must also configure their SSH keys in their profile settings.

On the development machine, clone the repository.

git clone git@192.168.1.100:backend-team/project-demo.git
cd project-demo

Attempt to push directly to the master branch. By default, GitLab protects the master branch, preventing direct pushes from developers.

echo "Feature logic" > feature.py
git add .
git commit -m "Add new feature logic"
git push -u origin master

The output will indicate a permission error. Developers must work on separate branches.

Feature Branch Workflow

Create a new branch, commit changes, and push this branch to the remote server.

git checkout -b feature/new-logic
git branch
git push -u origin feature/new-logic

GitLab will provide a URL to create a Merge Request, allowing code review before merging into the master branch.

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.