version: '3.8'

services:
  tunevault:
    build: .
    ports:
      - "${PORT:-3000}:3000"
    environment:
      - NODE_ENV=production
      - PORT=3000
      - DATABASE_URL=postgresql://tunevault:${DB_PASSWORD}@db:5432/tunevault
      - SESSION_SECRET=${SESSION_SECRET}
      - OPENAI_API_KEY=${OPENAI_API_KEY}
      - ANTHROPIC_API_KEY=${ANTHROPIC_API_KEY}
      - GOOGLE_CLIENT_ID=${GOOGLE_CLIENT_ID:-}
      - GOOGLE_CLIENT_SECRET=${GOOGLE_CLIENT_SECRET:-}
      - RESEND_API_KEY=${RESEND_API_KEY:-}
      - ADMIN_EMAILS=${ADMIN_EMAILS}
      - TUNEVAULT_LICENSE_KEY=${TUNEVAULT_LICENSE_KEY}
      - TUNEVAULT_SELF_HOSTED=true
      - APP_URL=${APP_URL:-http://localhost:3000}
    depends_on:
      db:
        condition: service_healthy
    restart: unless-stopped
    volumes:
      - tunevault_data:/app/data

  db:
    image: postgres:15-alpine
    environment:
      - POSTGRES_DB=tunevault
      - POSTGRES_USER=tunevault
      - POSTGRES_PASSWORD=${DB_PASSWORD}
    volumes:
      - postgres_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U tunevault"]
      interval: 5s
      timeout: 5s
      retries: 5
    restart: unless-stopped

volumes:
  postgres_data:
  tunevault_data:
