Merge remote-tracking branch 'origin/main'

main
mula.liu 2026-04-13 20:10:24 +08:00
commit a774c398e8
6 changed files with 111 additions and 16 deletions

View File

@ -1,9 +1,9 @@
# Public exposed port (only nginx is exposed) # Public exposed port (only nginx is exposed)
NGINX_PORT=8080 NGINX_PORT=8082
# Project data is always mounted from the repository root `./data`. # Project data is always mounted from the repository root `./data`.
# Only workspace root still needs an absolute host path. # Only workspace root still needs an absolute host path.
HOST_BOTS_WORKSPACE_ROOT=/opt/dashboard-nanobot/workspace/bots HOST_BOTS_WORKSPACE_ROOT=/dep/dashboard-nanobot/workspace/bots
# Optional custom image tags # Optional custom image tags
BACKEND_IMAGE_TAG=latest BACKEND_IMAGE_TAG=latest
@ -22,12 +22,7 @@ PIP_TRUSTED_HOST=pypi.tuna.tsinghua.edu.cn
# Frontend package registry mirror (used by yarn, recommended in CN) # Frontend package registry mirror (used by yarn, recommended in CN)
NPM_REGISTRY=https://registry.npmmirror.com NPM_REGISTRY=https://registry.npmmirror.com
# Database for deploy-prod.sh DATABASE_URL=postgresql+psycopg://postgres:postgres@10.100.52.43:5433/nanobot
# This mode now supports external PostgreSQL only.
# Before running deploy-prod.sh, initialize the target database explicitly with:
# scripts/sql/create-tables.sql
# scripts/sql/init-data.sql
DATABASE_URL=postgresql+psycopg://postgres:change_me@127.0.0.1:5432/dashboard
DATABASE_POOL_SIZE=20 DATABASE_POOL_SIZE=20
DATABASE_MAX_OVERFLOW=40 DATABASE_MAX_OVERFLOW=40
DATABASE_POOL_TIMEOUT=30 DATABASE_POOL_TIMEOUT=30
@ -37,7 +32,8 @@ DATABASE_POOL_RECYCLE=1800
# REDIS_URL must be reachable from the backend container. # REDIS_URL must be reachable from the backend container.
# In docker-compose.prod.yml, 127.0.0.1 points to the backend container itself, not the host machine. # In docker-compose.prod.yml, 127.0.0.1 points to the backend container itself, not the host machine.
REDIS_ENABLED=true REDIS_ENABLED=true
REDIS_URL=redis://127.0.0.1:6379/8 REDIS_URL=redis://10.100.52.43:6380/8
REDIS_PASSWORD=Unis@123
REDIS_PREFIX=nanobot REDIS_PREFIX=nanobot
REDIS_DEFAULT_TTL=60 REDIS_DEFAULT_TTL=60

1
.gitignore vendored
View File

@ -68,3 +68,4 @@ npm-debug.log*
yarn-debug.log* yarn-debug.log*
yarn-error.log* yarn-error.log*
pnpm-debug.log* pnpm-debug.log*
bot-images/nanobot-base-*

View File

