# docker-compose.yml
# TranscriptIQ backend stack on DGX Spark
# Database: Supabase Transaction Pooler (IPv4, port 6543)
# Port: 8001 (8000 is taken by another service on this server)
# Ollama: accessed via Tailscale IP 100.91.168.119

version: "3.9"

services:

  # ── Redis (Celery broker) ───────────────────────────────────────────────────
  redis:
    image: redis:7-alpine
    container_name: transcriptiq_redis
    restart: unless-stopped
    ports:
      - "6379:6379"
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 10s
      timeout: 5s
      retries: 5

  # ── FastAPI app ─────────────────────────────────────────────────────────────
  app:
    build: .
    container_name: transcriptiq_app
    restart: unless-stopped
    ports:
      - "8001:8000"
    environment:
      DATABASE_URL: "postgresql://postgres.jceyhqalyrcafdzmffqx:crmp%401234automated@aws-1-ap-northeast-1.pooler.supabase.com:6543/postgres"
      REDIS_URL: redis://redis:6379/0
      OLLAMA_BASE_URL: http://100.91.168.119:11434
      SECRET_KEY: ${SECRET_KEY}
      STRIPE_SECRET_KEY: ${STRIPE_SECRET_KEY}
      STRIPE_WEBHOOK_SECRET: ${STRIPE_WEBHOOK_SECRET}
      STORAGE_BASE_PATH: /data/uploads
      DEBUG: "false"
      SMTP_HOST: ${SMTP_HOST}
      SMTP_PORT: ${SMTP_PORT}
      SMTP_USER: ${SMTP_USER}
      SMTP_PASSWORD: ${SMTP_PASSWORD}
      NOTIFY_EMAIL: ${NOTIFY_EMAIL}
    volumes:
      - upload_data:/data/uploads
    depends_on:
      redis:
        condition: service_healthy
    extra_hosts:
      - "host.docker.internal:host-gateway"
    command: uvicorn app.main:app --host 0.0.0.0 --port 8000 --workers 2

  # ── Celery worker ───────────────────────────────────────────────────────────
  worker:
    build: .
    container_name: transcriptiq_worker
    restart: unless-stopped
    environment:
      DATABASE_URL: "postgresql://postgres.jceyhqalyrcafdzmffqx:crmp%401234automated@aws-1-ap-northeast-1.pooler.supabase.com:6543/postgres"
      REDIS_URL: redis://redis:6379/0
      OLLAMA_BASE_URL: http://100.91.168.119:11434
      SECRET_KEY: ${SECRET_KEY}
      STORAGE_BASE_PATH: /data/uploads
    volumes:
      - upload_data:/data/uploads
    depends_on:
      redis:
        condition: service_healthy
    extra_hosts:
      - "host.docker.internal:host-gateway"
    command: celery -A app.workers.celery_app worker --loglevel=info --concurrency=1

volumes:
  upload_data: