fix(docker-dev): guard the deploy POST against transport-level curl failure; bound both curls with --max-time

This commit is contained in:
Joseph Doherty
2026-08-17 05:37:04 -04:00
parent 45d670928a
commit 9f09a62ad2
+13 -3
View File
@@ -22,6 +22,10 @@
# ./deploy.sh artifact.json # send that file as the JSON request body
# cat artifact.json | ./deploy.sh
#
# NOTE (unverified against a live rig): the no-body invocation sends
# `Content-Type: application/json` with an empty body. Whether the minimal-API
# `DeployRequest?` parameter binds that as null or answers 400 has not been confirmed.
#
set -euo pipefail
BASE_URL="${OTOPCUA_ADMIN_URL:-http://localhost:9200}"
@@ -36,7 +40,8 @@ echo "Waiting for $READY_URL (up to ${READY_TIMEOUT_SECONDS}s)..."
deadline=$(( $(date +%s) + READY_TIMEOUT_SECONDS ))
ready=0
while [ "$(date +%s)" -lt "$deadline" ]; do
code="$(curl -s -o /dev/null -w "%{http_code}" "$READY_URL" || true)"
# --max-time bounds a connected-but-hung backend, so one poll can never eat the budget.
code="$(curl -s --max-time 10 -o /dev/null -w "%{http_code}" "$READY_URL" || true)"
if [ "$code" = "200" ]; then
ready=1
break
@@ -53,7 +58,7 @@ fi
echo "Ready. Posting deployment..."
# --- 2. the single, un-retried POST ------------------------------------------
curl_args=(-s -w '\n%{http_code}' -X POST "$DEPLOY_URL"
curl_args=(-s --max-time 60 -w '\n%{http_code}' -X POST "$DEPLOY_URL"
-H "X-Api-Key: $API_KEY"
-H "Content-Type: application/json")
@@ -64,7 +69,12 @@ elif [ ! -t 0 ]; then
curl_args+=(--data-binary @-)
fi
response="$(curl "${curl_args[@]}")"
# Guarded: a transport-level curl failure (connection refused/reset, timeout) must not trip
# `set -e` before the status/body reporting below — that reporting is the whole point here.
if ! response="$(curl "${curl_args[@]}")"; then
echo "ERROR: POST $DEPLOY_URL failed (curl could not complete the request)." >&2
exit 1
fi
status="$(printf '%s' "$response" | tail -n1)"
body="$(printf '%s' "$response" | sed '$d')"