---
# Docker Compose for test infrastructure (Redis + SSH test server)
# Used by make test-e2e to provide consistent test environment

services:
  redis:
    image: redis:7-alpine
    ports:
      - "6379:6379"
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 1s
      timeout: 3s
      retries: 10
      start_period: 2s

  ssh-test-server:
    image: linuxserver/openssh-server:latest
    ports:
      - "2222:2222"
    environment:
      - PUID=1000
      - PGID=1000
      - TZ=Etc/UTC
      - USER_NAME=testuser
      - USER_PASSWORD=testpass
      - SUDO_ACCESS=true
      - PASSWORD_ACCESS=true
    volumes:
      - ssh-config:/config
    healthcheck:
      test: ["CMD-SHELL", "nc -z localhost 2222 || exit 1"]
      interval: 2s
      timeout: 3s
      retries: 15
      start_period: 5s

  # Debug profile: API server for logs/debug e2e tests
  api-server:
    image: golang:1.25-bookworm
    profiles: ["debug"]
    working_dir: /app
    command: >
      sh -c "
        go build -o api-server ./cmd/api-server/main.go &&
        ./api-server --config /app/configs/api/dev.yaml
      "
    ports:
      - "9102:9101"
    environment:
      - LOG_LEVEL=debug
      - REDIS_ADDR=redis:6379
    volumes:
      - ../../:/app
      - api-logs:/logs
      - api-experiments:/data/experiments
      - api-active:/data/active
      - go-mod-cache:/go/pkg/mod
    depends_on:
      redis:
        condition: service_healthy
    healthcheck:
      test: ["CMD", "wget", "-q", "--spider", "http://localhost:9101/health"]
      interval: 5s
      timeout: 3s
      retries: 10
      start_period: 30s

volumes:
  ssh-config:
  api-logs:
  api-experiments:
  api-active:
  go-mod-cache:
