diff --git a/scripts/git-build-deploy.ps1 b/scripts/git-build-deploy.ps1 index 64c7a06..4db7250 100644 --- a/scripts/git-build-deploy.ps1 +++ b/scripts/git-build-deploy.ps1 @@ -34,7 +34,7 @@ log() { printf '[INFO] %s\n' "$*"; } ok() { printf '[OK] %s\n' "$*"; } fail() { printf '[ERR] %s\n' "$*" >&2; exit 1; } -for command in git docker curl ssh; do +for command in git docker curl ssh base64; do command -v "$command" >/dev/null 2>&1 || fail "构建机缺少命令: $command" done curl -fsS "http://127.0.0.1:${REGISTRY_HOST##*:}/v2/" >/dev/null \ @@ -160,8 +160,21 @@ if [ "$healthy" != 1 ]; then exit 1 fi +public_healthy=0 +for _ in $(seq 1 15); do + if curl -fsS --max-time 5 https://sc.jiansun.vip/notification-center/health >/tmp/yyd-notification-public-health.json; then + public_healthy=1 + break + fi + sleep 2 +done +if [ "$public_healthy" != 1 ]; then + echo '通知中心公网健康检查持续失败,保留本机健康的新容器以便排查反向代理。' >&2 + exit 1 +fi + printf '%s' "$COMMIT_SHA" > DEPLOYED_COMMIT -curl -fsS --max-time 10 https://sc.jiansun.vip/notification-center/health +cat /tmp/yyd-notification-public-health.json printf '\nDEPLOYED_COMMIT=' cat DEPLOYED_COMMIT printf '\nCONTAINER_IMAGE=' @@ -170,8 +183,9 @@ printf '\n' PRODUCTION )" -printf '%s\n' "$production_script" | ssh -o BatchMode=yes "$PRODUCTION_SERVER" \ - "REMOTE_IMAGE='$remote_commit' IMAGE_TAG='$image_tag' COMMIT_SHA='$commit_sha' bash -s" +production_script_base64="$(printf '%s\n' "$production_script" | base64 | tr -d '\n')" +ssh -o BatchMode=yes "$PRODUCTION_SERVER" \ + "printf '%s' '$production_script_base64' | base64 -d | REMOTE_IMAGE='$remote_commit' IMAGE_TAG='$image_tag' COMMIT_SHA='$commit_sha' bash -s" ok "通知中心已部署到 ${commit_sha}" '@