Skip to content
sentisso edited this page Sep 27, 2023 · 13 revisions

Pre-notes

  1. There's going to be a few individual docker-compose-__.yml file examples. So you can either continuously merge them into one final docker-compose.yml file or keep them separated. Which ever suits you.
  2. used constants:
    • /opt/gitlab/ - I'll assume that all the configuration files and/or installed stuff will be at the "root" folder /opt/gitlab/, because it seems like the right place to put all the configuration at. So you can either choose your own "root" folder or just accept this one.
    • mydomain.com - this domain name will be used as an example. You need to replace it everywhere with your own, already existing, domain name. The steps that include mydomain.com will be marked with "(👷 contains mydomain.com)".
  3. Lines with the ➡️ emoji are the actual steps to take, everything else are just useful notes.

1. Install Docker (with compose)

1. Install Docker engine
➡️ https://docs.docker.com/engine/install/

2. Install Docker compose
➡️ https://docs.docker.com/compose/install/

3. Create a common Docker network gitlab
➡️ $ docker network create -d bridge gitlab

2. Setup nginx-proxy and SSL

This will allow you to easily expose the container services under different (sub)domain names on the same server (all under SSL thanks to Let's encrypt).

Take note of the vhost volume at the bottom of the compose file. This configuration syncs the local folder /opt/gitlab/nginx/vhost.d/ with the nginx containers. This allows for easy use of custom nginx configuration per-VIRTUAL_HOST if needed.

➡️ docker-compose-nginx-proxy.yml

Sources:

3. Install GitLab using Docker compose

1. Set up the volumes location
➡️ https://docs.gitlab.com/ee/install/docker.html#set-up-the-volumes-location

2. Install GitLab using Docker Compose
➡️ docker-compose-gitlab.yml (👷 contains mydomain.com)

3. Check the public accessibility of the GitLab server

4. Get the root password
➡️ In the file initial_root_password (accessible via sudo cat /srv/gitlab/config/initial_root_password) should be the root password that you can use for logging in to the "root" account.

5. Configure sign-up restrictions
➡️ At /admin/application_settings/general#js-signup-settings you should disable new, unapproved sign-ups for your GitLab server.

6. Add SSH keys
➡️ At /-/profile/keys add an SSH key that will allow you to actually push code to your GitLab server. See https://docs.gitlab.com/16.4/ee/user/ssh.html. ➡️ Add SSH config: (👷 contains mydomain.com)

Host gitlab.mydomain.com
    HostName <your_server_IP>
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/gitlab_iusethisfortesting_sentisso

HostName can be left out if your DNS servers support the SSH protocol (for example Proxied Cloudflare does not).

7. Disable Auto DevOps
➡️ At /admin/application_settings/ci_cd#js-ci-cd-settings uncheck the "Default to Auto DevOps pipeline for all projects" option to disable Auto DevOps at the instance level.

8. Enable large body uploads
This is especially useful when you want to import projects from other sources.

➡️ Create file /opt/gitlab/nginx/vhost.d/gitlab.mydomain.com with the following contents: (👷 contains mydomain.com)

client_max_body_size 64m;

Sources:

4. Install and register GitLab runners

GitLab runners can be installed and ran on any server! Not just the root one, which hosts the GitLab server.

1. Install a new Docker GitLab runner
➡️ docker-compose-gitlab-runner.yml

2. Register the GitLab runner
➡️ In the admin settings at /admin/runners/new "create" a new GitLab runner.
➡️ After submitting the form, remember/copy the runner token glrt-***, which is shown on the confirmation page.
➡️ On the server where you created the Docker GitLab runner, run docker compose exec gitlab-runner gitlab-runner register (where the first gitlab-runner is the container name of the runner). It will ask you for:

  1. the public URL of your GitLab server: https://gitlab.mydomain.com/ (👷 contains mydomain.com),
  2. runner authentication token: that's the glrt-*** token from earlier,
  3. runner executor: use docker
  4. default image: use alpine:latest

➡️ Edit the runner's configuration at /srv/gitlab-runner/config/config.toml:

  1. Add "/var/run/docker.sock:/var/run/docker.sock:ro" to volumes in the [runners.docker] section,
  2. Add network_mode = "host" in the [runners.docker] section

➡️ Restart the GitLab runner by running docker compose exec gitlab-runner gitlab-runner restart

4. Check the availability of the runner
➡️ At /admin/runners it should have a status of "Online", including some information about the server where you deployed the runner at.

Sources:

Recommended next steps

If you've completed the previous steps, you can start developing and deploying new applications on your self-hosted GitLab server. The following sections are therefore optional, but are recommended and could be pretty useful.

Sources:

5. Configure SMTP

Configure SMTP for proper email notifications support.
The gitlab.rb file, that you should edit, is located at /srv/gitlab/config/gitlab.rb.

➡️ Follow the instructions for your email solution at https://docs.gitlab.com/omnibus/settings/smtp.html
➡️ Reconfigure the server by running docker compose exec gitlab gitlab-ctl reconfigure

Clone this wiki locally