GitLab Installation Method Guide on FreeBSD Systems

Gitlab is a service that provides remote access to Git repositories. In addition to hosting your code, these services provide additional features designed to help manage the software development cycle. Git is a tool that functions to make things easier for developers. This tool is useful as a Version Control System (VCS) whose job is to track changes to code files. For developers, the existence of Git makes it very easy for them to collaborate to complete projects with other developers or on their own projects.

Tools like Git allow developers to make changes to certain source code. They don't need to worry about there being conflicts in combining these codes. Because by using Git all changes to the source code can be tracked.

In order to use Git, currently there are various services available to store and share the code. For example, GitLab, GitHub, Bitbucket, and Gitorous. Among these choices, GitLab is one of the Git storage services that is gaining popularity and has many users.

Git is a source code versioning system that lets you track changes locally and push or pull changes from remote resources.

GitLab is a github-like service that organizations can use to provide internal management of git repositories. It is a self-hosted Git-repository management system that keeps user code private and can easily deploy code changes.

The following are some of the advantages of using Gitlab:
  1. There is open-source Gitlab CE.
  2. Realtime Logging.
  3. Supports Parallel Builds.
  4. Facilitates collaboration between developers


1. Install PostgreSQL database

All Gitlab features will run well if you use a PostgreSQL database. So we recommend using a PostgreSQL database that will connect with Gitlab. You can use the MySQL Database, but some Gitlab features will not work well.

On FreeBSD the PostgreSQL repository is available, you can install PostgreSQL with PKG or ports. But it's best to install PostgreSQL with system ports. There are two PostgreSQL that you must install, namely the PostgreSQL client and PostgreSQL server. Here's how to install PostgreSQL on FreeBSD.

Install PostgreSQL client and server
root@ns3:~ # cd /usr/ports/databases/postgresql15-client
root@ns3:/usr/ports/databases/postgresql15-client # make install clean
root@ns3:/usr/ports/databases/postgresql15-client # cd /usr/ports/databases/postgresql15-server
root@ns3:/usr/ports/databases/postgresql15-server # make install clean
In this article, we do not fully explain how to install and use PostgreSQL, you can read the previous article.



2. Create User PostgreSQL database

In this section we will create a database that will be used by Gitlab to communicate with PostgreSQL. Below is the database that we will create with PostgreSQL.

user: usergitlab
database: gitlab
host: localhost
password: router123

Run the command below to create a PostgreSQL database.

Connect to PostgreSQL
root@ns3:~ # su - postgres
$ createuser usergitlab
$ createdb gitlab -O usergitlab encoding='UTF8'
$ psql gitlab
psql (15.5)
Type "help" for help.

gitlab=# alter user usergitlab with password 'router123';
ALTER ROLE
gitlab=#
The above command is used to connect to a PostgreSQL database, and create a database, user and password.


3. Install Redis

Gitlab uses Redis to store all its cache. The goal is to speed up Gitlab performance. Run the following command to install Redis.

/usr/ports/databases/redis
root@ns3:~ # cd /usr/ports/databases/redis
root@ns3:/usr/ports/databases/redis # make install clean
After that, configure Redis, open the redis.conf file and activate it by removing the "#" sign at the beginning of the script. Below is the script that you must activate.

/usr/local/etc/redis.conf
root@ns3:~ # cd /usr/local/etc
root@ns3:/usr/local/etc # ee redis.conf
unixsocket /var/run/redis/redis.sock
unixsocketperm 770
requirepass foobared
#bind 127.0.0.1 -::1
Allow Redis to start by adding the script below to the rc.conf file.

/etc/rc.conf
root@ns3:~ # ee /etc/rc.conf
redis_enable="YES"
Run Redis with the service command.

Run Redis
root@ns3:~ # service redis restart


4. Install gitlab-ce

Before you install gitlab-ce, first install the dependencies required by gitlab-ce. Here is how to install gitlab-ce dependencies.

Install dependencies
root@ns3:~ # pkg install re2 html2text rubygem-re2 rubygem-gitlab-glfm-markdown rubygem-prometheus-client-mmap gpgme rubygem-rugged rubygem-charlock_holmes rubygem-plist rubygem-nkf rubygem-rouge rubygem-wmi-lite rubygem-net-ssh rubygem-lockbox rubygem-unf_ext
After that, you can run the gitlab-ce install command.

