# deploy/docker-compose.yml — dev(단일 머신) 자기호스트
# 기본: SQLite 볼륨 + Ollama 로컬 + Caddy HTTPS. prod 오버라이드는 docker-compose.prod.yml.
services:
  backend:
    build: ../backend
    env_file: [.env.prod]
    environment:
      DATABASE_URL: sqlite:////data/ari.db
      OLLAMA_HOST: http://ollama:11434
      WORKER_ENABLED: "false" # 웹 컨테이너는 스케줄러 미가동(잡 중복 방지)
      BACKUP_DIR: /backups
    volumes:
      - ari-data:/data
      - ari-backups:/backups
    depends_on: [ollama]
    restart: unless-stopped

  worker:
    build: ../backend
    env_file: [.env.prod]
    environment:
      DATABASE_URL: sqlite:////data/ari.db
      OLLAMA_HOST: http://ollama:11434
      WORKER_ENABLED: "true" # 스케줄러 전용 컨테이너 1개만 true
    command: ["python", "-m", "app.worker.runner"]
    volumes:
      - ari-data:/data
      - ari-backups:/backups
    depends_on: [backend, ollama]
    restart: unless-stopped

  frontend:
    build: ../frontend
    environment:
      NEXT_PUBLIC_API_BASE: "" # 동일 출처(Caddy 가 /api 를 backend 로 라우팅)
      NEXT_PUBLIC_AUTH_ENABLED: "true"
    depends_on: [backend]
    restart: unless-stopped

  ollama:
    image: ollama/ollama:latest
    volumes:
      - ollama-models:/root/.ollama
    restart: unless-stopped

  caddy:
    image: caddy:2-alpine
    ports: ["80:80", "443:443"]
    volumes:
      - ./Caddyfile:/etc/caddy/Caddyfile:ro
      - caddy-data:/data
      - caddy-config:/config
    depends_on: [frontend, backend]
    restart: unless-stopped

volumes:
  ari-data:
  ari-backups:
  ollama-models:
  caddy-data:
  caddy-config:
