# =============================================================================
# WOOO TECH - DevOps Services (GitLab + Runner)
# =============================================================================
# 部署位置: UAT Server (192.168.0.110)
# 用途: 自建 Git 伺服器 + CI/CD 平台
# =============================================================================

version: '3.8'

services:
  # ---------------------------------------------------------------------------
  # GitLab CE - Git 伺服器 + CI/CD
  # ---------------------------------------------------------------------------
  gitlab:
    image: gitlab/gitlab-ce:16.8.1-ce.0
    container_name: wooo-gitlab
    hostname: gitlab.wooo.local
    restart: unless-stopped
    environment:
      GITLAB_OMNIBUS_CONFIG: |
        # 外部 URL
        external_url 'http://192.168.0.110:8929'
        gitlab_rails['gitlab_shell_ssh_port'] = 2224

        # 降低資源使用
        puma['workers'] = 2
        puma['min_threads'] = 1
        puma['max_threads'] = 4

        sidekiq['max_concurrency'] = 10
        sidekiq['min_concurrency'] = 1

        postgresql['shared_buffers'] = "256MB"
        postgresql['max_worker_processes'] = 4

        prometheus_monitoring['enable'] = false
        grafana['enable'] = false

        # 停用不需要的服務
        gitlab_kas['enable'] = false
        sentinel['enable'] = false

        # 容器 Registry (使用外部 Harbor)
        registry['enable'] = false
    ports:
      - "8929:8929"    # HTTP
      - "2224:22"      # SSH
    volumes:
      - gitlab-config:/etc/gitlab
      - gitlab-logs:/var/log/gitlab
      - gitlab-data:/var/opt/gitlab
    shm_size: '256m'
    networks:
      - devops

  # ---------------------------------------------------------------------------
  # GitLab Runner - CI/CD 執行器
  # ---------------------------------------------------------------------------
  gitlab-runner:
    image: gitlab/gitlab-runner:v16.8.0
    container_name: wooo-gitlab-runner
    restart: unless-stopped
    volumes:
      - gitlab-runner-config:/etc/gitlab-runner
      - /var/run/docker.sock:/var/run/docker.sock
    networks:
      - devops
    depends_on:
      - gitlab

networks:
  devops:
    name: wooo-devops
    driver: bridge

volumes:
  gitlab-config:
    name: wooo-gitlab-config
  gitlab-logs:
    name: wooo-gitlab-logs
  gitlab-data:
    name: wooo-gitlab-data
  gitlab-runner-config:
    name: wooo-gitlab-runner-config
