feat: add build.sh for dynamic docker image building and update deploy scripts
parent
f904d97a3d
commit
725acd57c1
|
|
@ -1,9 +1,9 @@
|
|||
# Public exposed port (only nginx is exposed)
|
||||
NGINX_PORT=8080
|
||||
NGINX_PORT=8082
|
||||
|
||||
# Project data is always mounted from the repository root `./data`.
|
||||
# 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
|
||||
BACKEND_IMAGE_TAG=latest
|
||||
|
|
@ -22,12 +22,23 @@ PIP_TRUSTED_HOST=pypi.tuna.tsinghua.edu.cn
|
|||
# Frontend package registry mirror (used by yarn, recommended in CN)
|
||||
NPM_REGISTRY=https://registry.npmmirror.com
|
||||
|
||||
<<<<<<< HEAD
|
||||
# Database for deploy-prod.sh
|
||||
# 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 (choose one: SQLite / PostgreSQL / MySQL)
|
||||
# SQLite example:
|
||||
# DATABASE_URL=sqlite:////app/data/nanobot_dashboard.db
|
||||
# PostgreSQL example:
|
||||
# DATABASE_URL=postgresql+psycopg://user:password@127.0.0.1:5432/nanobot_dashboard
|
||||
# MySQL example:
|
||||
# DATABASE_URL=mysql+pymysql://user:password@127.0.0.1:3306/nanobot_dashboard
|
||||
DATABASE_URL=postgresql+psycopg://postgres:postgres@10.100.52.43:5433/nanobot
|
||||
>>>>>>> 658bedf (feat: add build.sh for dynamic docker image building and update deploy scripts)
|
||||
DATABASE_POOL_SIZE=20
|
||||
DATABASE_MAX_OVERFLOW=40
|
||||
DATABASE_POOL_TIMEOUT=30
|
||||
|
|
@ -35,7 +46,8 @@ DATABASE_POOL_RECYCLE=1800
|
|||
|
||||
# Redis cache (optional)
|
||||
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_DEFAULT_TTL=60
|
||||
|
||||
|
|
|
|||
|
|
@ -68,3 +68,4 @@ npm-debug.log*
|
|||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
pnpm-debug.log*
|
||||
bot-images/nanobot-base-*
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -12,7 +12,7 @@ services:
|
|||
restart: unless-stopped
|
||||
environment:
|
||||
APP_HOST: 0.0.0.0
|
||||
APP_PORT: 8000
|
||||
APP_PORT: 8002
|
||||
APP_RELOAD: "false"
|
||||
DATABASE_ECHO: "false"
|
||||
DATABASE_POOL_SIZE: ${DATABASE_POOL_SIZE:-20}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
upstream nanobot_backend {
|
||||
server backend:8000;
|
||||
server backend:8002;
|
||||
}
|
||||
|
||||
server {
|
||||
|
|
|
|||
|
|
@ -81,9 +81,12 @@ load_env_var() {
|
|||
}
|
||||
|
||||
if [[ ! -f "$ENV_FILE" ]]; then
|
||||
echo "Missing env file: $ENV_FILE"
|
||||
echo "Create it from: $ROOT_DIR/.env.prod.example"
|
||||
exit 1
|
||||
echo "[WARNING] Missing env file: $ENV_FILE"
|
||||
echo "[WARNING] Creating it from: $ROOT_DIR/.env.prod.example ..."
|
||||
cp "$ROOT_DIR/.env.prod.example" "$ENV_FILE"
|
||||
echo "[WARNING] 请编辑 $ENV_FILE 文件,配置正确的数据库、Redis、端口等参数"
|
||||
echo "[WARNING] 按任意键继续,或 Ctrl+C 退出..."
|
||||
read -n 1 -s
|
||||
fi
|
||||
|
||||
require_file "$COMPOSE_FILE" ""
|
||||
|
|
|
|||
Loading…
Reference in New Issue