Files
DeepTutor/docker-compose.yml
xor_xe 6ca2ecd64f feat: add optional PocketBase integration for auth and session storage
Introduces PocketBase as an optional sidecar for authentication and
session/KB storage, activated only when POCKETBASE_URL is set in .env.
Falls back to the existing SQLite/JSON backend when not configured.

Backend:
- SessionStoreProtocol (typing.Protocol) + get_session_store() factory
- PocketBaseSessionStore: JSONL write-ahead buffer, batch-flush on turn end
- pocketbase_client.py: singleton admin client, 60s in-memory token cache
- auth.py: additive PocketBase path (email-based login/register)
- CORS: explicit origins instead of wildcard (wildcard+credentials fails)
- WebSocket: validate token at connect time when AUTH_ENABLED

Infrastructure:
- docker-compose: pocketbase service with healthcheck + depends_on
- scripts/pb_setup.py: idempotent PocketBase collection bootstrap
- requirements/server.txt: pocketbase>=0.12.0

Frontend:
- Register/login: username field -> email field for PocketBase mode
- auth.ts: normalise FastAPI 422 errors to plain strings
- agents page: guard bots.map() against non-array responses
- settings page: graceful fetch error handling
- *.env.local added to .gitignore

Docs: README PocketBase sidecar setup section added
2026-04-17 21:42:29 +04:00

134 lines
4.9 KiB
YAML

# ============================================
# DeepTutor Docker Compose Configuration
# ============================================
# This file provides orchestration for DeepTutor services
#
# Usage:
# Production: docker compose up -d
# Development: docker compose -f docker-compose.yml -f docker-compose.dev.yml up
# Build only: docker compose build
#
# Prerequisites:
# 1. Copy .env.example to .env and configure your API keys
# 2. Runtime settings are stored in ./data/user/settings (created automatically)
#
# Local LLM (LM Studio / Ollama / vLLM):
# Use "host.docker.internal" instead of "localhost" for LLM_HOST / EMBEDDING_HOST.
# See .env.example for details.
# ============================================
services:
# ============================================
# PocketBase — optional auth + storage sidecar
# Set POCKETBASE_URL=http://pocketbase:8090 in .env to activate.
# Leave POCKETBASE_URL blank to run without PocketBase (SQLite fallback).
# ============================================
pocketbase:
image: ghcr.io/muchobien/pocketbase:latest
container_name: pocketbase
restart: unless-stopped
ports:
- "${POCKETBASE_PORT:-8090}:8090"
volumes:
- ./data/pocketbase:/pb/pb_data
networks:
- deeptutor-network
healthcheck:
test: ["CMD", "wget", "--quiet", "--tries=1", "--spider", "http://localhost:8090/api/health"]
interval: 10s
timeout: 5s
retries: 3
start_period: 10s
# ============================================
# All-in-One DeepTutor Service
# ============================================
deeptutor:
build:
context: .
dockerfile: Dockerfile
target: production
args:
# Pass backend port at build time for Next.js static optimization
- BACKEND_PORT=${BACKEND_PORT:-8001}
container_name: deeptutor
restart: unless-stopped
ports:
- "${BACKEND_PORT:-8001}:${BACKEND_PORT:-8001}"
- "${FRONTEND_PORT:-3782}:${FRONTEND_PORT:-3782}"
# Load environment variables from .env file
env_file:
- .env
environment:
# LLM Configuration (Required)
- LLM_BINDING=${LLM_BINDING:-openai}
- LLM_MODEL=${LLM_MODEL}
- LLM_API_KEY=${LLM_API_KEY}
- LLM_HOST=${LLM_HOST}
- LLM_API_VERSION=${LLM_API_VERSION:-}
- DISABLE_SSL_VERIFY=${DISABLE_SSL_VERIFY:-false}
# Embedding Configuration (Required for Knowledge Base)
- EMBEDDING_BINDING=${EMBEDDING_BINDING:-openai}
- EMBEDDING_MODEL=${EMBEDDING_MODEL:-text-embedding-3-large}
- EMBEDDING_API_KEY=${EMBEDDING_API_KEY}
- EMBEDDING_HOST=${EMBEDDING_HOST}
- EMBEDDING_DIMENSION=${EMBEDDING_DIMENSION:-3072}
- EMBEDDING_API_VERSION=${EMBEDDING_API_VERSION:-}
# Web Search Configuration (Optional)
- SEARCH_PROVIDER=${SEARCH_PROVIDER:-}
- SEARCH_API_KEY=${SEARCH_API_KEY:-}
- SEARCH_BASE_URL=${SEARCH_BASE_URL:-}
# ============================================
# Service Ports Configuration
# ============================================
# Backend API port (default: 8001)
- BACKEND_PORT=${BACKEND_PORT:-8001}
# Frontend web port (default: 3782)
- FRONTEND_PORT=${FRONTEND_PORT:-3782}
# ============================================
# API URL Configuration (Important for Remote Deployment)
# ============================================
# The frontend runs in the USER'S BROWSER — "localhost" means the user's machine,
# not the Docker host. This matters when Docker runs on a remote server.
#
# LOCAL (browsing from the same machine running Docker):
# Leave blank — defaults to http://localhost:8001, which works via port mapping.
#
# REMOTE SERVER (Docker on a server, accessed from another machine):
# Set to the server's public IP or hostname, e.g.:
# NEXT_PUBLIC_API_BASE_EXTERNAL=http://203.0.113.10:8001
# Without this the browser tries localhost:8001 on the user's laptop and all
# API calls (including WebSocket) will fail.
- NEXT_PUBLIC_API_BASE_EXTERNAL=${NEXT_PUBLIC_API_BASE_EXTERNAL:-}
# Alternative: Direct API base URL (same priority as NEXT_PUBLIC_API_BASE_EXTERNAL)
- NEXT_PUBLIC_API_BASE=${NEXT_PUBLIC_API_BASE:-}
volumes:
# Mount local data directory for persistence (read-write)
# This includes runtime settings under ./data/user/settings.
- ./data/user:/app/data/user
- ./data/knowledge_bases:/app/data/knowledge_bases
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:${BACKEND_PORT:-8001}/"]
interval: 30s
timeout: 10s
retries: 3
start_period: 60s
depends_on:
pocketbase:
condition: service_healthy
networks:
- deeptutor-network
# ============================================
# Networks
# ============================================
networks:
deeptutor-network:
driver: bridge