Skip to content

Gitlab

Setting Up GitLab on Docker Compose

GitLab is a web-based DevOps lifecycle tool that provides a Git repository manager with built-in features for software development and collaboration. GitLab integrates various aspects of the DevOps Lifecycle, including project planning, source code management, continous integration / continous deployment (CI/CD), monitoring and security. Below are some of the key features and aspects of GitLab:

  • Git Repository Management - GitLab allows users to host Git respositories, enabling version control, code review and collaboration.
  • CI / CD Pipeline - GitLab offers robust CI/CD capabilities, allowing teams to automate the build, test, and deployment processes. This helps in maintaining code quality and speeding up the release cycle.
  • Project Management - GitLab includes features for issue tracking, project planning, task management, supporting agile methodologies such as Scrum and Kanban.
  • Code Review and Collaboration - It provides tools for code review, such as merge requests, inline commenting, and code discussions, fostering better collaboration amoung team members.
  • Security and Compliance - GitLab includes security features like static application security testing (SAST), dynamic application security testing (DAST), container scanning, and dependency scanning. These tools help in identifying vulernerabilities early in the development process.
  • Monitioring and Analytics - GitLab offers monitoring tools and performance metrics, allowing teams to track the health and performance of any applications and infrastructure.
  • Integration and Extensibility - GitLab can integrate with various third-party tools and services, enhancing its capabilities and fitting into existing workflows.
  • Self-Hosted and SaaS Options - GitLab can be self-hosted on-premises or used as a service via GitLab.com, providing flexibility based on organisational needs.
  • Open Source and Enterprise Editions - GitLab is available in an open-source edition with a core set of features, and in serveral paid editions (such as GitLab Starter, Premium, and Ultimate) that offer additional enterprise-grade features and support.

*GitLab’s comprehensive toolset aims to streamline the software development lifecycle, improve collaboration, and ensure the delivery of high-quality software.

Why Choose GitLab

GitLab is open-source software, which allows GitLab to be hosted on any hardware. This provides full control over the repositories, enhancing security and customisation options.

Docker Compose Example

---
networks:
frontend:
external: true
backend:
external: true
services:
GitLab:
image: zengxs/GitLab:16.10.1-ce-arm64
#image: GitLab/GitLab-ce:17.1.2-ce.0 # Does Not Work due to CPU Architecture
container_name: GitLab
restart: always
hostname: 'GitLab.<domain>'
environment:
GitLab_OMNIBUS_CONFIG: |
# Add any other GitLab.rb configuration here, each on its own line
external_url 'https://GitLab.<domain>:8929';
GitLab_rails['initial_root_password'] = '<password>'
nginx['listen_port'] = 8929
nginx['listen_https'] = false
nginx['http2_enabled'] = false
nginx['proxy_set_headers'] = {
"Host" => "$$http_host",
"X-Real-IP" => "$$remote_addr",
"X-Forwarded-For" => "$$proxy_add_x_forwarded_for",
"X-Forwarded-Proto" => "https",
"X-Forwarded-Ssl" => "on"
}
GitLab_rails['GitLab_shell_ssh_port'] = 2233;
registry_external_url 'https://registry.GitLab.example.com'
registry_nginx['listen_port'] = 5100
registry_nginx['listen_https'] = false
registry_nginx['proxy_set_headers'] = {
"Host" => "$$http_host",
"X-Real-IP" => "$$remote_addr",
"X-Forwarded-For" => "$$proxy_add_x_forwarded_for",
"X-Forwarded-Proto" => "https",
"X-Forwarded-Ssl" => "on"
}
pages_external_url 'https://pages.GitLab.example.com'
pages_nginx['listen_port'] = 5200
pages_nginx['listen_https'] = false
pages_nginx['proxy_set_headers'] = {
"Host" => "$$http_host",
"X-Real-IP" => "$$remote_addr",
"X-Forwarded-For" => "$$proxy_add_x_forwarded_for",
"X-Forwarded-Proto" => "https",
"X-Forwarded-Ssl" => "on"
}
GitLab_pages['inplace_chroot'] = true
GitLab_pages['external_http'] = ['GitLab:5201']
shm_size: '256m'
# secrets:
#- GitLab_root_password
ports:
- '8929:80' # http port for GitLab itself
- '8443:443' # https
- '2233:22' # ssh port
volumes:
- '$GitLab_HOME/config:/etc/GitLab'
- '$GitLab_HOME/logs:/var/log/GitLab'
- '$GitLab_HOME/data:/var/opt/GitLab'
shm_size: '256m'
labels:
- traefik.enable=true
- traefik.http.routers.GitLab.rule=Host(`GitLab.<domain>`)
- traefik.http.routers.GitLab.entrypoints=https
- traefik.http.routers.GitLab.tls=true
- traefik.http.routers.GitLab.tls.certresolver=myresolver
- traefik.http.routers.GitLab.service=GitLab
- traefik.http.services.GitLab.loadbalancer.server.scheme=http
- traefik.http.services.GitLab.loadBalancer.server.port=8929
- traefik.tcp.services.GitLab-ssh.loadbalancer.server.port=22
- "--certificatesresolvers.myresolver.acme.dnschallenge=true"
- "--certificatesresolvers.myresolver.acme.dnschallenge.provider=cloudflare"
- "traefik.registry.frontend.rule=Host:registry.GitLab.example.com"
- "traefik.registry.port=5100"
- "traefik.pages.frontend.rule=Host:pages.GitLab.example.com,username.pages.GitLab.example.com"
- traefik.pages.port=5201
# GitLab-runner:
# image: GitLab/GitLab-runner:alpine
# restart: always
# volumes:
# # Mount Docker socket for dind
# - /var/run/docker.sock:/var/run/docker.sock
# # We need to slightly modify the runner config, so mount it here and just create an empty file for the beginning
# # Make sure that the permissions are correct so that the container can write to it
# - ./runner.toml:/etc/GitLab-runner/config.toml
networks:
- backend
- frontend
#secrets:
# GitLab_root_password:
# file: ./root_password.txt

Start GitLab

Start GitLab by running the following command within the folder / location where the docker compose file for GitLab has been stored.

docker compose up -d

Key Components of Docker Compose Configuration Explained

  • Image - Specifies the GitLab server image and tag
  • Ports - Exposes GitLab on specified ports relating to the configuration above.
  • Volumes - For configuration, logs and application data
  • Environment - Various GitLab specific configuration options passed in as environment variables instead of using files within the GitLab configuration.
  • Labels - Used by Traefik to provide external access to the service, once the service all its dependancies have been started are "healthy" and Accessible, Public Service Name and what provider to use to check and obtain for an SSL Certificate