@ -0,0 +1,95 @@
#!/bin/bash
set -e
BASE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# 执行拷贝和打包的核心函数
build_image() {
local dir_name=$1
local version=$2
local image_name="nanobot-base:${version}"
echo "=================================================="
echo "准备构建镜像: ${image_name}"
echo "=================================================="
# 1. 拷贝 Dashboard.Dockerfile
echo ">> [1/3] 拷贝 Dashboard.Dockerfile 到根目录 ..."
cp "${BASE_DIR}/Dashboard.Dockerfile" "${BASE_DIR}/${dir_name}/"
# 2. 拷贝 dashboard.py
echo ">> [2/3] 拷贝 dashboard.py 到 channels 目录 ..."
if [ -d "${BASE_DIR}/${dir_name}/nanobot/channels" ]; then
cp "${BASE_DIR}/dashboard.py" "${BASE_DIR}/${dir_name}/nanobot/channels/"
elif [ -d "${BASE_DIR}/${dir_name}/channels" ]; then
cp "${BASE_DIR}/dashboard.py" "${BASE_DIR}/${dir_name}/channels/"
else
# 兜底创建 nanobot/channels/
mkdir -p "${BASE_DIR}/${dir_name}/nanobot/channels/"
cp "${BASE_DIR}/dashboard.py" "${BASE_DIR}/${dir_name}/nanobot/channels/"
fi
# 3. 执行 Docker build
echo ">> [3/3] 开始打包 Docker 镜像: ${image_name} ..."
cd "${BASE_DIR}/${dir_name}"
docker build -f Dashboard.Dockerfile -t "${image_name}" .
echo "=================================================="
echo "✅ 构建完成: ${image_name}"
echo "=================================================="
}
echo "请选择操作模式:"
echo "1) 从 Git 拉取最新代码并打包 (会覆盖已有同名目录)"
echo "2) 扫描本地已有的目录并打包"
read -p "输入选项 [1/2]: " mode
if [ "$mode" = "1" ]; then
echo "正在从 https://github.com/HKUDS/nanobot.git 获取最新版本号..."
LATEST_TAG=$(git ls-remote --tags https://github.com/HKUDS/nanobot.git | awk -F/ '{print $3}' | grep -v '\^{}$' | sort -V | tail -n1)
if [ -z "$LATEST_TAG" ]; then
echo "获取远程版本号失败,请检查网络或仓库地址。"
exit 1
fi
VERSION="${LATEST_TAG}"
DIR_NAME="nanobot-base-${VERSION}"
if [ -d "${BASE_DIR}/${DIR_NAME}" ]; then
echo ">> 清理已有的目录 ${DIR_NAME} ..."
rm -rf "${BASE_DIR}/${DIR_NAME}"
fi
echo ">> 正在克隆 nanobot (版本: ${VERSION}) ..."
git clone -b "${VERSION}" https://github.com/HKUDS/nanobot.git "${BASE_DIR}/${DIR_NAME}"
build_image "${DIR_NAME}" "${VERSION}"
elif [ "$mode" = "2" ]; then
echo "正在扫描本地目录..."
# 查找 nanobot-base-* 格式的目录
dirs=($(find "${BASE_DIR}" -maxdepth 1 -type d -name "nanobot-base-*" | awk -F/ '{print $NF}'))
if [ ${#dirs[@]} -eq 0 ]; then
echo "未找到任何本地克隆的目录 (格式: nanobot-base-*)。"
exit 1
fi
echo "找到以下本地目录,请选择要打包的目录:"
select DIR_NAME in "${dirs[@]}"; do
if [ -n "$DIR_NAME" ]; then
echo "您选择了: $DIR_NAME"
# 提取版本号,例如从 nanobot-base-v0.1.5 提取 v0.1.5
VERSION=${DIR_NAME#nanobot-base-}
build_image "${DIR_NAME}" "${VERSION}"
break
else
echo "无效的选项,请重新选择。"
fi
done
else
echo "无效的选项,退出。"
exit 1
fi

View File

@ -12,7 +12,7 @@ services:
restart: unless-stopped restart: unless-stopped
environment: environment:
APP_HOST: 0.0.0.0 APP_HOST: 0.0.0.0
APP_PORT: 8000 APP_PORT: 8002
APP_RELOAD: "false" APP_RELOAD: "false"
DATABASE_ECHO: "false" DATABASE_ECHO: "false"
DATABASE_POOL_SIZE: ${DATABASE_POOL_SIZE:-20} DATABASE_POOL_SIZE: ${DATABASE_POOL_SIZE:-20}
@ -44,9 +44,9 @@ services:
- ./data:/app/data - ./data:/app/data
- ${HOST_BOTS_WORKSPACE_ROOT}:${HOST_BOTS_WORKSPACE_ROOT} - ${HOST_BOTS_WORKSPACE_ROOT}:${HOST_BOTS_WORKSPACE_ROOT}
expose: expose:
- "8000" - "8002"
healthcheck: healthcheck:
test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8000/api/health', timeout=3).read()"] test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8002/api/health', timeout=3).read()"]
interval: 15s interval: 15s
timeout: 5s timeout: 5s
retries: 5 retries: 5

View File

@ -1,5 +1,5 @@
upstream nanobot_backend { upstream nanobot_backend {
server backend:8000; server backend:8002;
} }
server { server {

View File

@ -81,9 +81,12 @@ load_env_var() {
} }
if [[ ! -f "$ENV_FILE" ]]; then if [[ ! -f "$ENV_FILE" ]]; then
echo "Missing env file: $ENV_FILE" echo "[WARNING] Missing env file: $ENV_FILE"
echo "Create it from: $ROOT_DIR/.env.prod.example" echo "[WARNING] Creating it from: $ROOT_DIR/.env.prod.example ..."
exit 1 cp "$ROOT_DIR/.env.prod.example" "$ENV_FILE"
echo "[WARNING] 请编辑 $ENV_FILE 文件配置正确的数据库、Redis、端口等参数"
echo "[WARNING] 按任意键继续,或 Ctrl+C 退出..."
read -n 1 -s
fi fi
require_file "$COMPOSE_FILE" "" require_file "$COMPOSE_FILE" ""