version: "3"
services:
  postgres:
    image: postgres
    hostname: postgres
    restart: unless-stopped
    environment:
      POSTGRES_DB: gitlab
      POSTGRES_USER: gitlab
      # It's better to replace this password with something stronger
      POSTGRES_PASSWORD: gitlab
    volumes:
      - db_data:/var/lib/postgresql/data
      # This script will init the sonar database. Comment it if you don't want to use sonar
      # Edit the script to change sonar database password
      - ./postgres_init_sonar.sql:/docker-entrypoint-initdb.d/postgres_init_sonar.sql
    networks:
      - ci

  gitlab:
    image: gitlab/gitlab-ce
    hostname: gitlab
    restart: unless-stopped
    depends_on:
      - postgres
    environment:
      # Replace db_password with the password you set for the postgres database
      # Replace external_url with the url from which gitlab will be accessible
      # Replace gitlab_shell_ssh_port with the port that will be mapped to the container's port 22
      GITLAB_OMNIBUS_CONFIG: |
        postgresql['enable'] = false
        gitlab_rails['db_adapter'] = 'postgresql'
        gitlab_rails['db_encoding'] = 'utf8'
        gitlab_rails['db_host'] = 'postgres'
        gitlab_rails['db_port'] = '5432'
        gitlab_rails['db_database'] = 'gitlab'
        gitlab_rails['db_username'] = 'gitlab'
        gitlab_rails['db_password'] = 'gitlab'
        external_url 'http://gitlab'
        gitlab_rails['gitlab_shell_ssh_port'] = 2222
    ports:
      # We expose SSH port for allowing ssh git management
      - "2222:22"
    volumes:
      - gitlab_config:/etc/gitlab
      - gitlab_data:/var/opt/gitlab
      - gitlab_logs:/var/log/gitlab
    networks:
      - ci
      - reverse_proxy
    labels:
      - "traefik.backend=gitlab"
      - "traefik.frontend.rule=Host:subdomain.domain_in_toml.org"
      - "traefik.docker.network=reverse_proxy"
      - "traefik.enable=true"
      - "traefik.port=80"

  jenkins:
    # Comment the following line if you want to use docker in your jenkins
    image: jenkins/jenkins:lts
    # Uncomment the following section if you want to use docker in your jenkins
    #image: jenkins_with_docker
    #build:
    # context: ./
    # args:
    #   docker_gid: #HERE put the docker group gid on the host (in quotes, e.g. "1234")
    #   docker_deb_url: #HERE put the address of the docker deb package
    hostname: jenkins
    restart: unless-stopped
    volumes:
      - jenkins_home:/var/jenkins_home
      # Uncomment the following lines if you want to use docker in your jenkins
      #- /var/run/docker.sock:/var/run/docker.sock:ro
    networks:
      - ci
      - reverse_proxy
    labels:
      - "traefik.backend=jenkins"
      - "traefik.frontend.rule=Host:subdomain.domain_in_toml.org"
      - "traefik.docker.network=reverse_proxy"
      - "traefik.enable=true"
      - "traefik.port=8080"

  sonar:
    image: sonarqube:lts
    hostname: sonar
    depends_on:
      - postgres
    restart: unless-stopped
    environment:
      # Username, password and database name are set in postgres_init_sonar.sql
      # It is better to use a non-trivial password
      SONARQUBE_JDBC_URL: jdbc:postgresql://postgres/sonar
      SONARQUBE_JDBC_USERNAME: sonar
      SONARQUBE_JDBC_PASSWORD: sonar
    volumes:
      - sonar_data:/opt/sonarqube/data
      - sonar_extensions:/opt/sonarqube/extensions
    networks:
      - ci
      - reverse_proxy
    labels:
      - "traefik.backend=sonar"
      - "traefik.frontend.rule=Host:subdomain.domain_in_toml.org"
      - "traefik.docker.network=reverse_proxy"
      - "traefik.enable=true"
      - "traefik.port=9000"

networks:
  ci:
  reverse_proxy:
    external: true
volumes:
  db_data:
  gitlab_config:
  gitlab_data:
  gitlab_logs:
  jenkins_home:
  sonar_data:
  sonar_extensions:
