add_files

This commit is contained in:
HuYingTran 2025-11-03 17:26:02 +07:00
parent 53ee24f828
commit 1799cfac98
4 changed files with 253 additions and 1 deletions

6
Dockerfile-server-arm Normal file
View file

@ -0,0 +1,6 @@
FROM xiaozhi-esp32-server:server-base
WORKDIR /opt/xiaozhi-esp32-server
COPY main/xiaozhi-server .
CMD ["python", "app.py"]

150
docker-setup-arm.sh Normal file
View file

@ -0,0 +1,150 @@
#!/bin/sh
# Author: Huynh (Modified for ARM64)
# This script supports ARM64
# Interrupt handler function
handle_interrupt() {
echo ""
echo "Installation interrupted by user (Ctrl+C or Esc)"
echo "To reinstall, please run the script again"
exit 1
}
# Setup signal trap for Ctrl+C
trap handle_interrupt SIGINT
# Save terminal settings and configure for immediate key reading
old_stty_settings=$(stty -g)
stty -icanon -echo min 1 time 0
# Background process to detect ESC key to interrupt the script
(while true; do
read -r key
if [[ $key == $'\e' ]]; then
kill -SIGINT $$
break
fi
done) &
# Restore terminal settings on script exit
trap 'stty "$old_stty_settings"' EXIT
# Print banner in green
echo -e "\e[1;32m"
cat << "EOF"
Author: Huynh (ARM64 version)
_ ____ __ __
/ \ | _ \| \/ |
/ _ \ | |_) | |\/| |
/ ___ \| _ <| | | |
/_/ \_\_| \_\_| |_|
EOF
echo -e "\e[0m"
echo -e "\e[1;36m One-click installer for XiaoZhi Server on ARM64 \e[0m\n"
sleep 1
# Check root permission
if [ $EUID -ne 0 ]; then
echo "Please run this script as root"
exit 1
fi
# Check OS version
if [ -f /etc/os-release ]; then
. /etc/os-release
if [ "$ID" != "debian" ] && [ "$ID" != "ubuntu" ]; then
echo "This script only supports Debian/Ubuntu systems"
exit 1
fi
else
echo "Cannot determine OS version, only Debian/Ubuntu supported"
exit 1
fi
# Install whiptail if not installed
if ! command -v whiptail &>/dev/null; then
echo "Installing whiptail..."
apt update
apt install -y whiptail
fi
# Install curl if not installed
if ! command -v curl &>/dev/null; then
echo "Installing curl..."
apt update
apt install -y curl
fi
# Install Docker if not installed
if ! command -v docker &>/dev/null; then
echo "Installing Docker..."
DISTRO=$(lsb_release -cs)
MIRROR_URL="https://mirrors.aliyun.com/docker-ce/linux/ubuntu"
GPG_URL="https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg"
apt update
apt install -y apt-transport-https ca-certificates curl software-properties-common gnupg
mkdir -p /etc/apt/keyrings
curl -fsSL "$GPG_URL" | gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] $MIRROR_URL $DISTRO stable" > /etc/apt/sources.list.d/docker.list
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 7EA0A9C3F273FCD8 2>/dev/null || echo "Warning: some keys failed to add"
apt update
apt install -y docker-ce docker-ce-cli containerd.io
systemctl start docker
systemctl enable docker
docker --version || { echo "Docker installation failed"; exit 1; }
else
echo "Docker is already installed"
fi
# Create necessary directories
mkdir -p /opt/xiaozhi-server/data
mkdir -p /opt/xiaozhi-server/models/SenseVoiceSmall
# Download voice recognition model
MODEL_PATH="/opt/xiaozhi-server/models/SenseVoiceSmall/model.pt"
if [ ! -f "$MODEL_PATH" ]; then
echo "Downloading voice recognition model..."
curl -fL --progress-bar https://modelscope.cn/models/iic/SenseVoiceSmall/resolve/master/model.pt -o "$MODEL_PATH" || { echo "Failed to download model"; exit 1; }
else
echo "Model already exists, skipping download"
fi
# Download docker-compose_arm.yml
COMPOSE_FILE="/opt/xiaozhi-server/docker-compose_arm.yml"
COMPOSE_URL="https://raw.githubusercontent.com/HuYingTran/xiaozhi-esp32-server/main/xiaozhi-server/docker-compose_arm.yml"
if [ ! -f "$COMPOSE_FILE" ]; then
echo "Downloading docker-compose_arm.yml..."
curl -fL --progress-bar "$COMPOSE_URL" -o "$COMPOSE_FILE" || { echo "Failed to download docker-compose_arm.yml"; exit 1; }
else
echo "docker-compose_arm.yml already exists, skipping download"
fi
# --- Download additional Dockerfiles ---
DOCKERFILES_DIR="/opt/xiaozhi-server"
BASE_URL="https://raw.githubusercontent.com/HuYingTran/xiaozhi-esp32-server/main/xiaozhi-server"
for FILE in Dockerfile-server-base Dockerfile-server-arm Dockerfile-web; do
TARGET_PATH="$DOCKERFILES_DIR/$FILE"
FILE_URL="$BASE_URL/$FILE"
if [ ! -f "$TARGET_PATH" ]; then
echo "Downloading $FILE..."
curl -fL --progress-bar "$FILE_URL" -o "$TARGET_PATH" || { echo "Failed to download $FILE"; exit 1; }
else
echo "$FILE already exists, skipping download"
fi
done
# ---------------------------------------
# Change directory and build Docker images locally
cd /opt/xiaozhi-server || exit 1
echo "Building Docker images, this may take 10-30 minutes, please wait..."
docker compose -f docker-compose_arm.yml build || { echo "Docker image build failed"; exit 1; }
# Start Docker containers
docker compose -f docker-compose_arm.yml up -d || { echo "Failed to start Docker containers"; exit 1; }
# Show final info
LOCAL_IP=$(hostname -I | awk '{print $1}')
whiptail --title "Installation Complete" --msgbox "Server installation complete! Access addresses:\n\nAdmin Panel: http://$LOCAL_IP:8002\nOTA URL: http://$LOCAL_IP:8002/xiaozhi/ota/\nVision Analysis API: http://$LOCAL_IP:8003/mcp/vision/explain\nWebSocket: ws://$LOCAL_IP:8000/xiaozhi/v1/\n\nThank you for using!" 16 70

View file

@ -410,4 +410,4 @@ whiptail --title "安装完成!" --msgbox "\
OTA 地址: http://$LOCAL_IP:8002/xiaozhi/ota/\n\ OTA 地址: http://$LOCAL_IP:8002/xiaozhi/ota/\n\
视觉分析接口地址: http://$LOCAL_IP:8003/mcp/vision/explain\n\ 视觉分析接口地址: http://$LOCAL_IP:8003/mcp/vision/explain\n\
WebSocket 地址: ws://$LOCAL_IP:8000/xiaozhi/v1/\n\ WebSocket 地址: ws://$LOCAL_IP:8000/xiaozhi/v1/\n\
\n安装完毕!感谢您的使用!\n按Enter键退出..." 16 70 \n安装完毕!感谢您的使用!\n按Enter键退出..." 16 70

View file

@ -0,0 +1,96 @@
# Docker安装全模块
version: '3'
services:
# Server模块
xiaozhi-esp32-server:
build:
context: .
dockerfile: Dockerfile-server
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: