test: 增加生产环境冒烟检查
This commit is contained in:
@@ -30,6 +30,8 @@
|
||||
- [ ] 启动管理后台。
|
||||
- [ ] 启动统一入口 gateway。
|
||||
- [ ] 检查 `域名/api/health` 后端健康接口。
|
||||
- [ ] 检查 `域名/api/ready` 返回数据库和 Redis 均就绪。
|
||||
- [ ] 执行 `BASE_URL=https://正式域名 ./scripts/production_smoke_test.sh`。
|
||||
|
||||
## 发布后
|
||||
|
||||
@@ -45,6 +47,9 @@
|
||||
- [ ] 管理后台可以新增知识库。
|
||||
- [ ] AI 请求日志有记录。
|
||||
- [ ] 操作日志有记录。
|
||||
- [ ] 访问日志为单行 JSON,且可用响应头中的 `X-Request-ID` 定位同一次请求。
|
||||
- [ ] 已确认备份任务生成 `.sql.gz` 和对应 `.sha256` 文件。
|
||||
- [ ] 已完成至少一次隔离数据库恢复演练。
|
||||
|
||||
## 回滚触发条件
|
||||
|
||||
|
||||
@@ -49,5 +49,6 @@ docker compose -f docker-compose.prod.yml config --quiet
|
||||
echo "== 备份恢复脚本语法检查 =="
|
||||
bash -n scripts/mysql_backup.sh
|
||||
bash -n scripts/mysql_restore.sh
|
||||
bash -n scripts/production_smoke_test.sh
|
||||
|
||||
echo "阶段六自动验证完成"
|
||||
|
||||
37
ai_knowledge_base_v2/scripts/production_smoke_test.sh
Executable file
37
ai_knowledge_base_v2/scripts/production_smoke_test.sh
Executable file
@@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
BASE_URL="${BASE_URL:-http://127.0.0.1:8080}"
|
||||
BASE_URL="${BASE_URL%/}"
|
||||
temporary_dir="$(mktemp -d)"
|
||||
trap 'rm -rf "$temporary_dir"' EXIT
|
||||
|
||||
check_json_status() {
|
||||
local path="$1"
|
||||
local expected="$2"
|
||||
local output="$temporary_dir/response.json"
|
||||
local headers="$temporary_dir/headers.txt"
|
||||
curl --fail --silent --show-error --max-time 10 -D "$headers" -o "$output" "$BASE_URL$path"
|
||||
grep -qi '^x-request-id:' "$headers"
|
||||
grep -q "\"status\":\"$expected\"" "$output"
|
||||
echo "通过:$path"
|
||||
}
|
||||
|
||||
check_page() {
|
||||
local path="$1"
|
||||
local output="$2"
|
||||
curl --fail --silent --show-error --max-time 10 -o "$output" "$BASE_URL$path"
|
||||
grep -qi '<!doctype html' "$output"
|
||||
echo "通过:$path"
|
||||
}
|
||||
|
||||
check_json_status "/api/health" "ok"
|
||||
check_json_status "/api/ready" "ready"
|
||||
check_page "/" "$temporary_dir/user.html"
|
||||
check_page "/login/" "$temporary_dir/admin.html"
|
||||
|
||||
admin_asset="$(grep -Eo '/login/assets/[^\" ]+\.(js|css)' "$temporary_dir/admin.html" | head -1)"
|
||||
test -n "$admin_asset"
|
||||
curl --fail --silent --show-error --max-time 10 -o /dev/null "$BASE_URL$admin_asset"
|
||||
echo "通过:后台静态资源 $admin_asset"
|
||||
echo "生产冒烟检查完成:$BASE_URL"
|
||||
Reference in New Issue
Block a user