# ---------------------------------------------------------------------------
# docker-compose for local E2E test development.
#
# Usage:
#   docker compose -f e2e/docker-compose.yml up -d gitlab
#   # Wait ~3 min for GitLab to boot
#   cd e2e && npm run provision && npm test
# ---------------------------------------------------------------------------
services:
  gitlab:
    image: gitlab/gitlab-ce:18.11.3-ce.0
    ports:
      - "${GITLAB_HOST_PORT:-8080}:80"
    environment:
      # external_url uses a nominal hostname (NOT host:port) so nginx
      # listens on container's port 80 — that's what the port mapping
      # and healthcheck below expect. Setting external_url to
      # http://localhost:<port> would force nginx onto that port instead
      # and break both the mapping and the healthcheck.
      # The hostname 'gitlab.local' is also what warm-gitlab.yml uses
      # in CI, keeping local-dev and CI configs aligned.
      GITLAB_OMNIBUS_CONFIG: |
        external_url 'http://gitlab.local'
        gitlab_rails['initial_root_password'] = 'E2eTestPassword1!'
        # Allow /-/readiness and /-/health endpoints from any source so the
        # host-side wait-for-gitlab.sh script can poll readiness through
        # the docker port forward (which presents as the docker bridge IP,
        # not localhost). Default whitelist is loopback-only and produces
        # silent 404s for external probes.
        gitlab_rails['monitoring_whitelist'] = ['0.0.0.0/0', '::/0']
        prometheus_monitoring['enable'] = false
        registry['enable'] = false
        sidekiq['concurrency'] = 2
        puma['worker_processes'] = 1
        gitlab_rails['gitlab_shell_ssh_port'] = 2222
    shm_size: 512m
    healthcheck:
      test: ["CMD", "curl", "-sf", "http://localhost:80/-/readiness"]
      interval: 30s
      timeout: 10s
      retries: 20
      start_period: 180s

  mcp-server:
    build:
      context: ..
      dockerfile: Dockerfile
    ports:
      - "3000:3000"
    environment:
      GITLAB_URL: http://gitlab:80
      GITLAB_PERSONAL_ACCESS_TOKEN: ${GITLAB_TOKEN:-}
      PORT: "3000"
      USE_STREAMABLE_HTTP: "true"
    depends_on:
      gitlab:
        condition: service_healthy

  e2e-runner:
    build:
      context: .
      dockerfile: Dockerfile
    environment:
      GITLAB_URL: http://gitlab:80
      GITLAB_ROOT_PASSWORD: "E2eTestPassword1!"
      MCP_SERVER_URL: http://mcp-server:3000
    depends_on:
      mcp-server:
        condition: service_started
      gitlab:
        condition: service_healthy