Install gitlab-ce with ports
root@ns3:~ # cd /usr/ports/www/gitlab-ce
root@ns3:/usr/ports/www/gitlab-ce # make install clean
Or, if you want to use the PKG package, run the command below.

Install gitlab-ce with PKG
root@ns3:~ # pkg install gitlab-ce


5. Gitlab Configuration

In this section, we will explain how to configure Gitlab on FreeBSD. Because you have to do a lot of configuration, we recommend following every step we explain so you don't miss any scripts.

a. Create connections

After the gitlab-ce installation process is complete, open the gitlab installation directory and edit the configuration file, you follow the instructions at the top of the file. In the gitlab.yml file, activate the script below.

/usr/local/www/gitlab-ce/config/gitlab.yml
root@ns3:~ # cd /usr/local/www/gitlab-ce/config
root@ns3:/usr/local/www/gitlab-ce/config # ee gitlab.yml
connect_src: "'self' http://192.168.5.2:* ws://192.168.5.2:* wss://192.168.5.2:*"
allowed_hosts: [192.168.5.2]
gitlab:
    host: 192.168.5.2
    port: 8080
email_from: datainchi@gmail.com
email_reply_to: datainchi@gmail.com
user: git
time_zone: 'UTC'

b. Create database connections

In the database.yml file, change the database script according to the PostgreSQL database you created above.

/usr/local/www/gitlab-ce/config/database.yml
root@ns3:~ # cd /usr/local/www/gitlab-ce/config
root@ns3:/usr/local/www/gitlab-ce/config # ee database.yml
production:
  main:
    adapter: postgresql
    encoding: unicode
    database: gitlab
    username: usergitlab
    password: "router123"
    host: localhost

c. Create global git settings

We will use the git user to initialize Gitlab, run the following command to switch to the git user and update some of its global git settings.

Create directory
root@ns3:~ # mkdir -p /usr/local/git/repositories
root@ns3:~ # mkdir -p /usr/home/git && mkdir -p /usr/home/git/gitlab
root@ns3:~ # chown -R git:git /usr/local/git/repositories
root@ns3:~ # chown -R git:git /usr/home/git/
Global git settings
root@ns3:~ # su - git
$ git config --global core.autocrlf input
$ git config --global gc.auto 0
$ git config --global repack.writeBitmaps true
$ git config --global receive.advertisePushOptions true
$ git config --global core.fsync objects,derived-metadata,reference
$ exit
root@ns3:~ #

d. Change ownership and permissions

On some Gitlab directories and files, you must change file ownership rights and file permissions.

Ownership
root@ns3:~ # chown -R git:git /usr/local/www/gitlab-ce/log
root@ns3:~ # chown -R git:git /usr/local/www/gitlab-ce/tmp
root@ns3:~ # chown -R git:git /usr/local/www/gitlab-ce/public
root@ns3:~ # chown -R git:git /usr/local/www/gitlab-ce/builds
root@ns3:~ # chown -R git:git /usr/local/www/gitlab-ce/shared
Permissions
root@ns3:~ # chmod -R 770 /usr/local/www/gitlab-ce/log
root@ns3:~ # chmod -R 770 /usr/local/www/gitlab-ce/tmp
root@ns3:~ # chmod -R 770 /usr/local/www/gitlab-ce/public
root@ns3:~ # chmod -R 770 /usr/local/www/gitlab-ce/builds
root@ns3:~ # chmod -R 770 /usr/local/www/gitlab-ce/shared
root@ns3:~ # chmod -R 770 /usr/local/www/gitlab-ce/config

e. Installed rubygem libraries

To prevent hangs during Gitlab installation, configure rubygem to use the installed libraries.

