version: "3.8"

services:
  postgres:
    image: postgres:16-alpine
    ports:
      - "5432:5432"
    environment:
      - POSTGRES_USER=${POSTGRES_USER:-raggr}
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-changeme}
      - POSTGRES_DB=${POSTGRES_DB:-raggr}
    volumes:
      - postgres_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-raggr}"]
      interval: 10s
      timeout: 5s
      retries: 5
    restart: unless-stopped

  raggr:
    build:
      context: .
      dockerfile: Dockerfile
    image: torrtle/simbarag:latest
    ports:
      - "8080:8080"
    environment:
      - PAPERLESS_TOKEN=${PAPERLESS_TOKEN}
      - BASE_URL=${BASE_URL}
      - OLLAMA_URL=${OLLAMA_URL:-http://localhost:11434}
      - CHROMADB_PATH=/app/data/chromadb
      - OPENAI_API_KEY=${OPENAI_API_KEY}
      - JWT_SECRET_KEY=${JWT_SECRET_KEY}
      - LLAMA_SERVER_URL=${LLAMA_SERVER_URL}
      - LLAMA_MODEL_NAME=${LLAMA_MODEL_NAME}
      - OIDC_ISSUER=${OIDC_ISSUER}
      - OIDC_CLIENT_ID=${OIDC_CLIENT_ID}
      - OIDC_CLIENT_SECRET=${OIDC_CLIENT_SECRET}
      - OIDC_REDIRECT_URI=${OIDC_REDIRECT_URI}
      - OIDC_USE_DISCOVERY=${OIDC_USE_DISCOVERY:-true}
      - DATABASE_URL=${DATABASE_URL:-postgres://raggr:changeme@postgres:5432/raggr}
      - TAVILY_API_KEY=${TAVILIY_API_KEY}
      - YNAB_ACCESS_TOKEN=${YNAB_ACCESS_TOKEN}
      - YNAB_BUDGET_ID=${YNAB_BUDGET_ID}
      - TWILIO_ACCOUNT_SID=${TWILIO_ACCOUNT_SID}
      - TWILIO_AUTH_TOKEN=${TWILIO_AUTH_TOKEN}
      - TWILIO_WHATSAPP_NUMBER=${TWILIO_WHATSAPP_NUMBER}
      - ALLOWED_WHATSAPP_NUMBERS=${ALLOWED_WHATSAPP_NUMBERS}
      - TWILIO_SIGNATURE_VALIDATION=${TWILIO_SIGNATURE_VALIDATION:-true}
      - TWILIO_WEBHOOK_URL=${TWILIO_WEBHOOK_URL:-}
      - OBSIDIAN_AUTH_TOKEN=${OBSIDIAN_AUTH_TOKEN}
      - OBSIDIAN_VAULT_ID=${OBSIDIAN_VAULT_ID}
      - OBSIDIAN_E2E_PASSWORD=${OBSIDIAN_E2E_PASSWORD}
      - OBSIDIAN_DEVICE_NAME=${OBSIDIAN_DEVICE_NAME}
      - OBSIDIAN_CONTINUOUS_SYNC=${OBSIDIAN_CONTINUOUS_SYNC:-false}
      - OBSIDIAN_VAULT_PATH=${OBSIDIAN_VAULT_PATH:-/app/data/obsidian}
    depends_on:
      postgres:
        condition: service_healthy
    volumes:
      - chromadb_data:/app/data/chromadb
      - ./obvault:/app/data/obsidian
    restart: unless-stopped

volumes:
  chromadb_data:
  postgres_data:
