# docker-compose.board-integrated.yml
# KohakuBoard integrated with KohakuHub (shared database for SSO)
#
# This is OPTIONAL - only use if you want KohakuBoard to share
# database with KohakuHub for unified user accounts (SSO).
#
# If KohakuHub is already running:
#   - KohakuBoard will connect to existing PostgreSQL
#   - Users can login to both systems with same credentials
#
# If KohakuHub is NOT running:
#   - Use docker-compose.kohakuboard.yml instead (fully standalone)
#
# Usage:
#   python scripts/deploy_board_integrated.py

services:
  board-ui:
    image: nginx:alpine
    container_name: board-ui
    restart: always
    ports:
      - "28081:80"  # Board web interface
    volumes:
      - ./src/kohaku-board-ui/dist:/usr/share/nginx/html
      - ./docker/kohakuboard/nginx.conf:/etc/nginx/conf.d/default.conf
    depends_on:
      - board-api
    networks:
      - hub-net

  board-api:
    build:
      context: .
      dockerfile: docker/kohakuboard/Dockerfile
    container_name: board-api
    restart: always
    ports:
      - "48889:48889"  # Internal API port (optional, for debugging)
    environment:
      ## ===== Mode Configuration =====
      - KOHAKU_BOARD_MODE=remote
      - KOHAKU_BOARD_BASE_URL=http://127.0.0.1:28081

      ## ===== CRITICAL: Shared Database with KohakuHub =====
      ## Use the EXACT same database as KohakuHub for unified accounts
      - KOHAKU_BOARD_DB_BACKEND=postgres
      - KOHAKU_BOARD_DATABASE_URL=postgresql://hub:hubpass@postgres:5432/kohakuhub

      ## ===== CRITICAL: Shared Session Secret for SSO =====
      ## Must match KohakuHub's session secret for single sign-on
      - KOHAKU_BOARD_AUTH_SESSION_SECRET=change-this-to-random-string-in-production

      ## ===== Authentication Configuration =====
      - KOHAKU_BOARD_AUTH_REQUIRE_EMAIL_VERIFICATION=false
      - KOHAKU_BOARD_AUTH_INVITATION_ONLY=false
      - KOHAKU_BOARD_AUTH_SESSION_EXPIRE_HOURS=168
      - KOHAKU_BOARD_AUTH_TOKEN_EXPIRE_DAYS=365

      ## ===== SMTP Configuration =====
      - KOHAKU_BOARD_SMTP_ENABLED=false
      - KOHAKU_BOARD_SMTP_HOST=smtp.gmail.com
      - KOHAKU_BOARD_SMTP_PORT=587
      - KOHAKU_BOARD_SMTP_USERNAME=
      - KOHAKU_BOARD_SMTP_PASSWORD=
      - KOHAKU_BOARD_SMTP_FROM=noreply@kohakuhub.local
      - KOHAKU_BOARD_SMTP_TLS=true

      ## ===== Application Configuration =====
      - KOHAKU_BOARD_BOARD_DATA_DIR=/app/kohakuboard
    volumes:
      - ./board-data:/app/kohakuboard
    networks:
      - hub-net

networks:
  hub-net:
    external: true  # Connect to existing hub-net from KohakuHub
