mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-11-28 04:59:52 +01:00
feat:route to api && custom_config
This commit is contained in:
parent
ca82165324
commit
e28546a220
6 changed files with 1352 additions and 9 deletions
80
main/xiaozhi-server/.dockerignore
Normal file
80
main/xiaozhi-server/.dockerignore
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
# Python cache and compiled files
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
*$py.class
|
||||
*.so
|
||||
.Python
|
||||
|
||||
# Virtual environments
|
||||
venv/
|
||||
env/
|
||||
ENV/
|
||||
.venv
|
||||
|
||||
# IDE and editor files
|
||||
.vscode/
|
||||
.idea/
|
||||
*.swp
|
||||
*.swo
|
||||
*~
|
||||
.DS_Store
|
||||
|
||||
# Git
|
||||
.git/
|
||||
.gitignore
|
||||
.gitattributes
|
||||
|
||||
# Documentation
|
||||
*.md
|
||||
docs/
|
||||
|
||||
# Docker files
|
||||
Dockerfile*
|
||||
docker-compose*.yml
|
||||
.dockerignore
|
||||
|
||||
# Test files
|
||||
test/
|
||||
tests/
|
||||
performance_tester/
|
||||
performance_tester.py
|
||||
|
||||
# Data directories (should be mounted as volumes)
|
||||
# Note: data/ directory should be mounted as volume for persistent config
|
||||
# But we exclude some files that shouldn't be in the image
|
||||
data/.config.yaml
|
||||
data/*.log
|
||||
data/tmp/
|
||||
mysql/
|
||||
redis/
|
||||
uploadfile/
|
||||
logs/
|
||||
|
||||
# Temporary files
|
||||
tmp/
|
||||
*.tmp
|
||||
*.log
|
||||
|
||||
# Model files (should be mounted as volumes)
|
||||
models/*/model.pt
|
||||
|
||||
# Music files (optional, can be mounted)
|
||||
music/
|
||||
|
||||
# Backup and old files
|
||||
*.bak
|
||||
*.backup
|
||||
*.old
|
||||
# Note: custom_config.yaml is required in the image as default config
|
||||
# config_from_api.yaml is generated at runtime, exclude it
|
||||
config_from_api.yaml
|
||||
|
||||
# OS generated files
|
||||
.DS_Store
|
||||
.DS_Store?
|
||||
._*
|
||||
.Spotlight-V100
|
||||
.Trashes
|
||||
ehthumbs.db
|
||||
Thumbs.db
|
||||
|
||||
49
main/xiaozhi-server/Dockerfile
Normal file
49
main/xiaozhi-server/Dockerfile
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
# Dockerfile for local development and testing
|
||||
# Build xiaozhi-server image from local source code
|
||||
|
||||
FROM python:3.10-slim
|
||||
|
||||
# Install system dependencies
|
||||
RUN apt-get update && \
|
||||
apt-get install -y --no-install-recommends \
|
||||
libopus0 \
|
||||
ffmpeg \
|
||||
build-essential \
|
||||
git && \
|
||||
apt-get clean && \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Configure pip to use Aliyun mirror for faster downloads in China
|
||||
RUN pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/ && \
|
||||
pip config set global.trusted-host mirrors.aliyun.com && \
|
||||
pip config set global.timeout 120 && \
|
||||
pip config set install.retries 5
|
||||
|
||||
# Set working directory
|
||||
WORKDIR /opt/xiaozhi-esp32-server
|
||||
|
||||
# Copy requirements file
|
||||
COPY requirements.txt .
|
||||
|
||||
# Install Python dependencies
|
||||
RUN pip install --no-cache-dir --upgrade pip setuptools wheel && \
|
||||
pip install --no-cache-dir -r requirements.txt --default-timeout=120 --retries 5
|
||||
|
||||
# Copy application code
|
||||
COPY . .
|
||||
|
||||
# Set timezone
|
||||
ENV TZ=Asia/Shanghai
|
||||
|
||||
# Expose ports
|
||||
# 8000: WebSocket server
|
||||
# 8003: HTTP server for OTA and vision analysis
|
||||
EXPOSE 8000 8003
|
||||
|
||||
# Health check
|
||||
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
|
||||
CMD python -c "import socket; s = socket.socket(socket.AF_INET, socket.SOCK_STREAM); s.settimeout(5); s.connect(('localhost', 8000)); s.close()" || exit 1
|
||||
|
||||
# Start application
|
||||
CMD ["python", "app.py"]
|
||||
|
||||
|
|
@ -24,18 +24,18 @@ def load_config():
|
|||
if cached_config is not None:
|
||||
return cached_config
|
||||
|
||||
default_config_path = get_project_dir() + "config.yaml"
|
||||
custom_config_path = get_project_dir() + "data/.config.yaml"
|
||||
# default_config_path = get_project_dir() + "config.yaml"
|
||||
custom_config_path = get_project_dir() + "custom_config.yaml"
|
||||
|
||||
# 加载默认配置
|
||||
default_config = read_config(default_config_path)
|
||||
# default_config = read_config(default_config_path)
|
||||
custom_config = read_config(custom_config_path)
|
||||
|
||||
if custom_config.get("manager-api", {}).get("url"):
|
||||
config = get_config_from_api(custom_config)
|
||||
else:
|
||||
# 合并配置
|
||||
config = merge_configs(default_config, custom_config)
|
||||
# else:
|
||||
# # 合并配置
|
||||
# config = merge_configs(default_config, custom_config)
|
||||
# 初始化目录
|
||||
ensure_directories(config)
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import os
|
|||
from config.config_loader import read_config, get_project_dir, load_config
|
||||
|
||||
|
||||
default_config_file = "config.yaml"
|
||||
default_config_file = "custom_config.yaml"
|
||||
config_file_valid = False
|
||||
|
||||
|
||||
|
|
@ -13,10 +13,10 @@ def check_config_file():
|
|||
"""
|
||||
简化的配置检查,仅提示用户配置文件的使用情况
|
||||
"""
|
||||
custom_config_file = get_project_dir() + "data/." + default_config_file
|
||||
custom_config_file = get_project_dir() + default_config_file
|
||||
if not os.path.exists(custom_config_file):
|
||||
raise FileNotFoundError(
|
||||
"找不到data/.config.yaml文件,请按教程确认该配置文件是否存在"
|
||||
"找不到custom_config.yaml文件,请按教程确认该配置文件是否存在"
|
||||
)
|
||||
|
||||
# 检查是否从API读取配置
|
||||
|
|
|
|||
1036
main/xiaozhi-server/custom_config.yaml
Normal file
1036
main/xiaozhi-server/custom_config.yaml
Normal file
File diff suppressed because it is too large
Load diff
178
main/xiaozhi-server/docker-compose_local_all.yml
Normal file
178
main/xiaozhi-server/docker-compose_local_all.yml
Normal file
|
|
@ -0,0 +1,178 @@
|
|||
# Docker Compose configuration for local development
|
||||
# This file uses locally built images instead of pulling from remote registry
|
||||
|
||||
services:
|
||||
# ============================================================================
|
||||
# xiaozhi-server (Python WebSocket Server)
|
||||
# ============================================================================
|
||||
xiaozhi-esp32-server:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
image: xiaozhi-esp32-server:local
|
||||
container_name: xiaozhi-esp32-server
|
||||
depends_on:
|
||||
xiaozhi-esp32-server-db:
|
||||
condition: service_healthy
|
||||
xiaozhi-esp32-server-redis:
|
||||
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
|
||||
volumes:
|
||||
# Configuration directory
|
||||
- ./data:/opt/xiaozhi-esp32-server/data
|
||||
# Custom config (optional override, uncomment if you need to customize)
|
||||
- ./custom_config.yaml:/opt/xiaozhi-esp32-server/custom_config.yaml
|
||||
# Model files (important!)
|
||||
- ./models/SenseVoiceSmall:/opt/xiaozhi-esp32-server/models/SenseVoiceSmall
|
||||
- ./models/snakers4_silero-vad:/opt/xiaozhi-esp32-server/models/snakers4_silero-vad
|
||||
# Temporary files
|
||||
- ./tmp:/opt/xiaozhi-esp32-server/tmp
|
||||
# Music files (optional)
|
||||
- ./music:/opt/xiaozhi-esp32-server/music
|
||||
# Logs (optional, for debugging)
|
||||
- ./logs:/opt/xiaozhi-esp32-server/logs
|
||||
|
||||
# ============================================================================
|
||||
# manager-web (Management Console + API)
|
||||
# ============================================================================
|
||||
xiaozhi-esp32-server-web:
|
||||
# Build from local source (supports ARM64/Apple Silicon)
|
||||
build:
|
||||
context: ../../
|
||||
dockerfile: Dockerfile-web
|
||||
image: xiaozhi-esp32-server-web:local
|
||||
|
||||
# Option: Use pre-built image from registry (x86 only)
|
||||
# image: ghcr.nju.edu.cn/xinnan-tech/xiaozhi-esp32-server:web_latest
|
||||
# platform: linux/amd64 # Uncomment to force x86 emulation on ARM64
|
||||
|
||||
container_name: xiaozhi-esp32-server-web
|
||||
restart: unless-stopped
|
||||
networks:
|
||||
- xiaozhi-network
|
||||
depends_on:
|
||||
xiaozhi-esp32-server-db:
|
||||
condition: service_healthy
|
||||
xiaozhi-esp32-server-redis:
|
||||
condition: service_healthy
|
||||
ports:
|
||||
# Management console and API
|
||||
- "8002:8002"
|
||||
environment:
|
||||
- TZ=Asia/Shanghai
|
||||
- SPRING_PROFILES_ACTIVE=dev
|
||||
# Database connection
|
||||
- SPRING_DATASOURCE_DRUID_URL=jdbc:mysql://xiaozhi-esp32-server-db:3306/xiaozhi_esp32_server?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true&connectTimeout=30000&socketTimeout=30000&autoReconnect=true&failOverReadOnly=false&maxReconnects=10
|
||||
- SPRING_DATASOURCE_DRUID_USERNAME=root
|
||||
- SPRING_DATASOURCE_DRUID_PASSWORD=123456
|
||||
# Redis connection
|
||||
- SPRING_DATA_REDIS_HOST=xiaozhi-esp32-server-redis
|
||||
- SPRING_DATA_REDIS_PORT=6379
|
||||
- SPRING_DATA_REDIS_PASSWORD=
|
||||
volumes:
|
||||
# Upload files directory
|
||||
- ./uploadfile:/uploadfile
|
||||
logging:
|
||||
driver: "json-file"
|
||||
options:
|
||||
max-size: "10m"
|
||||
max-file: "3"
|
||||
|
||||
# ============================================================================
|
||||
# MySQL Database
|
||||
# ============================================================================
|
||||
xiaozhi-esp32-server-db:
|
||||
image: mysql:8.0
|
||||
container_name: xiaozhi-esp32-server-db
|
||||
restart: unless-stopped
|
||||
networks:
|
||||
- xiaozhi-network
|
||||
ports:
|
||||
# Expose MySQL port for local debugging (optional)
|
||||
- "3307:3306"
|
||||
volumes:
|
||||
# Persistent database storage
|
||||
- ./mysql/data:/var/lib/mysql
|
||||
# MySQL configuration (optional)
|
||||
# - ./mysql/conf:/etc/mysql/conf.d
|
||||
environment:
|
||||
- TZ=Asia/Shanghai
|
||||
- MYSQL_ROOT_PASSWORD=123456
|
||||
- MYSQL_DATABASE=xiaozhi_esp32_server
|
||||
- MYSQL_INITDB_ARGS=--character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
|
||||
command:
|
||||
- --character-set-server=utf8mb4
|
||||
- --collation-server=utf8mb4_unicode_ci
|
||||
- --default-authentication-plugin=mysql_native_password
|
||||
- --max_connections=1000
|
||||
- --max_allowed_packet=256M
|
||||
logging:
|
||||
driver: "json-file"
|
||||
options:
|
||||
max-size: "10m"
|
||||
max-file: "3"
|
||||
healthcheck:
|
||||
test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "root", "-p123456"]
|
||||
timeout: 45s
|
||||
interval: 10s
|
||||
retries: 10
|
||||
start_period: 60s
|
||||
|
||||
# ============================================================================
|
||||
# Redis Cache
|
||||
# ============================================================================
|
||||
xiaozhi-esp32-server-redis:
|
||||
image: redis:7-alpine
|
||||
container_name: xiaozhi-esp32-server-redis
|
||||
restart: unless-stopped
|
||||
networks:
|
||||
- xiaozhi-network
|
||||
ports:
|
||||
# Expose Redis port for local debugging (optional)
|
||||
- "6380:6379"
|
||||
volumes:
|
||||
# Persistent Redis data (optional)
|
||||
- ./redis/data:/data
|
||||
environment:
|
||||
- TZ=Asia/Shanghai
|
||||
command: redis-server --appendonly yes --maxmemory 512mb --maxmemory-policy allkeys-lru
|
||||
logging:
|
||||
driver: "json-file"
|
||||
options:
|
||||
max-size: "5m"
|
||||
max-file: "3"
|
||||
healthcheck:
|
||||
test: ["CMD", "redis-cli", "ping"]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 3
|
||||
start_period: 10s
|
||||
|
||||
# ============================================================================
|
||||
# Networks
|
||||
# ============================================================================
|
||||
networks:
|
||||
xiaozhi-network:
|
||||
driver: bridge
|
||||
name: xiaozhi-local-network
|
||||
|
||||
# ============================================================================
|
||||
# Volumes (optional - for named volumes instead of bind mounts)
|
||||
# ============================================================================
|
||||
# volumes:
|
||||
# mysql-data:
|
||||
# redis-data:
|
||||
|
||||
Loading…
Reference in a new issue