修复(08-08-production-deployment-execution): 持久化远端部署阶段日志
ci-e2e / e2e (push) Canceled after 0s
ci-minimal / check-minimal (push) Canceled after 0s

这个提交包含在:
2026-08-08 21:29:55 +08:00
父节点 b94afcfab0
当前提交 0224ad83d7
共修改 6 个文件,包含 110 行新增和 3 行删除
+29 -3
查看文件
@@ -263,6 +263,32 @@ if [[ "$ENABLE_WORKER" == "1" ]]; then
profile_args+=(--profile worker)
fi
DEPLOY_RUNTIME_LOG_REF="artifacts/deployment-runtime"
DEPLOY_RUNTIME_LOG_DIR="$REMOTE_DIR/$DEPLOY_RUNTIME_LOG_REF"
install -d -m 0700 "$DEPLOY_RUNTIME_LOG_DIR"
run_logged_deploy_stage() {
local stage="$1"
shift
[[ "$stage" =~ ^[a-z0-9-]+$ ]] || {
echo "[deploy-stage][ERROR] 阶段名称格式无效" >&2
return 2
}
local log_ref="$DEPLOY_RUNTIME_LOG_REF/${stage}-${BUILD_SHA:0:12}.log"
local log_file="$REMOTE_DIR/$log_ref"
: > "$log_file"
chmod 0600 "$log_file"
echo "[deploy-stage] stage=$stage logRef=$log_ref"
if "$@" </dev/null >"$log_file" 2>&1; then
echo "[deploy-stage][PASS] stage=$stage logRef=$log_ref"
return 0
else
local status=$?
echo "[deploy-stage][ERROR] stage=$stage exit=$status logRef=$log_ref" >&2
return "$status"
fi
}
echo ">>> 4.1 校验远端 compose 配置"
"${compose_cmd[@]}" "${profile_args[@]}" config >/dev/null
@@ -273,13 +299,13 @@ if [[ "$ENABLE_MINIO" == "1" ]]; then
fi
echo ">>> 4.3 构建最新 init 镜像"
"${compose_cmd[@]}" build init
run_logged_deploy_stage "build-init" "${compose_cmd[@]}" build init
echo ">>> 4.4 预检新配置并执行 init"
"${compose_cmd[@]}" run --rm -T --entrypoint sh init -lc 'cd /app/server && node -e '\''require("./src/config").getConfig()'\'' && npm run prisma:migrate:deploy && npm run seed:config && npm run seed:trialrun' </dev/null
run_logged_deploy_stage "run-init" "${compose_cmd[@]}" run --rm -T --entrypoint sh init -lc 'cd /app/server && node -e '\''require("./src/config").getConfig()'\'' && npm run prisma:migrate:deploy && npm run seed:config && npm run seed:trialrun'
echo ">>> 4.5 构建并切换应用服务"
"${compose_cmd[@]}" "${profile_args[@]}" up -d --build server
run_logged_deploy_stage "build-switch-server" "${compose_cmd[@]}" "${profile_args[@]}" up -d --build server
if [[ "$ENABLE_WORKER" == "1" ]]; then
"${compose_cmd[@]}" "${profile_args[@]}" up -d worker
fi
+13
查看文件
@@ -746,6 +746,19 @@ if (deployExistingScriptContent.indexOf('ssh "$DEPLOY_REFRESH_SERVER" refresh')
errors.push('deploy-existing.sh 必须在应用部署成功后刷新备份合同');
}
for (const requiredFragment of [
'DEPLOY_RUNTIME_LOG_REF="artifacts/deployment-runtime"',
'install -d -m 0700 "$DEPLOY_RUNTIME_LOG_DIR"',
'chmod 0600 "$log_file"',
'run_logged_deploy_stage "build-init"',
'run_logged_deploy_stage "run-init"',
'run_logged_deploy_stage "build-switch-server"',
]) {
if (!deployScriptContent.includes(requiredFragment)) {
errors.push(`deploy.sh 缺少远端阶段日志合同: ${requiredFragment}`);
}
}
for (const requiredFragment of [
'validateProductionOrigin',
'validateProductionDbName',