mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-11-28 04:59:52 +01:00
dev
This commit is contained in:
parent
b37f87d231
commit
ff8b1ccae7
3 changed files with 218 additions and 0 deletions
6
Dockerfile-server-arm
Normal file
6
Dockerfile-server-arm
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
FROM xiaozhi-esp32-server:server-base
|
||||
|
||||
WORKDIR /opt/xiaozhi-esp32-server
|
||||
COPY main/xiaozhi-server .
|
||||
|
||||
CMD ["python", "app.py"]
|
||||
116
docker-setup-arm.sh
Normal file
116
docker-setup-arm.sh
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
#!/bin/bash
|
||||
# Raspberry Pi ARM64 Setup Script for XiaoZhi Server (ESP32 Backend)
|
||||
|
||||
set -e # Exit immediately if any command fails
|
||||
|
||||
# ========== 1. Create required directories ==========
|
||||
BASE_DIR="/main/xiaozhi-server"
|
||||
DATA_DIR="$BASE_DIR/data"
|
||||
MODEL_DIR="$BASE_DIR/models/SenseVoiceSmall"
|
||||
|
||||
echo "📁 Checking and creating directory structure..."
|
||||
[ -d "$DATA_DIR" ] && echo "✅ Data directory exists. Skipping..." || mkdir -p "$DATA_DIR"
|
||||
[ -d "$MODEL_DIR" ] && echo "✅ Model directory exists. Skipping..." || mkdir -p "$MODEL_DIR"
|
||||
|
||||
# ========== 2. Download AI voice model ==========
|
||||
MODEL_URL="https://modelscope.cn/models/iic/SenseVoiceSmall/resolve/master/model.pt"
|
||||
MODEL_PATH="$MODEL_DIR/model.pt"
|
||||
|
||||
if [ ! -f "$MODEL_PATH" ]; then
|
||||
echo "📥 Downloading voice recognition model..."
|
||||
curl -fL --progress-bar "$MODEL_URL" -o "$MODEL_PATH"
|
||||
else
|
||||
echo "✅ Model already downloaded at $MODEL_PATH. Skipping..."
|
||||
fi
|
||||
|
||||
# ========== 3. Install Docker & buildx support ==========
|
||||
if ! command -v docker >/dev/null 2>&1; then
|
||||
echo "🐳 Docker not found. Installing Docker..."
|
||||
curl -fsSL https://get.docker.com | sh
|
||||
sudo usermod -aG docker $USER
|
||||
newgrp docker
|
||||
else
|
||||
echo "✅ Docker already installed. Skipping..."
|
||||
fi
|
||||
|
||||
# Enable buildx (if not already enabled)
|
||||
if ! docker buildx ls >/dev/null 2>&1; then
|
||||
echo "🔧 Enabling Docker buildx..."
|
||||
docker buildx create --use
|
||||
else
|
||||
echo "✅ Buildx already enabled. Skipping..."
|
||||
fi
|
||||
|
||||
# ========== 4. Build Docker Image for ARM64 ==========
|
||||
IMAGE_NAME="xiaozhi-esp32-server:server-base"
|
||||
if ! docker image inspect $IMAGE_NAME >/dev/null 2>&1; then
|
||||
echo "🏗️ Building backend Docker image for ARM64..."
|
||||
docker buildx build --platform linux/arm64 \
|
||||
-t $IMAGE_NAME \
|
||||
-f ./Dockerfile-server-base \
|
||||
.
|
||||
else
|
||||
echo "✅ Image $IMAGE_NAME already exists. Skipping build..."
|
||||
fi
|
||||
|
||||
# ========== 5. Run Docker Compose (ARM64) ==========
|
||||
COMPOSE_FILE="$(pwd)/main/xiaozhi-server/docker-compose_arm.yml"
|
||||
|
||||
if [ -f "$COMPOSE_FILE" ]; then
|
||||
echo "🚀 Starting services with Docker Compose (ARM64)..."
|
||||
docker compose -f "$COMPOSE_FILE" up -d --build
|
||||
else
|
||||
echo "❌ Docker Compose file not found at $COMPOSE_FILE"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# ========== 6. Prompt user for server.secret ==========
|
||||
PUBLIC_IP=$(hostname -I | awk '{print $1}')
|
||||
echo ""
|
||||
echo "🔗 Server management panel addresses:"
|
||||
echo " - Local: http://127.0.0.1:8002/"
|
||||
echo " - Public: http://$PUBLIC_IP:8002/"
|
||||
echo ""
|
||||
echo "Open the above link in your browser and register the first admin account."
|
||||
echo "Then log in → Go to 'Parameter Dictionary' → 'Parameter Management' → Find entry with Code: server.secret"
|
||||
echo "Copy its value and paste it below."
|
||||
echo ""
|
||||
|
||||
read -p "Please enter server.secret (leave blank to skip): " SECRET_KEY
|
||||
|
||||
# ========== 7. Write secret-key into config ==========
|
||||
CONFIG_FILE="$DATA_DIR/.config.yaml"
|
||||
if [ -n "$SECRET_KEY" ]; then
|
||||
echo "🔑 Writing secret key into $CONFIG_FILE ..."
|
||||
python3 - <<EOF
|
||||
import yaml, os
|
||||
config_path = "$CONFIG_FILE"
|
||||
config = {}
|
||||
if os.path.exists(config_path):
|
||||
with open(config_path, "r") as f:
|
||||
config = yaml.safe_load(f) or {}
|
||||
config['manager-api'] = {
|
||||
'url': 'http://xiaozhi-esp32-server-web:8002/xiaozhi',
|
||||
'secret': '$SECRET_KEY'
|
||||
}
|
||||
with open(config_path, "w") as f:
|
||||
yaml.dump(config, f, allow_unicode=True)
|
||||
EOF
|
||||
docker restart xiaozhi-esp32-server
|
||||
echo "✅ Secret key added and container restarted."
|
||||
else
|
||||
echo "⚠️ No secret key provided. Skipping configuration update..."
|
||||
fi
|
||||
|
||||
# ========== 8. Display summary ==========
|
||||
LOCAL_IP=$(hostname -I | awk '{print $1}')
|
||||
|
||||
echo ""
|
||||
echo "✅ Installation completed successfully!"
|
||||
echo "---------------------------------------------"
|
||||
echo "Admin Panel: http://$LOCAL_IP:8002"
|
||||
echo "OTA Endpoint: http://$LOCAL_IP:8002/xiaozhi/ota/"
|
||||
echo "Vision API: http://$LOCAL_IP:8003/mcp/vision/explain"
|
||||
echo "WebSocket: ws://$LOCAL_IP:8000/xiaozhi/v1/"
|
||||
echo "---------------------------------------------"
|
||||
echo "🎉 Setup finished! You can now access the web dashboard."
|
||||
96
main/xiaozhi-server/docker-compose_arm.yml
Normal file
96
main/xiaozhi-server/docker-compose_arm.yml
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
# Docker安装全模块
|
||||
|
||||
version: '3'
|
||||
services:
|
||||
# Server模块
|
||||
xiaozhi-esp32-server:
|
||||
build:
|
||||
context: ../..
|
||||
dockerfile: Dockerfile-server-arm
|
||||
container_name: xiaozhi-esp32-server
|
||||
depends_on:
|
||||
- xiaozhi-esp32-server-db
|
||||
- xiaozhi-esp32-server-redis
|
||||
restart: always
|
||||
networks:
|
||||
- default
|
||||
ports:
|
||||
# ws服务端
|
||||
- "8000:8000"
|
||||
# http服务的端口,用于视觉分析接口
|
||||
- "8003:8003"
|
||||
security_opt:
|
||||
- seccomp:unconfined
|
||||
environment:
|
||||
- TZ=Asia/Shanghai
|
||||
volumes:
|
||||
# 配置文件目录
|
||||
- ./data:/opt/xiaozhi-esp32-server/data
|
||||
# 模型文件挂接,很重要
|
||||
- ./models/SenseVoiceSmall/model.pt:/opt/xiaozhi-esp32-server/models/SenseVoiceSmall/model.pt
|
||||
|
||||
# manager-api和manager-web模块
|
||||
xiaozhi-esp32-server-web:
|
||||
build:
|
||||
context: ../..
|
||||
dockerfile: Dockerfile-web
|
||||
container_name: xiaozhi-esp32-server-web
|
||||
restart: always
|
||||
networks:
|
||||
- default
|
||||
depends_on:
|
||||
xiaozhi-esp32-server-db:
|
||||
condition: service_healthy
|
||||
xiaozhi-esp32-server-redis:
|
||||
condition: service_healthy
|
||||
ports:
|
||||
# 智控台
|
||||
- "8002:8002"
|
||||
environment:
|
||||
- TZ=Asia/Shanghai
|
||||
- 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
|
||||
- SPRING_DATA_REDIS_HOST=xiaozhi-esp32-server-redis
|
||||
- SPRING_DATA_REDIS_PASSWORD=
|
||||
- SPRING_DATA_REDIS_PORT=6379
|
||||
volumes:
|
||||
# 配置文件目录
|
||||
- ./uploadfile:/uploadfile
|
||||
# 数据库模块
|
||||
xiaozhi-esp32-server-db:
|
||||
image: mysql:latest
|
||||
container_name: xiaozhi-esp32-server-db
|
||||
healthcheck:
|
||||
test: [ "CMD", "mysqladmin" ,"ping", "-h", "localhost" ]
|
||||
timeout: 45s
|
||||
interval: 10s
|
||||
retries: 10
|
||||
restart: always
|
||||
networks:
|
||||
- default
|
||||
expose:
|
||||
- 3306
|
||||
volumes:
|
||||
- ./mysql/data:/var/lib/mysql
|
||||
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"
|
||||
# redis模块
|
||||
xiaozhi-esp32-server-redis:
|
||||
image: redis
|
||||
expose:
|
||||
- 6379
|
||||
container_name: xiaozhi-esp32-server-redis
|
||||
restart: always
|
||||
healthcheck:
|
||||
test: ["CMD", "redis-cli", "ping"]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 3
|
||||
networks:
|
||||
- default
|
||||
networks:
|
||||
default:
|
||||
Loading…
Reference in a new issue