aido-onyx/docker-compose.yml

641 lines
No EOL
24 KiB
YAML

services:
api_server:
image: ${ONYX_BACKEND_IMAGE:-onyxdotapp/onyx-backend:${IMAGE_TAG:-latest}}
entrypoint: |
sh -c "
python3 << 'PYEOF'
import os, sys
def read_file(path):
with open(path, \"r\") as f:
return f.read()
def write_file(path, content):
with open(path, \"w\") as f:
f.write(content)
# --- 1. Clean up corrupted factory.py ---
factory_path = \"/app/onyx/voice/factory.py\"
if os.path.exists(factory_path):
src = read_file(factory_path)
# Fix corrupted api_base line (remove repeated or chains)
if 'api_base = provider.api_base or \\\"https://aido-whisper-ch.livtec.cloud/v1\\\"' in src:
src = src.replace(
'api_base = provider.api_base or \\\"https://aido-whisper-ch.livtec.cloud/v1\\\" or \\\"https://aido-whisper-ch.livtec.cloud/v1\\\" or \\\"https://aido-whisper-ch.livtec.cloud/v1\\\"',
'api_base = provider.api_base or \\\"https://aido-whisper-ch.livtec.cloud/v1\\\"'
)
# Also handle case where it ran twice with different corruption levels
src = src.replace(
'api_base = provider.api_base or \\\"https://aido-whisper-ch.livtec.cloud/v1\\\" or \\\"https://aido-whisper-ch.livtec.cloud/v1\\\"',
'api_base = provider.api_base or \\\"https://aido-whisper-ch.livtec.cloud/v1\\\"'
)
print(\"[OK] factory.py api_base cleaned up\")
# Ensure api_base fallback is present (idempotent)
if 'api_base = provider.api_base or \\\"https://aido-whisper-ch.livtec.cloud/v1\\\"' not in src:
if 'api_base = provider.api_base' in src:
src = src.replace(
'api_base = provider.api_base',
'api_base = provider.api_base or \\\"https://aido-whisper-ch.livtec.cloud/v1\\\"'
)
print(\"[OK] factory.py api_base fallback applied\")
else:
print(\"[WARN] factory.py: api_base pattern not found\")
else:
print(\"[OK] factory.py api_base already correct\")
# Fix corrupted stt_model line
if 'stt_model = provider.stt_model or \\\"whisper-1\\\" or \\\"whisper-1\\\"' in src:
src = src.replace(
'stt_model = provider.stt_model or \\\"whisper-1\\\" or \\\"whisper-1\\\"',
'stt_model = provider.stt_model or \\\"whisper-1\\\"'
)
print(\"[OK] factory.py stt_model cleaned up\")
# Ensure stt_model fallback is present (idempotent)
if 'stt_model = provider.stt_model or \\\"whisper-1\\\"' not in src:
if 'stt_model = provider.stt_model' in src:
src = src.replace(
'stt_model = provider.stt_model',
'stt_model = provider.stt_model or \\\"whisper-1\\\"'
)
print(\"[OK] factory.py stt_model fallback applied\")
else:
print(\"[WARN] factory.py: stt_model pattern not found\")
else:
print(\"[OK] factory.py stt_model already correct\")
write_file(factory_path, src)
else:
print(\"[FATAL] factory.py not found\")
sys.exit(1)
# --- 2. Patch openai.py ---
openai_path = \"/app/onyx/voice/providers/openai.py\"
if not os.path.exists(openai_path):
print(\"[FATAL] openai.py not found\")
sys.exit(1)
src = read_file(openai_path)
# 2a. Ensure DEFAULT_OPENAI_API_BASE points to your endpoint (idempotent)
if 'DEFAULT_OPENAI_API_BASE = \\\"https://api.openai.com\\\"' in src:
src = src.replace(
'DEFAULT_OPENAI_API_BASE = \\\"https://api.openai.com\\\"',
'DEFAULT_OPENAI_API_BASE = \\\"https://aido-whisper-ch.livtec.cloud/v1\\\"'
)
print(\"[OK] openai.py DEFAULT_OPENAI_API_BASE patched\")
else:
print(\"[OK] openai.py DEFAULT_OPENAI_API_BASE already correct or upstream changed\")
# 2b. Ensure realtime models are whisper-1 (idempotent)
if 'OPENAI_REALTIME_SESSION_MODEL = \\\"gpt-realtime-1.5\\\"' in src:
src = src.replace(
'OPENAI_REALTIME_SESSION_MODEL = \\\"gpt-realtime-1.5\\\"',
'OPENAI_REALTIME_SESSION_MODEL = \\\"whisper-1\\\"'
)
print(\"[OK] openai.py REALTIME_SESSION_MODEL patched\")
else:
print(\"[OK] openai.py REALTIME_SESSION_MODEL already correct or upstream changed\")
if 'OPENAI_REALTIME_STT_MODEL = \\\"gpt-realtime-whisper\\\"' in src:
src = src.replace(
'OPENAI_REALTIME_STT_MODEL = \\\"gpt-realtime-whisper\\\"',
'OPENAI_REALTIME_STT_MODEL = \\\"whisper-1\\\"'
)
print(\"[OK] openai.py REALTIME_STT_MODEL patched\")
else:
print(\"[OK] openai.py REALTIME_STT_MODEL already correct or upstream changed\")
# 2c. Inject language parameter into SDK transcribe call (THE CRITICAL FIX)
if \"WHISPER_LANGUAGE\" not in src:
# Add import os near top if missing
lines = src.split(\"\\n\")
import_idx = next((i for i, l in enumerate(lines) if l.startswith(\"import \") or l.startswith(\"from \")), 0)
if not any(\"import os\" in l for l in lines[:import_idx+5]):
lines.insert(import_idx, \"import os\")
print(\"[OK] openai.py added import os\")
# Rejoin and find the transcribe method's create() call
src = \"\\n\".join(lines)
# Pattern: the SDK call inside transcribe()
old_pattern = ''' response = await client.audio.transcriptions.create(
model=self.stt_model,
file=audio_file,
)'''
new_pattern = ''' response = await client.audio.transcriptions.create(
model=self.stt_model,
file=audio_file,
language=os.environ.get(\"WHISPER_LANGUAGE\", \"de\"),
)'''
if old_pattern in src:
src = src.replace(old_pattern, new_pattern)
print(\"[OK] openai.py language parameter injected into transcribe()\")
else:
print(\"[WARN] openai.py: could not find exact transcribe() SDK call pattern to inject language\")
print(\"[WARN] STT may default to English auto-detect instead of German\")
else:
print(\"[OK] openai.py language already present\")
write_file(openai_path, src)
print(\"[DONE] All patches applied successfully\")
PYEOF
# Run migrations and start server
alembic upgrade head && echo \"Starting Onyx Api Server\" && exec uvicorn onyx.main:app --host 0.0.0.0 --port 8080
"
#command: >
# /bin/sh -c "alembic upgrade head && echo \"Starting Onyx Api Server\" &&
# uvicorn onyx.main:app --host 0.0.0.0 --port 8080"
# Check env.template and copy to .env for env vars
env_file:
- path: .env
required: false
depends_on:
relational_db:
condition: service_started
opensearch:
condition: service_started
cache:
condition: service_started
inference_model_server:
condition: service_started
restart: unless-stopped
networks:
- onyx-network
# DEV: To expose ports, either:
# 1. Use docker-compose.dev.yml: docker compose -f docker-compose.yml -f docker-compose.dev.yml up -d --wait
# 2. Uncomment the ports below
# ports:
# - "8080:8080"
environment:
# Auth Settings
- AUTH_TYPE=${AUTH_TYPE:-basic}
- FILE_STORE_BACKEND=${FILE_STORE_BACKEND:-s3}
- POSTGRES_HOST=${POSTGRES_HOST:-relational_db}
- OPENSEARCH_HOST=${OPENSEARCH_HOST:-opensearch}
- OPENSEARCH_ADMIN_PASSWORD=${OPENSEARCH_ADMIN_PASSWORD:-StrongPassword123!}
- REDIS_HOST=${REDIS_HOST:-cache}
- MODEL_SERVER_HOST=${MODEL_SERVER_HOST:-inference_model_server}
- CODE_INTERPRETER_BASE_URL=${CODE_INTERPRETER_BASE_URL:-http://code-interpreter:8000}
- S3_ENDPOINT_URL=${S3_ENDPOINT_URL:-http://minio:9000}
- S3_REGION=us-east-1
- S3_AWS_ACCESS_KEY_ID=${S3_AWS_ACCESS_KEY_ID:-minioadmin}
- S3_AWS_SECRET_ACCESS_KEY=${S3_AWS_SECRET_ACCESS_KEY:-minioadmin}
# Onyx Craft configuration (disabled by default, set ENABLE_CRAFT=true in .env to enable)
# Use --include-craft with install script, or manually set in .env file
- ENABLE_CRAFT=${ENABLE_CRAFT:-false}
- VOICE_DISABLE_STREAMING_STT=true
- WHISPER_LANGUAGE=de
# PRODUCTION: Uncomment the line below to use if IAM_AUTH is true and you are using iam auth for postgres
# volumes:
# - ./bundle.pem:/app/bundle.pem:ro
extra_hosts:
- host.docker.internal:host-gateway
logging:
driver: json-file
options:
max-size: 50m
max-file: "6"
healthcheck:
test:
- CMD
- python
- -c
- import urllib.request;
urllib.request.urlopen('http://localhost:8080/health')
interval: 30s
timeout: 20s
retries: 3
# Generous start_period so that `docker compose up --wait` does not flag
# the container unhealthy while alembic migrations run on a fresh DB.
# Healthy is reported as soon as /health responds, so this does not slow
# down fast boots.
start_period: 600s
# Optional, only for debugging purposes
volumes:
- ./api_server_logs:/var/log/onyx
# Shared volume for persistent document storage (Craft file-system mode)
- ./file-system:/app/file-system
background:
image: ${ONYX_BACKEND_IMAGE:-onyxdotapp/onyx-backend:${IMAGE_TAG:-latest}}
command: |
/bin/sh -c " if [ -f /etc/ssl/certs/custom-ca.crt ]; then
update-ca-certificates;
fi && /app/scripts/supervisord_entrypoint.sh"
networks:
- onyx-network
env_file:
- path: .env
required: false
depends_on:
relational_db:
condition: service_started
opensearch:
condition: service_started
cache:
condition: service_started
inference_model_server:
condition: service_started
indexing_model_server:
condition: service_started
restart: unless-stopped
environment:
- FILE_STORE_BACKEND=${FILE_STORE_BACKEND:-s3}
- POSTGRES_HOST=${POSTGRES_HOST:-relational_db}
- OPENSEARCH_HOST=${OPENSEARCH_HOST:-opensearch}
- OPENSEARCH_ADMIN_PASSWORD=${OPENSEARCH_ADMIN_PASSWORD:-StrongPassword123!}
- REDIS_HOST=${REDIS_HOST:-cache}
- MODEL_SERVER_HOST=${MODEL_SERVER_HOST:-inference_model_server}
- INDEXING_MODEL_SERVER_HOST=${INDEXING_MODEL_SERVER_HOST:-indexing_model_server}
- S3_ENDPOINT_URL=${S3_ENDPOINT_URL}
- S3_REGION=${S3_REGION}
- S3_AWS_ACCESS_KEY_ID=${S3_AWS_ACCESS_KEY_ID}
- S3_AWS_SECRET_ACCESS_KEY=${S3_AWS_SECRET_ACCESS_KEY}
- DISCORD_BOT_TOKEN=${DISCORD_BOT_TOKEN:-}
- DISCORD_BOT_INVOKE_CHAR=${DISCORD_BOT_INVOKE_CHAR:-!}
# API Server connection for Discord bot message processing
- API_SERVER_PROTOCOL=${API_SERVER_PROTOCOL:-http}
- API_SERVER_HOST=${API_SERVER_HOST:-api_server}
# Onyx Craft configuration (set up automatically on container startup)
- ENABLE_CRAFT=${ENABLE_CRAFT:-false}
# PRODUCTION: Uncomment the line below to use if IAM_AUTH is true and you are using iam auth for postgres
# volumes:
# - ./bundle.pem:/app/bundle.pem:ro
extra_hosts:
- host.docker.internal:host-gateway
# Optional, only for debugging purposes
volumes:
- ./background_logs:/var/log/onyx
# Shared volume for persistent document storage (Craft file-system mode)
- ./file-system:/app/file-system
logging:
driver: json-file
options:
max-size: 50m
max-file: "6"
# PRODUCTION: Uncomment the following lines if you need to include a custom CA certificate
# This section enables the use of a custom CA certificate
# If present, the custom CA certificate is mounted as a volume
# The container checks for its existence and updates the system's CA certificates
# This allows for secure communication with services using custom SSL certificates
# Optional volume mount for CA certificate
# volumes:
# # Maps to the CA_CERT_PATH environment variable in the Dockerfile
# - ${CA_CERT_PATH:-./custom-ca.crt}:/etc/ssl/certs/custom-ca.crt:ro
web_server:
# Branded AIDO web image, built locally from ./web after `make apply`.
# This is the ONLY locally-built image; every other service below uses the
# official Onyx images unchanged. pull_policy: never => never overwrite it.
image: livtec/aido-web:local
pull_policy: never
build:
context: ./web
dockerfile: Dockerfile
args:
- NEXT_PUBLIC_DISABLE_LOGOUT=${NEXT_PUBLIC_DISABLE_LOGOUT:-}
- NEXT_PUBLIC_FORGOT_PASSWORD_ENABLED=${NEXT_PUBLIC_FORGOT_PASSWORD_ENABLED:-}
# Enterprise Edition only
- NEXT_PUBLIC_THEME=${NEXT_PUBLIC_THEME:-}
# DO NOT TURN ON unless you have EXPLICIT PERMISSION from Onyx.
- NEXT_PUBLIC_DO_NOT_USE_TOGGLE_OFF_DANSWER_POWERED=${NEXT_PUBLIC_DO_NOT_USE_TOGGLE_OFF_DANSWER_POWERED:-false}
- NODE_OPTIONS=${NODE_OPTIONS:-"--max-old-space-size=4096"}
networks:
- onyx-network
env_file:
- path: .env
required: false
depends_on:
- api_server
restart: unless-stopped
environment:
- INTERNAL_URL=${INTERNAL_URL:-http://api_server:8080}
logging:
driver: json-file
options:
max-size: 50m
max-file: "6"
healthcheck:
test:
- CMD
- node
- -e
- "require('http').get('http://127.0.0.1:3000/', (r) =>
process.exit(r.statusCode < 500 ? 0 : 1)).on('error', () =>
process.exit(1))"
interval: 30s
timeout: 10s
retries: 5
start_period: 30s
# Uncomment the block below to enable the MCP server for Onyx.
# mcp_server:
# image: ${ONYX_BACKEND_IMAGE:-onyxdotapp/onyx-backend:${IMAGE_TAG:-latest}}
# command: >
# /bin/sh -c "if [ \"${MCP_SERVER_ENABLED:-}\" != \"True\" ] && [ \"${MCP_SERVER_ENABLED:-}\" != \"true\" ]; then
# echo 'MCP server is disabled (MCP_SERVER_ENABLED=false), skipping...';
# exit 0;
# else
# exec python -m onyx.mcp_server_main;
# fi"
# env_file:
# - path: .env
# required: false
# depends_on:
# - relational_db
# - cache
# restart: "no"
# environment:
# - POSTGRES_HOST=${POSTGRES_HOST:-relational_db}
# - REDIS_HOST=${REDIS_HOST:-cache}
# # MCP Server Configuration
# - MCP_SERVER_ENABLED=${MCP_SERVER_ENABLED:-false}
# - MCP_SERVER_PORT=${MCP_SERVER_PORT:-8090}
# - MCP_SERVER_CORS_ORIGINS=${MCP_SERVER_CORS_ORIGINS:-}
# - API_SERVER_PROTOCOL=${API_SERVER_PROTOCOL:-http}
# - API_SERVER_HOST=${API_SERVER_HOST:-api_server}
# extra_hosts:
# - "host.docker.internal:host-gateway"
# logging:
# driver: json-file
# options:
# max-size: "50m"
# max-file: "6"
# # Optional, only for debugging purposes
# volumes:
# - ./mcp_server_logs:/var/log/onyx
inference_model_server:
image: ${ONYX_MODEL_SERVER_IMAGE:-onyxdotapp/onyx-model-server:${IMAGE_TAG:-latest}}
networks:
- onyx-network
env_file:
- path: .env
required: false
restart: unless-stopped
volumes:
# Not necessary, this is just to reduce download time during startup
- ./model_cache_huggingface:/app/.cache/huggingface/
# Optional, only for debugging purposes
- ./inference_model_server_logs:/var/log/onyx
logging:
driver: json-file
options:
max-size: 50m
max-file: "6"
healthcheck:
test:
- CMD
- python
- -c
- import urllib.request;
urllib.request.urlopen('http://localhost:9000/api/health')
interval: 20s
timeout: 5s
retries: 3
# Generous start_period to absorb HuggingFace model downloads on first
# boot. Healthy is reported as soon as /api/health responds.
start_period: 600s
indexing_model_server:
image: ${ONYX_MODEL_SERVER_IMAGE:-onyxdotapp/onyx-model-server:${IMAGE_TAG:-latest}}
networks:
- onyx-network
env_file:
- path: .env
required: false
restart: unless-stopped
environment:
- INDEXING_ONLY=True
volumes:
# Not necessary, this is just to reduce download time during startup
- ./indexing_huggingface_model_cache:/app/.cache/huggingface/
# Optional, only for debugging purposes
- ./indexing_model_server_logs:/var/log/onyx
logging:
driver: json-file
options:
max-size: 50m
max-file: "6"
healthcheck:
test:
- CMD
- python
- -c
- import urllib.request;
urllib.request.urlopen('http://localhost:9000/api/health')
interval: 20s
timeout: 5s
retries: 3
# Generous start_period to absorb HuggingFace model downloads on first
# boot. Healthy is reported as soon as /api/health responds.
start_period: 600s
relational_db:
image: ${BASE_IMAGE_REGISTRY:-docker.io}/library/postgres:15.2-alpine
shm_size: 1g
command: -c 'max_connections=250'
networks:
- onyx-network
env_file:
- path: .env
required: false
restart: unless-stopped
# PRODUCTION: Override the defaults by passing in the environment variables
environment:
- POSTGRES_USER=${POSTGRES_USER:-postgres}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-password}
# DEV: To expose ports, either:
# 1. Use docker-compose.dev.yml: docker compose -f docker-compose.yml -f docker-compose.dev.yml up -d --wait
# 2. Uncomment the ports below
# ports:
# - "5432:5432"
healthcheck:
test:
- CMD-SHELL
- pg_isready -U ${POSTGRES_USER:-postgres}
interval: 10s
timeout: 5s
retries: 5
volumes:
- ./db_volume:/var/lib/postgresql/data
logging:
driver: json-file
options:
max-size: 50m
max-file: "6"
opensearch:
image: ${BASE_IMAGE_REGISTRY:-docker.io}/opensearchproject/opensearch:3.6.0
restart: unless-stopped
# OpenSearch is the search backend and is enabled by default. To run against
# an external OpenSearch instance, set OPENSEARCH_HOST in your env and
# remove this service from the compose file (or skip it via the service list
# when running `docker compose up`).
environment:
# We need discovery.type=single-node so that OpenSearch doesn't try
# forming a cluster and waiting for other nodes to become live.
- discovery.type=single-node
- OPENSEARCH_INITIAL_ADMIN_PASSWORD=${OPENSEARCH_ADMIN_PASSWORD:-StrongPassword123!}
# This and the JVM config below come from the example in https://docs.opensearch.org/latest/install-and-configure/install-opensearch/docker/
# We do this to avoid unstable performance from page swaps.
- bootstrap.memory_lock=true # Disable JVM heap memory swapping.
# Java heap should be ~50% of memory limit. For now we assume a limit of
# 4g although in practice the container can request more than this.
# See https://opster.com/guides/opensearch/opensearch-basics/opensearch-heap-size-usage-and-jvm-garbage-collection/
# Xms is the starting size, Xmx is the maximum size. These should be the
# same.
- OPENSEARCH_JAVA_OPTS=-Xms2g -Xmx2g
networks:
- onyx-network
volumes:
- opensearch-data:/usr/share/opensearch/data
# These come from the example in https://docs.opensearch.org/latest/install-and-configure/install-opensearch/docker/
ulimits:
# Similarly to bootstrap.memory_lock, we don't want to impose limits on
# how much memory a process can lock from being swapped.
memlock:
soft: -1 # Set memlock to unlimited (no soft or hard limit).
hard: -1
nofile:
soft: 65536 # Maximum number of open files for the opensearch user - set to at least 65536.
hard: 65536
logging:
driver: json-file
options:
max-size: 50m
max-file: "6"
nginx:
image: ${BASE_IMAGE_REGISTRY:-docker.io}/library/nginx:1.25.5-alpine
restart: unless-stopped
# nginx will immediately crash with `nginx: [emerg] host not found in upstream`
# if api_server / web_server are not up
depends_on:
api_server:
condition: service_healthy
web_server:
condition: service_healthy
env_file:
- path: .env
required: false
environment:
- DOMAIN=localhost
# Nginx proxy timeout settings (in seconds)
- NGINX_PROXY_CONNECT_TIMEOUT=${NGINX_PROXY_CONNECT_TIMEOUT:-300}
- NGINX_PROXY_SEND_TIMEOUT=${NGINX_PROXY_SEND_TIMEOUT:-300}
- NGINX_PROXY_READ_TIMEOUT=${NGINX_PROXY_READ_TIMEOUT:-300}
labels:
- traefik.enable=true
# Chat service
- traefik.http.routers.onyx-router.rule=Host(`${FQDN}`)
- traefik.http.routers.onyx-router.service=onyx-service
- traefik.http.routers.onyx-router.entrypoints=web,websecure
- traefik.http.services.onyx-service.loadbalancer.server.port=80
expose:
- 3000
networks:
- onyx-network
- web
# Local access at http://localhost:3000 out of the box. The Traefik labels
# above still apply in production; set HOST_PORT in .env to change the port.
ports:
- "${HOST_PORT:-3000}:80"
volumes:
# Mount templates read-only; the startup command copies them into
# the writable /etc/nginx/conf.d/ inside the container. This avoids
# "Permission denied" errors on Windows Docker bind mounts.
- ./data/nginx:/nginx-templates:ro
logging:
driver: json-file
options:
max-size: 50m
max-file: "6"
# The specified script waits for the api_server to start up.
# Without this we've seen issues where nginx shows no error logs but
# does not receive any traffic
# PRODUCTION: Change to app.conf.template.prod for production nginx config
command: >
/bin/sh -c "rm -f /etc/nginx/conf.d/default.conf && cp -a
/nginx-templates/. /etc/nginx/conf.d/ && sed 's/\r$//'
/etc/nginx/conf.d/run-nginx.sh > /tmp/run-nginx.sh && chmod +x
/tmp/run-nginx.sh && /tmp/run-nginx.sh app.conf.template"
healthcheck:
test:
- CMD
- wget
- --quiet
- --tries=1
- --spider
- http://127.0.0.1/nginx-health
interval: 30s
timeout: 10s
retries: 5
start_period: 30s
cache:
image: ${BASE_IMAGE_REGISTRY:-docker.io}/library/redis:7.4-alpine
restart: unless-stopped
command: redis-server --save "" --appendonly no
networks:
- onyx-network
env_file:
- path: .env
required: false
# Use tmpfs to prevent creation of anonymous volumes for /data
tmpfs:
- /data
code-interpreter:
image: onyxdotapp/code-interpreter:${CODE_INTERPRETER_IMAGE_TAG:-latest}
command:
- bash
- ./entrypoint.sh
- code-interpreter-api
restart: unless-stopped
networks:
- onyx-network
env_file:
- path: .env
required: false
# Below is needed for the `docker-out-of-docker` execution mode
# For Linux rootless Docker, set DOCKER_SOCK_PATH=${XDG_RUNTIME_DIR}/docker.sock
user: root
volumes:
- ${DOCKER_SOCK_PATH:-/var/run/docker.sock}:/var/run/docker.sock
logging:
driver: json-file
options:
max-size: 50m
max-file: "6"
healthcheck:
test:
- CMD
- python
- -c
- "import urllib.request; urllib.request.urlopen('http://localhost:8000/health')"
interval: 30s
timeout: 10s
retries: 3
start_period: 60s
volumes:
# Persistent data for OpenSearch.
opensearch-data: null
# Persistent data for the MinIO (S3) file store.
#minio_data: null
networks:
onyx-network:
driver: bridge
web:
name: web
external: true
attachable: true