xiaozhi-esp32-server/main/docker-compose_dokploy.yml
2025-12-19 10:51:59 +08:00

153 lines
5.4 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

services:
# ============================================================================
# xiaozhi-server (Python WebSocket Server)
# ============================================================================
xiaozhi-esp32-server:
build:
context: ./xiaozhi-server/
dockerfile: Dockerfile
image: xiaozhi-esp32-server:local
container_name: xiaozhi-esp32-server
env_file:
- .env
depends_on:
live-agent-api:
condition: service_healthy
restart: unless-stopped
networks:
- xiaozhi-network
ports:
# WebSocket server
- "8000:8000"
# HTTP server for vision analysis and OTA
- "8003:8003"
security_opt:
- seccomp:unconfined
environment:
- TZ=Asia/Shanghai
- PYTHONUNBUFFERED=1
- LOG_LEVEL=INFO
- REGION=LOCAL
healthcheck:
disable: true
# 容器启动时自动获取公网 IP 并设置环境变量(使用 Python,无需 curl)
command:
- sh
- -c
- |
get_public_ip() {
python3 -c "
import urllib.request
def get_ip():
for url, timeout in [('http://169.254.169.254/latest/meta-data/public-ipv4',2),('https://ifconfig.me',3),('https://api.ipify.org',3)]:
try:
req = urllib.request.Request(url, headers={'User-Agent': 'curl/7.68.0'})
with urllib.request.urlopen(req, timeout=timeout) as r:
ip = r.read().decode().strip()
if ip: return ip
except: pass
return 'localhost'
print(get_ip())
"
}
export PUBLIC_IP=$$(get_public_ip)
export WEBSOCKET_URL="ws://$${PUBLIC_IP}:8000/xiaozhi/v1/"
export OTA_URL="http://$${PUBLIC_IP}:8003/xiaozhi/ota/"
echo ">>> Detected PUBLIC_IP: $${PUBLIC_IP}"
echo ">>> WEBSOCKET_URL: $${WEBSOCKET_URL}"
echo ">>> OTA_URL: $${OTA_URL}"
exec python app.py
volumes:
# Configuration directory
- /home/ubuntu/live-agent/main/xiaozhi-server/data:/opt/xiaozhi-esp32-server/data
# Custom config (optional override, uncomment if you need to customize)
- /home/ubuntu/live-agent/main/xiaozhi-server/custom_config.yaml:/opt/xiaozhi-esp32-server/custom_config.yaml
# Model files (important!)
- /home/ubuntu/live-agent/main/xiaozhi-server/models/SenseVoiceSmall:/opt/xiaozhi-esp32-server/models/SenseVoiceSmall
- /home/ubuntu/live-agent/main/xiaozhi-server/models/snakers4_silero-vad:/opt/xiaozhi-esp32-server/models/snakers4_silero-vad
# Temporary files
- /home/ubuntu/live-agent/main/xiaozhi-server/tmp:/opt/xiaozhi-esp32-server/tmp
# Music files (optional)
- /home/ubuntu/live-agent/main/xiaozhi-server/music:/opt/xiaozhi-esp32-server/music
# Logs (optional, for debugging)
- /home/ubuntu/live-agent/main/xiaozhi-server/logs:/opt/xiaozhi-esp32-server/logs
# ============================================================================
# live-agent-api Dependencies: Postgres + Minio
# ============================================================================
live-agent-postgres:
image: postgres:16-alpine
container_name: live-agent-postgres
environment:
POSTGRES_DB: live_agent
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
ports:
- "5432:5432"
volumes:
- /home/ubuntu/live-agent/main/live-agent-api/data/postgres:/var/lib/postgresql/data
- /home/ubuntu/live-agent/main/live-agent-api/init_db.sql:/docker-entrypoint-initdb.d/init_db.sql
networks:
- xiaozhi-network
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 5s
timeout: 5s
retries: 5
live-agent-minio:
image: minio/minio:latest
container_name: live-agent-minio
command: server /data --console-address ":9001"
environment:
MINIO_ROOT_USER: minioadmin
MINIO_ROOT_PASSWORD: minioadmin
ports:
- "19000:9000"
- "19001:9001"
volumes:
- /home/ubuntu/live-agent/main/live-agent-api/data/minio:/data
networks:
- xiaozhi-network
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"]
interval: 10s
timeout: 5s
retries: 5
# ============================================================================
# live-agent-api
# ============================================================================
live-agent-api:
build:
context: ./live-agent-api
dockerfile: Dockerfile
container_name: live-agent-api
env_file:
- .env
environment:
DATABASE_URL: postgresql+asyncpg://postgres:postgres@live-agent-postgres:5432/live_agent
S3_ENDPOINT_URL: http://live-agent-minio:9000
DEBUG: "True" # 如果是正式生产,可改成 "False"
ports:
- "8080:8080"
networks:
- xiaozhi-network
depends_on:
live-agent-postgres:
condition: service_healthy
live-agent-minio:
condition: service_healthy
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8080/health"]
interval: 10s
timeout: 5s
retries: 5
# ============================================================================
# Networks
# ============================================================================
networks:
xiaozhi-network:
driver: bridge
name: xiaozhi-network