# Public Otter stack — no GitHub clone required for end users.
# Served from the marketing site: https://otter.manasdutta.com/docker-compose.yml
#
#   docker pull manasdutta04/otter
#   docker compose -f https://otter.manasdutta.com/docker-compose.yml up -d
#   open http://127.0.0.1:3000/app
#   Click Connect GitHub (Otter GitHub App via Cloudflare auth broker)
#
# Source is public: https://github.com/manasdutta04/otter
# No GitHub Client Secret on the user machine. Operator sets OTTER_AUTH_BROKER_URL
# when the broker is deployed.

name: otter

services:
  postgres:
    image: postgres:16-alpine
    environment:
      POSTGRES_USER: otter
      POSTGRES_PASSWORD: otter
      POSTGRES_DB: otter
    volumes:
      - postgres_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U otter -d otter"]
      interval: 2s
      timeout: 5s
      retries: 20
      start_period: 5s
    restart: unless-stopped

  redis:
    image: redis:7-alpine
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 2s
      timeout: 3s
      retries: 20
    restart: unless-stopped

  platform:
    image: manasdutta04/otter:latest
    ports:
      - "127.0.0.1:3000:3000"
      - "127.0.0.1:8000:8000"
    environment:
      DATABASE_URL: postgresql+asyncpg://otter:otter@postgres:5432/otter
      REDIS_URL: redis://redis:6379/0
      REPOSITORY_DATA_DIR: /data/repositories
      PYTHONPATH: /app:/app/api
      POSTGRES_HOST: postgres
      POSTGRES_PORT: "5432"
      REDIS_HOST: redis
      REDIS_PORT: "6379"
      NEXT_PUBLIC_URL: http://127.0.0.1:3000
      NEXT_PUBLIC_SITE_URL: ${NEXT_PUBLIC_SITE_URL:-http://127.0.0.1:3001}
      LLM_BASE_URL: ${PLATFORM_LLM_BASE_URL:-http://host.docker.internal:11434/v1}
      LLM_MODEL: ${LLM_MODEL:-qwen2.5-coder:7b}
      LLM_FREE_FAILOVER: ${LLM_FREE_FAILOVER:-true}
      # Public auth broker URL (no secrets). Optional redeem secret comes from your .env only.
      OTTER_AUTH_BROKER_URL: ${OTTER_AUTH_BROKER_URL:-https://otter-auth-broker.manasdutta512.workers.dev}
      OTTER_AUTH_REDEEM_SECRET: ${OTTER_AUTH_REDEEM_SECRET:-}
    volumes:
      - repository_data:/data/repositories
    extra_hosts:
      - "host.docker.internal:host-gateway"
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_healthy
    restart: unless-stopped

volumes:
  postgres_data:
  repository_data:
