0

Gitlab Docker Service

In this article, I will explain how to create and deploy GitLab docker service in your swarm cluster.

In my current organization, we are in the process of migrating all application to containers. we are using mainly GitLab as SCM and is running on a ubuntu server. Also haven’t updated for a long.

Below is the Docker service file. I hope you already have one swarm cluster up and running. You can check out this article docker swarm using ansible

version: "3.6"

services:
  gitlab:
    image: gitlab/gitlab-ce:latest
    ports:
      - "2222:22"
    volumes:
      - /var/storage/gitlab/data:/var/opt/gitlab
      - /var/storage/gitlab/logs:/var/log/gitlab
      - /var/storage/gitlab/config:/etc/gitlab
    hostname: gitlab
    environment:
      GITLAB_OMNIBUS_CONFIG: |
        external_url 'https://gitlab.devopsbyte.com'
        gitlab_rails['smtp_enable'] = true
        gitlab_rails['smtp_address'] = "192.168.101.10"
        gitlab_rails['smtp_openssl_verify_mode'] = 'none'
        gitlab_rails['smtp_port'] = 25
        nginx['listen_port'] = 80
        nginx['listen_https'] = false
        nginx['redirect_http_to_https'] = false
        gitlab_rails['time_zone'] = UTC
        gitlab_rails['gitlab_default_can_create_group'] = {{ gitlab_default_can_create_group | lower }}
        gitlab_rails['webhook_timeout'] = 30
        gitlab_rails['gitlab_shell_ssh_port'] = 2222
        gitlab_rails['ldap_enabled'] = true
        gitlab_rails['ldap_servers'] = {
        'main' => {
          'label' => 'LDAP',
          'host' =>  'ldap server IP/NAME',
          'port' => 'ldap port,
          'uid' => 'sAMAccountName',
          'encryption' => 'plain',
          'verify_certificates' => false,
          'bind_dn' => 'dap_bind_dn',
          'password' => 'ldap_bind_password',
          'active_directory' => true,
          'base' => 'DC=devopsbyte,DC=local',
          'group_base' => '',
          'admin_group' => ''
          }
        }
    networks:
      - gitlab
    deploy:
      replicas: 1
      resources:
          limits:
            cpus: '0.6'
            memory: 6G
          reservations:
            cpus: '0.3'
            memory: 4G
      restart_policy:
        condition: on-failure
        delay: 20s
        max_attempts: 3
        window: 60s
networks:
  net:
   external:
    name: gitlab_net
  • Update the omnibus configuration as you required. I have added SMTP because the default GitLab image doesn’t ship with Sendmail. If you don’t have an SMTP server, you can build your own GitLab docker image with Sendmail.
  • LDAP configuration can be updated as per your LDAP config. if you are planning to use an internal user database, remove the LDAP section

Deploy the service.

ssh to swarm manager and Deploy the service to swarm cluster using

$ docker stack deploy --compose file gitlab.devopsbyte.yml gitlab

Else, if you have an automated deployment using Jenkins or any other tool, you can use that too

Leave a Reply

Your email address will not be published. Required fields are marked *