fix(deploy): gate smoke readiness atomically (#1)
This commit is contained in:
+17
-11
@@ -58,6 +58,14 @@ temp_dir="$(mktemp -d)"
|
||||
host_log="$temp_dir/host.jsonl"
|
||||
join_log="$temp_dir/join.jsonl"
|
||||
host_pid=''
|
||||
sanitize_log() {
|
||||
jq -Rrc 'fromjson? | {
|
||||
event: (.event // "unknown"),
|
||||
status: (.status // "unknown"),
|
||||
phase: (.phase // "unknown"),
|
||||
hasListingId: (((.listingId // "") | length) > 0)
|
||||
}' "$1"
|
||||
}
|
||||
cleanup() {
|
||||
local status="$?"
|
||||
if [[ -n "$host_pid" ]] && kill -0 "$host_pid" 2>/dev/null; then
|
||||
@@ -66,8 +74,8 @@ cleanup() {
|
||||
fi
|
||||
if [[ "$status" -ne 0 ]]; then
|
||||
printf 'Deployment smoke failed; sanitized diagnostic events follow.\n' >&2
|
||||
[[ -f "$host_log" ]] && jq -c . "$host_log" >&2 || true
|
||||
[[ -f "$join_log" ]] && jq -c . "$join_log" >&2 || true
|
||||
[[ -f "$host_log" ]] && sanitize_log "$host_log" >&2 || true
|
||||
[[ -f "$join_log" ]] && sanitize_log "$join_log" >&2 || true
|
||||
fi
|
||||
rm -rf "$temp_dir"
|
||||
return "$status"
|
||||
@@ -84,26 +92,24 @@ dotnet run --project "$PROJECT" --configuration "$BUILD_CONFIGURATION" --no-buil
|
||||
host_pid="$!"
|
||||
|
||||
ready=false
|
||||
listing_id=''
|
||||
for ((iteration = 0; iteration < TIMEOUT_SECONDS * 4; iteration++)); do
|
||||
if jq -e 'select(.event == "host.ready")' "$host_log" >/dev/null 2>&1; then
|
||||
if listing_id="$(jq -er '
|
||||
select(.event == "host.ready" and .status == "ready")
|
||||
| .listingId // empty
|
||||
' "$host_log" 2>/dev/null | tail -n 1)" && [[ -n "$listing_id" ]]; then
|
||||
ready=true
|
||||
break
|
||||
fi
|
||||
if ! kill -0 "$host_pid" 2>/dev/null; then
|
||||
printf 'Host diagnostic stopped before it became ready.\n' >&2
|
||||
jq -c . "$host_log" >&2 || true
|
||||
sanitize_log "$host_log" >&2 || true
|
||||
exit 1
|
||||
fi
|
||||
sleep 0.25
|
||||
done
|
||||
if [[ "$ready" != true ]]; then
|
||||
printf 'Host diagnostic did not become ready within %s seconds.\n' "$TIMEOUT_SECONDS" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
listing_id="$(jq -r 'select(.event == "host.ready") | .listingId' "$host_log" | tail -n 1)"
|
||||
if [[ -z "$listing_id" || "$listing_id" == null ]]; then
|
||||
printf 'Host diagnostic did not report a listing ID.\n' >&2
|
||||
printf 'Host diagnostic did not report a ready listing within %s seconds.\n' "$TIMEOUT_SECONDS" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
Reference in New Issue
Block a user