feat: optimize security and deployment of agent skills

This commit is contained in:
nullkey
2026-02-04 17:11:58 +08:00
committed by lyingbug
parent 3f21345546
commit 43a2c647ea
19 changed files with 1335 additions and 154 deletions
+52 -10
View File
@@ -26,6 +26,7 @@ show_help() {
echo " -p, --app 仅构建应用镜像"
echo " -d, --docreader 仅构建文档读取器镜像"
echo " -f, --frontend 仅构建前端镜像"
echo " -s, --sandbox 仅构建沙箱镜像"
echo " -c, --clean 清理所有本地镜像"
echo " -v, --version 显示版本信息"
exit 0
@@ -198,26 +199,52 @@ build_frontend_image() {
fi
}
# 构建沙箱镜像
build_sandbox_image() {
log_info "构建沙箱镜像 (weknora-sandbox)..."
cd "$PROJECT_ROOT"
docker build \
--platform $PLATFORM \
-f docker/Dockerfile.sandbox \
-t wechatopenai/weknora-sandbox:latest \
.
if [ $? -eq 0 ]; then
log_success "沙箱镜像构建成功"
return 0
else
log_error "沙箱镜像构建失败"
return 1
fi
}
# 构建所有镜像
build_all_images() {
log_info "开始构建所有镜像..."
local app_result=0
local docreader_result=0
local frontend_result=0
local sandbox_result=0
# 构建应用镜像
build_app_image
app_result=$?
# 构建文档读取器镜像
build_docreader_image
docreader_result=$?
# 构建前端镜像
build_frontend_image
frontend_result=$?
# 构建沙箱镜像
build_sandbox_image
sandbox_result=$?
# 显示构建结果
echo ""
log_info "=== 构建结果 ==="
@@ -226,20 +253,26 @@ build_all_images() {
else
log_error "✗ 应用镜像构建失败"
fi
if [ $docreader_result -eq 0 ]; then
log_success "✓ 文档读取器镜像构建成功"
else
log_error "✗ 文档读取器镜像构建失败"
fi
if [ $frontend_result -eq 0 ]; then
log_success "✓ 前端镜像构建成功"
else
log_error "✗ 前端镜像构建失败"
fi
if [ $app_result -eq 0 ] && [ $docreader_result -eq 0 ] && [ $frontend_result -eq 0 ]; then
if [ $sandbox_result -eq 0 ]; then
log_success "✓ 沙箱镜像构建成功"
else
log_error "✗ 沙箱镜像构建失败"
fi
if [ $app_result -eq 0 ] && [ $docreader_result -eq 0 ] && [ $frontend_result -eq 0 ] && [ $sandbox_result -eq 0 ]; then
log_success "所有镜像构建完成!"
return 0
else
@@ -269,6 +302,7 @@ clean_images() {
docker rmi wechatopenai/weknora-app:latest 2>/dev/null || true
docker rmi wechatopenai/weknora-docreader:latest 2>/dev/null || true
docker rmi wechatopenai/weknora-ui:latest 2>/dev/null || true
docker rmi wechatopenai/weknora-sandbox:latest 2>/dev/null || true
docker image prune -f
@@ -281,6 +315,7 @@ BUILD_ALL=false
BUILD_APP=false
BUILD_DOCREADER=false
BUILD_FRONTEND=false
BUILD_SANDBOX=false
CLEAN_IMAGES=false
# 没有参数时默认构建所有镜像
@@ -300,6 +335,8 @@ while [ "$1" != "" ]; do
;;
-f | --frontend ) BUILD_FRONTEND=true
;;
-s | --sandbox ) BUILD_SANDBOX=true
;;
-c | --clean ) CLEAN_IMAGES=true
;;
-v | --version ) show_version
@@ -347,4 +384,9 @@ if [ "$BUILD_FRONTEND" = true ]; then
exit $?
fi
exit 0
if [ "$BUILD_SANDBOX" = true ]; then
build_sandbox_image
exit $?
fi
exit 0
+47 -3
View File
@@ -310,6 +310,32 @@ check_platform() {
log_info "当前平台:$PLATFORM"
}
# 预拉取沙箱镜像(Agent Skills 执行所需,仅拉取不启动)
ensure_sandbox_image() {
local sandbox_image="wechatopenai/weknora-sandbox:${WEKNORA_VERSION:-latest}"
# 检查本地是否已存在沙箱镜像
if docker image inspect "$sandbox_image" &> /dev/null; then
log_success "沙箱镜像已就绪: $sandbox_image"
return 0
fi
log_info "沙箱镜像 ($sandbox_image) 未检测到,正在后台拉取..."
log_info "Agent Skills 功能依赖此镜像,首次执行前需要拉取完成"
# 后台拉取,不阻塞主流程
(
if PLATFORM=$PLATFORM "$DOCKER_COMPOSE_BIN" $DOCKER_COMPOSE_SUBCMD --profile sandbox pull sandbox 2>/dev/null; then
log_success "沙箱镜像拉取完成: $sandbox_image"
else
log_warning "沙箱镜像拉取失败,Agent Skills 功能可能不可用"
log_warning "可稍后手动拉取: $DOCKER_COMPOSE_BIN $DOCKER_COMPOSE_SUBCMD --profile sandbox pull sandbox"
fi
) &
return 0
}
# 启动Docker容器
start_docker() {
log_info "正在启动Docker容器..."
@@ -350,11 +376,14 @@ start_docker() {
fi
log_success "所有Docker容器已成功启动"
# 显示容器状态
log_info "当前容器状态:"
"$DOCKER_COMPOSE_BIN" $DOCKER_COMPOSE_SUBCMD ps
# 预拉取Sandbox镜像(Agent Skills 执行所需,仅拉取不启动)
ensure_sandbox_image
return 0
}
@@ -432,7 +461,12 @@ pull_images() {
log_error "镜像拉取失败"
return 1
fi
# 拉取 sandbox 镜像(sandbox 在 profile 中,需要单独拉取)
log_info "拉取沙箱镜像..."
PLATFORM=$PLATFORM "$DOCKER_COMPOSE_BIN" $DOCKER_COMPOSE_SUBCMD --profile sandbox pull sandbox 2>/dev/null || \
log_warning "沙箱镜像拉取失败(非必需,跳过)"
log_success "所有镜像已成功拉取到最新版本"
# 显示拉取的镜像信息
@@ -531,6 +565,16 @@ check_environment() {
fi
fi
# 检查沙箱镜像
log_info "检查沙箱镜像..."
local sandbox_image="wechatopenai/weknora-sandbox:${WEKNORA_VERSION:-latest}"
if docker image inspect "$sandbox_image" &> /dev/null; then
log_success "沙箱镜像已就绪: $sandbox_image"
else
log_warning "沙箱镜像未找到: $sandbox_image (Agent Skills 功能需要此镜像)"
log_info "可通过以下命令拉取: $0 -p 或 docker pull $sandbox_image"
fi
# 检查磁盘空间
log_info "检查磁盘空间..."
df -h | grep -E "(Filesystem|/$)"