fix: align business reports and record task migration progress

This commit is contained in:
Yvan
2026-11-06 00:47:06 +08:00
parent 1bc2082718
commit b1f14bd525
32 changed files with 501 additions and 53 deletions
+2
View File
@@ -37,6 +37,8 @@ bash /www/wwwroot/sw2.fuhua91.com/releases/<commit>/deploy.sh <commit>
脚本先构建和检查镜像,再停止当前受管容器,保留一份停止的 `-previous` 容器。健康检查失败时恢复前一组容器。配置、上传文件和数据库不随镜像替换;索引迁移由后端启动按版本执行。
首次启动持续等待建表与索引迁移完成,以后端健康检查通过为准,不设置总等待时限。容器退出或重启时立即回退;迁移日志记录每一步的名称、结果和耗时。切换数据库前需备份运行配置;镜像回退不会自动还原数据库连接配置。
首次接入域名时,备份宝塔原站点配置,再安装 `bt-nginx-sw2.fuhua91.com.conf` 至 `/www/server/panel/vhost/nginx/`,执行 `/www/server/nginx/sbin/nginx -t` 通过后重载。模板保留证书验证目录,当前监听 HTTP;后续由宝塔为 sw2 单独配置匹配域名的证书。
验证首页、静态资源、`/api/health`、登录状态、商务接口和任务启停/执行日志。回退版本可执行 `bash /www/wwwroot/sw2.fuhua91.com/deploy.sh <旧commit>`;数据库迁移及业务数据不由镜像回退脚本撤销。
+1 -1
View File
@@ -44,7 +44,7 @@ try {
Get-ChildItem -LiteralPath (Join-Path $repoRoot 'web\dist') | ForEach-Object {
Copy-Item -LiteralPath $_.FullName -Destination $frontendDist -Recurse -Force
}
foreach ($name in @('deploy.sh', 'bt-nginx-sw2.fuhua91.com.conf')) {
foreach ($name in @('deploy.sh', 'wait-backend.sh', 'bt-nginx-sw2.fuhua91.com.conf')) {
Copy-Item -LiteralPath (Join-Path $PSScriptRoot $name) -Destination (Join-Path $stage $name)
}
& tar -czf $archive -C $stage .
+2 -6
View File
@@ -47,6 +47,7 @@ if [[ "$MODE" == '--build-only' ]]; then exit 0; fi
test -s "$BASE_DIR/config/config.yaml"
test -f "$BASE_DIR/runtime.env"
test -f "$RELEASE/wait-backend.sh"
install -d -o 1000 -g 1000 -m 0750 "$BASE_DIR/config" "$BASE_DIR/log" "$BASE_DIR/uploads"
chown 1000:1000 "$BASE_DIR/config/config.yaml"
chmod 0600 "$BASE_DIR/config/config.yaml" "$BASE_DIR/runtime.env"
@@ -98,12 +99,7 @@ docker run -d --name sw2-backend --label com.sw2.application=sw2 \
-v "$BASE_DIR/config:/data/conf" -v "$BASE_DIR/log:/app/logs" -v "$BASE_DIR/uploads:/app/uploads" \
"$BACKEND_IMAGE"
ready=false
for attempt in $(seq 1 45); do
if curl -fsS --max-time 3 http://127.0.0.1:9602/health >/dev/null 2>&1; then ready=true; break; fi
sleep 2
done
[[ "$ready" == true ]] || { echo 'Backend health check failed' >&2; false; }
bash "$RELEASE/wait-backend.sh"
created+=(sw2-frontend)
docker run -d --name sw2-frontend --label com.sw2.application=sw2 \
+19
View File
@@ -0,0 +1,19 @@
#!/usr/bin/env bash
set -euo pipefail
# The HTTP listener starts after migrations. Large indexes have no meaningful
# fixed startup deadline; a stopped/restarted process is an actual failure.
started=$SECONDS
echo 'Waiting for backend startup and database migrations to finish...'
while true; do
state=$(docker inspect --format '{{.State.Running}} {{.RestartCount}}' sw2-backend) || exit 1
if [[ "$state" != 'true 0' ]]; then
echo "Backend exited or restarted during initialization ($state); check the migration logs." >&2
exit 1
fi
if curl -fsS --max-time 3 http://127.0.0.1:9602/health >/dev/null 2>&1; then
printf 'Backend ready after %s seconds.\n' "$((SECONDS - started))"
exit 0
fi
sleep 2
done
+45
View File
@@ -0,0 +1,45 @@
#!/usr/bin/env bash
set -euo pipefail
SCRIPT=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)/wait-backend.sh
TEST_TMP=$(cd -- "${TMPDIR:-/tmp}" && pwd -P)
TEST_ROOT=$(mktemp -d "$TEST_TMP/sw-backend-readiness.XXXXXX")
cleanup() {
[[ "$TEST_ROOT" == "$TEST_TMP/sw-backend-readiness."* ]] || exit 1
rm -rf -- "$TEST_ROOT"
}
trap cleanup EXIT
mkdir "$TEST_ROOT/bin"
cat > "$TEST_ROOT/bin/docker" <<'DOCKER'
#!/usr/bin/env bash
set -euo pipefail
[[ "$1" == inspect && "${!#}" == sw2-backend ]]
case "$TEST_MODE" in
exited) echo 'false 0' ;;
restarted) echo 'true 1' ;;
inspect-failed) exit 1 ;;
*) echo 'true 0' ;;
esac
DOCKER
cat > "$TEST_ROOT/bin/curl" <<'CURL'
#!/usr/bin/env bash
set -euo pipefail
count=$(cat "$TEST_ROOT/polls")
count=$((count + 1))
echo "$count" > "$TEST_ROOT/polls"
[[ "$TEST_MODE" == ready || "$count" -gt 60 ]]
CURL
printf '#!/usr/bin/env bash\nexit 0\n' > "$TEST_ROOT/bin/sleep"
chmod +x "$TEST_ROOT/bin/"*
export TEST_ROOT PATH="$TEST_ROOT/bin:$PATH"
for scenario in ready long-migration exited restarted inspect-failed; do
export TEST_MODE="$scenario"
echo 0 > "$TEST_ROOT/polls"
result=0
bash "$SCRIPT" > "$TEST_ROOT/output" 2>&1 || result=$?
case "$scenario" in
ready) [[ "$result" == 0 && "$(cat "$TEST_ROOT/polls")" == 1 ]] ;;
long-migration) [[ "$result" == 0 && "$(cat "$TEST_ROOT/polls")" == 61 ]] ;;
*) [[ "$result" != 0 && "$(cat "$TEST_ROOT/polls")" == 0 ]] ;;
esac
printf 'passed: %s\n' "$scenario"
done