services: postgres: image: postgres:16-alpine restart: unless-stopped environment: POSTGRES_DB: ${WB_POSTGRES_DB:-wb2api} POSTGRES_USER: ${WB_POSTGRES_USER:-wb2api} POSTGRES_PASSWORD: ${WB_POSTGRES_PASSWORD:-wb2api} TZ: ${TZ:-Asia/Shanghai} volumes: - pgdata:/var/lib/postgresql/data healthcheck: test: ["CMD-SHELL", "pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_DB}"] interval: 5s timeout: 3s retries: 20 start_period: 5s redis: image: redis:7-alpine restart: unless-stopped command: ["redis-server", "--appendonly", "yes", "--maxmemory-policy", "noeviction"] volumes: - redisdata:/data healthcheck: test: ["CMD", "redis-cli", "ping"] interval: 5s timeout: 3s retries: 20 wb2api: build: context: . args: VERSION: ${WB_VERSION:-dev} image: wb2api:local container_name: wb2api restart: unless-stopped depends_on: postgres: condition: service_healthy redis: condition: service_healthy ports: - "${WB_PORT:-8788}:8788" environment: # Set a strong password before exposing the panel. Empty means the # built-in default "admin" and a forced password change on first login. WB_PANEL_PASSWORD: ${WB_PANEL_PASSWORD:-} WB_MAX_BODY_MB: ${WB_MAX_BODY_MB:-16} WB_POSTGRES_DSN: postgres://${WB_POSTGRES_USER:-wb2api}:${WB_POSTGRES_PASSWORD:-wb2api}@postgres:5432/${WB_POSTGRES_DB:-wb2api}?sslmode=disable WB_REDIS_ADDR: redis:6379 WB_REDIS_INFLIGHT: ${WB_REDIS_INFLIGHT:-8} # Queue briefly for a hot account instead of spilling the conversation to # a cold account and losing its prefix cache. WB_REDIS_WAIT_MS: ${WB_REDIS_WAIT_MS:-1500} # Pick among this many least-loaded accounts instead of always the single # least-loaded one; avoids herding all new sessions onto one account. WB_SCHED_TOP_K: ${WB_SCHED_TOP_K:-7} # Hold response headers until the account emits semantic output; fail over # when it stays silent longer than this. 0 keeps the legacy behavior. WB_FIRST_OUTPUT_MS: ${WB_FIRST_OUTPUT_MS:-30000} # Completion first commits to a local durable outbox; PostgreSQL delivery # is asynchronous and ordered. Only optional details may be shed/sampled. WB_USAGE_QUEUE: ${WB_USAGE_QUEUE:-16384} WB_USAGE_WORKERS: ${WB_USAGE_WORKERS:-1} WB_USAGE_OVERFLOW: ${WB_USAGE_OVERFLOW:-drop} WB_USAGE_OUTBOX: /data/usage/usage-outbox.db WB_USAGE_OUTBOX_MB: ${WB_USAGE_OUTBOX_MB:-256} WB_SHARED_LIMIT_FAIL_OPEN: ${WB_SHARED_LIMIT_FAIL_OPEN:-0} WB_DOWNSTREAM_WRITE_MS: ${WB_DOWNSTREAM_WRITE_MS:-30000} TZ: ${TZ:-Asia/Shanghai} volumes: # Existing accounts/settings.json and legacy usage.db/usage.jsonl are # imported into PostgreSQL on the first boot. Completed usage is first # accepted in /data/usage/usage-outbox.db, then delivered to PostgreSQL. # Preserve this volume, including SQLite WAL files, across upgrades. - ./data:/data command: - -lan - -port - "8788" - -accounts-dir - /data/accounts - -usage-dir - /data/usage - -catalog-dir - /data/catalog healthcheck: test: ["CMD", "wget", "-qO-", "http://127.0.0.1:8788/health"] interval: 30s timeout: 3s retries: 3 start_period: 15s volumes: pgdata: redisdata: