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"
|
host_log="$temp_dir/host.jsonl"
|
||||||
join_log="$temp_dir/join.jsonl"
|
join_log="$temp_dir/join.jsonl"
|
||||||
host_pid=''
|
host_pid=''
|
||||||
|
sanitize_log() {
|
||||||
|
jq -Rrc 'fromjson? | {
|
||||||
|
event: (.event // "unknown"),
|
||||||
|
status: (.status // "unknown"),
|
||||||
|
phase: (.phase // "unknown"),
|
||||||
|
hasListingId: (((.listingId // "") | length) > 0)
|
||||||
|
}' "$1"
|
||||||
|
}
|
||||||
cleanup() {
|
cleanup() {
|
||||||
local status="$?"
|
local status="$?"
|
||||||
if [[ -n "$host_pid" ]] && kill -0 "$host_pid" 2>/dev/null; then
|
if [[ -n "$host_pid" ]] && kill -0 "$host_pid" 2>/dev/null; then
|
||||||
@@ -66,8 +74,8 @@ cleanup() {
|
|||||||
fi
|
fi
|
||||||
if [[ "$status" -ne 0 ]]; then
|
if [[ "$status" -ne 0 ]]; then
|
||||||
printf 'Deployment smoke failed; sanitized diagnostic events follow.\n' >&2
|
printf 'Deployment smoke failed; sanitized diagnostic events follow.\n' >&2
|
||||||
[[ -f "$host_log" ]] && jq -c . "$host_log" >&2 || true
|
[[ -f "$host_log" ]] && sanitize_log "$host_log" >&2 || true
|
||||||
[[ -f "$join_log" ]] && jq -c . "$join_log" >&2 || true
|
[[ -f "$join_log" ]] && sanitize_log "$join_log" >&2 || true
|
||||||
fi
|
fi
|
||||||
rm -rf "$temp_dir"
|
rm -rf "$temp_dir"
|
||||||
return "$status"
|
return "$status"
|
||||||
@@ -84,26 +92,24 @@ dotnet run --project "$PROJECT" --configuration "$BUILD_CONFIGURATION" --no-buil
|
|||||||
host_pid="$!"
|
host_pid="$!"
|
||||||
|
|
||||||
ready=false
|
ready=false
|
||||||
|
listing_id=''
|
||||||
for ((iteration = 0; iteration < TIMEOUT_SECONDS * 4; iteration++)); do
|
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
|
ready=true
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
if ! kill -0 "$host_pid" 2>/dev/null; then
|
if ! kill -0 "$host_pid" 2>/dev/null; then
|
||||||
printf 'Host diagnostic stopped before it became ready.\n' >&2
|
printf 'Host diagnostic stopped before it became ready.\n' >&2
|
||||||
jq -c . "$host_log" >&2 || true
|
sanitize_log "$host_log" >&2 || true
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
sleep 0.25
|
sleep 0.25
|
||||||
done
|
done
|
||||||
if [[ "$ready" != true ]]; then
|
if [[ "$ready" != true ]]; then
|
||||||
printf 'Host diagnostic did not become ready within %s seconds.\n' "$TIMEOUT_SECONDS" >&2
|
printf 'Host diagnostic did not report a ready listing 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
|
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
@@ -61,7 +61,9 @@ public sealed partial class DocumentationContractTests
|
|||||||
Assert.Contains("metadata.st_mode & 0o077", helper, StringComparison.Ordinal);
|
Assert.Contains("metadata.st_mode & 0o077", helper, StringComparison.Ordinal);
|
||||||
Assert.Contains("metadata.st_nlink != 1", helper, StringComparison.Ordinal);
|
Assert.Contains("metadata.st_nlink != 1", helper, StringComparison.Ordinal);
|
||||||
Assert.Contains("mint-local-publisher-credential.sh", smoke, StringComparison.Ordinal);
|
Assert.Contains("mint-local-publisher-credential.sh", smoke, StringComparison.Ordinal);
|
||||||
Assert.Contains("select(.event == \"host.ready\") | .listingId", smoke, StringComparison.Ordinal);
|
Assert.Contains("select(.event == \"host.ready\" and .status == \"ready\")", smoke, StringComparison.Ordinal);
|
||||||
|
Assert.Contains("hasListingId", smoke, StringComparison.Ordinal);
|
||||||
|
Assert.DoesNotContain("jq -c .", smoke, StringComparison.Ordinal);
|
||||||
Assert.DoesNotContain("hexkey:", smoke, StringComparison.Ordinal);
|
Assert.DoesNotContain("hexkey:", smoke, StringComparison.Ordinal);
|
||||||
Assert.DoesNotContain("openssl dgst", smoke, StringComparison.Ordinal);
|
Assert.DoesNotContain("openssl dgst", smoke, StringComparison.Ordinal);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user