Rubygem libraries
root@ns3:~ # cd /usr/local/www/gitlab-ce
root@ns3:/usr/local/www/gitlab-ce # bundle config build.gpgme "--use-system-libraries"
root@ns3:/usr/local/www/gitlab-ce # bundle config build.rugged "--use-system-libraries"
root@ns3:/usr/local/www/gitlab-ce # bundle config build.re2 "--use-system-libraries"
root@ns3:/usr/local/www/gitlab-ce # bundle config build.charlock_holmes "--use-system-libraries"
root@ns3:/usr/local/www/gitlab-ce # bundle config build.gitlab-glfm-markdown "--use-system-libraries"
root@ns3:/usr/local/www/gitlab-ce # bundle config build.nkf "--use-system-libraries"
root@ns3:/usr/local/www/gitlab-ce # bundle config build.rouge "--use-system-libraries"
root@ns3:/usr/local/www/gitlab-ce # bundle config build.wmi-lite "--use-system-libraries"
root@ns3:/usr/local/www/gitlab-ce # bundle config build.plist "--use-system-libraries"
root@ns3:/usr/local/www/gitlab-ce # bundle config build.net-ssh "--use-system-libraries"
root@ns3:/usr/local/www/gitlab-ce # bundle config build.lockbox "--use-system-libraries"
root@ns3:/usr/local/www/gitlab-ce # bundle config build.unf_ext "--use-system-libraries"
root@ns3:/usr/local/www/gitlab-ce # bundle config build.prometheus-client-mmap "--use-system-libraries"
If there is still an "error", you can try the command below.

Rubygem libraries
root@ns3:/usr/local/www/gitlab-ce # bundle config build.prometheus-client-mmap "--platform ruby"
root@ns3:/usr/local/www/gitlab-ce # bundle config build.gitlab-glfm-markdown "--platform ruby"
root@ns3:/usr/local/www/gitlab-ce # gem install prometheus-client-mmap --platform ruby
root@ns3:/usr/local/www/gitlab-ce # gem install gitlab-glfm-markdown --platform ruby

f. Install the gems for PostgreSQL

GitLab Shell is an SSH access and repository management software developed specially for GitLab. First of all we have to install Ruby Gems.

/usr/local/www/gitlab-ce
root@ns3:/usr/local/www/gitlab-ce # bundle install --without development test
Run the installation task for gitlab-shell.

/usr/local/www/gitlab-ce
root@ns3:/usr/local/www/gitlab-ce # bundle exec rake gitlab:shell:install REDIS_URL=unix:/var/run/redis/redis.sock RAILS_ENV=production SKIP_STORAGE_VALIDATION=true
g. Create srip rc.d

In order for Gitlab to run automatically on a FreeBSD server, you must create the rc.d script. Follow the commands below.

Enable gitlab to run automatically on FreeBSD. In the rc.conf file type the script below.

/etc/rc.conf
root@ns3:~ # ee /etc/rc.conf
gitlab_enable="YES"
gitlab_authBackend="http://192.168.5.2:8080"
gitlab_workhorse_tcp="NO"
gitlab_workhorse_addr="192.168.5.2:8181"
gitlab_mail_room_enable="NO"
gitlab_allow_conflicts="NO"
gitlab_wait="120"

gitlab_pages_enable="YES"
gitlab_pages_dir="/var/tmp/gitlab_pages"
gitlab_pages_user="gitlab-pages"
gitlab_pages_group="gitlab-pages"
gitlab_pages_logfile="/var/log/gitlab_pages.log"
gitlab_pages_args="-config=/usr/local/share/gitlab-pages/gitlab-pages.conf"

h. Run Gitlab

The next step is for us to set Redmine to connect to Ruby.

/usr/local/www/gitlab-ce
root@ns3:/usr/local/www/gitlab-ce # bundle exec rake generate_secret_token
root@ns3:/usr/local/www/gitlab-ce # bundle exec rake db:migrate RAILS_ENV="production"
The final step is to run gitlab-ce.

/usr/local/www/gitlab-ce
root@ns3:/usr/local/www/gitlab-ce # service gitlab restart
root@ns3:/usr/local/www/gitlab-ce # ruby bin/rails server -e production
Once you have finished this article, your server now has a fully functional GitLab hosted on your own server. You can start importing or creating a new project and share access to it with your team members. Gitlab will regularly add new features and update the platform, therefore, it doesn't hurt to visit the GitLab platform page frequently to check the project home page for the latest information on important fixes or notices.
Iwan Setiawan

I Like Adventure: Mahameru Mount, Rinjani Mount I Like Writer FreeBSD

Post a Comment

Previous Post Next Post