-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-entrypoint.sh
More file actions
97 lines (88 loc) · 3.05 KB
/
Copy pathdocker-entrypoint.sh
File metadata and controls
97 lines (88 loc) · 3.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/bin/bash
# AI Director Workbench - 容器启动脚本
#
# 功能:
# 1. 首次启动自动初始化数据库(建表 + 种子数据)
# 2. 根据 SERVICE_ROLE 环境变量启动对应服务:
# - web : FastAPI (uvicorn)
# - worker : Celery worker
# - beat : Celery beat(单实例!)
# - flower : Flower 监控面板
set -e
echo "========================================="
echo " AI Director Workbench 启动中..."
echo " 角色: ${SERVICE_ROLE:-web}"
echo " 时间: $(date '+%Y-%m-%d %H:%M:%S')"
echo "========================================="
# ===== 1. 数据库初始化(仅 web 角色执行一次)=====
if [ "$SERVICE_ROLE" = "web" ] || [ -z "$SERVICE_ROLE" ]; then
DB_PATH="/data/ai_director.db"
DB_SIZE=$(stat -c%s "$DB_PATH" 2>/dev/null || echo 0)
if [ ! -f "$DB_PATH" ] || [ "$DB_SIZE" -eq 0 ]; then
echo "[init] 检测到首次启动(DB不存在或为空),正在初始化数据库..."
mkdir -p /data/images /data/logs /data/avatars
python -c "
from app.database import init_db
import asyncio
asyncio.run(init_db())
print('[init] 数据库初始化完成')
"
echo "[init] ✅ 数据库和表已创建"
# 自动导入种子数据(智能体/世界观/起首语),受 AUTO_IMPORT_SEED 控制
if [ "${AUTO_IMPORT_SEED:-true}" = "true" ]; then
echo "[init] 开始导入种子数据..."
python -m scripts.import_seed || echo "[init] ⚠️ 种子数据导入失败(不影响启动)"
fi
# 创建默认管理员提示
echo "[init] ️ 请通过浏览器访问本服务,在 /admin 页面创建管理员账号"
else
echo "[init] 数据库已存在(${DB_SIZE} bytes),跳过初始化"
fi
fi
# ===== 2. 根据角色启动对应服务 =====
case "${SERVICE_ROLE:-web}" in
web)
echo "[web] 启动 FastAPI 服务 (uvicorn)..."
exec uvicorn \
"app.main:app" \
--host "0.0.0.0" \
--port 8000 \
--log-level info \
--workers 1
;;
worker)
echo "[worker] 启动 Celery Worker..."
exec celery \
-A app.celery_app.celery_app \
worker \
--loglevel=info \
-Q image,cleanup \
-P solo \
-c 2
;;
beat)
echo "[beat] 启动 Celery Beat (定时任务调度)..."
exec celery \
-A app.celery_app.celery_app \
beat \
--loglevel=info
;;
flower)
echo "[flower] 启动 Flower 监控面板..."
# 如果设置了 FLOWER_BASIC_AUTH 则启用认证
AUTH_ARGS=""
if [ -n "$FLOWER_BASIC_AUTH" ]; then
AUTH_ARGS="--basic_auth=$FLOWER_BASIC_AUTH"
fi
exec celery \
-A app.celery_app.celery_app \
flower \
--port=5555 \
$AUTH_ARGS
;;
*)
echo "[ERROR] 未知的 SERVICE_ROLE: $SERVICE_ROLE"
echo "可用值: web, worker, beat, flower"
exit 1
;;
esac