@biffo/cli 0.376.0 → 0.378.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/_skeletons/plugin-template/scripts/core-version-preflight.sh +45 -7
- package/_skeletons/plugin-template/scripts/core-version-preflight.test.sh +61 -1
- package/_skeletons/sibling-template/scripts/core-version-preflight.sh +45 -7
- package/_skeletons/sibling-template/scripts/core-version-preflight.test.sh +61 -1
- package/package.json +1 -1
|
@@ -83,6 +83,10 @@
|
|
|
83
83
|
# CORE_HEALTH_URL — where to fetch the instance's health document,
|
|
84
84
|
# typically "${CORE_API_URL}/api/v1/health".
|
|
85
85
|
# Required whenever a minimum is declared.
|
|
86
|
+
# PREFLIGHT_WAIT_SECONDS — how long to keep retrying an unreachable/5xx
|
|
87
|
+
# health endpoint (default 600).
|
|
88
|
+
# PREFLIGHT_INITIAL_DELAY / PREFLIGHT_MAX_DELAY — backoff bounds in seconds
|
|
89
|
+
# (default 5 doubling up to 60).
|
|
86
90
|
# PREFLIGHT_CURL — override the curl binary/wrapper (tests use
|
|
87
91
|
# this to point at a stub).
|
|
88
92
|
#
|
|
@@ -124,15 +128,49 @@ BODY_FILE=/tmp/core-version-preflight-body.$$
|
|
|
124
128
|
ERR_FILE=/tmp/core-version-preflight-err.$$
|
|
125
129
|
trap 'rm -f "$BODY_FILE" "$ERR_FILE"' EXIT
|
|
126
130
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
+
# A core deploy replaces the API over several minutes, and a health check in
|
|
132
|
+
# that window can return 5xx or fail to connect. Only a MISSING answer
|
|
133
|
+
# (transport failure or 5xx) is retried, with exponential backoff, for up to
|
|
134
|
+
# PREFLIGHT_WAIT_SECONDS (default 600); every attempt is logged. Any other
|
|
135
|
+
# answer (a 200 with a wrong version, a 404, ...) is final and never waits.
|
|
136
|
+
WAIT_SECONDS=${PREFLIGHT_WAIT_SECONDS:-600}
|
|
137
|
+
DELAY=${PREFLIGHT_INITIAL_DELAY:-5}
|
|
138
|
+
MAX_DELAY=${PREFLIGHT_MAX_DELAY:-60}
|
|
139
|
+
START=$(date +%s)
|
|
140
|
+
ATTEMPT=0
|
|
131
141
|
|
|
132
|
-
|
|
133
|
-
|
|
142
|
+
while :; do
|
|
143
|
+
ATTEMPT=$((ATTEMPT + 1))
|
|
144
|
+
HTTP_CODE=$("$CURL" -sS --max-time 15 \
|
|
145
|
+
-o "$BODY_FILE" -w '%{http_code}' "$URL" 2>"$ERR_FILE")
|
|
146
|
+
RC=$?
|
|
147
|
+
ERR=$(cat "$ERR_FILE" 2>/dev/null)
|
|
148
|
+
|
|
149
|
+
RETRYABLE=0
|
|
150
|
+
if [ "$RC" -ne 0 ]; then
|
|
151
|
+
RETRYABLE=1
|
|
152
|
+
else
|
|
153
|
+
case "$HTTP_CODE" in
|
|
154
|
+
5[0-9][0-9]) RETRYABLE=1 ;;
|
|
155
|
+
esac
|
|
156
|
+
fi
|
|
157
|
+
|
|
158
|
+
if [ "$RC" -eq 0 ] && [ "$HTTP_CODE" = "200" ]; then
|
|
159
|
+
break
|
|
160
|
+
fi
|
|
161
|
+
|
|
162
|
+
ELAPSED=$(($(date +%s) - START))
|
|
163
|
+
if [ "$RETRYABLE" -eq 1 ] && [ $((ELAPSED + DELAY)) -le "$WAIT_SECONDS" ]; then
|
|
164
|
+
echo "core-version-preflight: attempt $ATTEMPT got no healthy answer from $URL (curl exit $RC, http ${HTTP_CODE:-none}${ERR:+, $ERR}); core may be redeploying — retrying in ${DELAY}s (${ELAPSED}s of ${WAIT_SECONDS}s elapsed)."
|
|
165
|
+
sleep "$DELAY"
|
|
166
|
+
DELAY=$((DELAY * 2))
|
|
167
|
+
[ "$DELAY" -gt "$MAX_DELAY" ] && DELAY=$MAX_DELAY
|
|
168
|
+
continue
|
|
169
|
+
fi
|
|
170
|
+
|
|
171
|
+
echo "::error::core-version-preflight: no health response available at $URL after $ATTEMPT attempt(s) over ${ELAPSED}s (curl exit $RC, http ${HTTP_CODE:-none}${ERR:+, $ERR}). An absent or unreachable health endpoint is treated as NOT satisfied — this is expected on a down instance, a network issue, or a not-yet-deployed core — and is a DIFFERENT fact from 'core is behind version $MIN'. Refusing to deploy rather than assuming core is ready." >&2
|
|
134
172
|
exit 1
|
|
135
|
-
|
|
173
|
+
done
|
|
136
174
|
|
|
137
175
|
ACTUAL=$(command -v jq >/dev/null 2>&1 && jq -r 'if (.version | type) == "string" then .version else empty end' "$BODY_FILE" 2>/dev/null)
|
|
138
176
|
|
|
@@ -185,10 +185,70 @@ _assert_output_contains "core behind — names required" "at least 0.250.0"
|
|
|
185
185
|
# CLOSED, and says the health endpoint was missing rather than that core
|
|
186
186
|
# is behind.
|
|
187
187
|
_write_stub_unreachable
|
|
188
|
-
_run CORE_MIN_TEMPLATE_VERSION=0.250.0 CORE_HEALTH_URL="$URL"
|
|
188
|
+
_run CORE_MIN_TEMPLATE_VERSION=0.250.0 CORE_HEALTH_URL="$URL" PREFLIGHT_WAIT_SECONDS=0
|
|
189
189
|
_assert_exit "health endpoint unreachable" 1
|
|
190
190
|
_assert_output_contains "health endpoint unreachable — says missing, not behind" "no health response available"
|
|
191
191
|
|
|
192
|
+
# 4b. 500 first, then healthy within the window — passes after retrying.
|
|
193
|
+
COUNT_FILE=$STUB_DIR/count
|
|
194
|
+
: > "$COUNT_FILE"
|
|
195
|
+
cat > "$STUB_DIR/curl" <<STUB
|
|
196
|
+
#!/usr/bin/env sh
|
|
197
|
+
outfile=""
|
|
198
|
+
prev=""
|
|
199
|
+
for a in "\$@"; do
|
|
200
|
+
case "\$prev" in
|
|
201
|
+
-o) outfile="\$a" ;;
|
|
202
|
+
esac
|
|
203
|
+
prev="\$a"
|
|
204
|
+
done
|
|
205
|
+
echo x >> "$COUNT_FILE"
|
|
206
|
+
if [ "\$(wc -l < "$COUNT_FILE")" -le 1 ]; then
|
|
207
|
+
printf 'oops' > "\$outfile"
|
|
208
|
+
printf '500'
|
|
209
|
+
else
|
|
210
|
+
printf '{"status": "ok", "version": "0.287.12"}' > "\$outfile"
|
|
211
|
+
printf '200'
|
|
212
|
+
fi
|
|
213
|
+
exit 0
|
|
214
|
+
STUB
|
|
215
|
+
chmod +x "$STUB_DIR/curl"
|
|
216
|
+
_run CORE_MIN_TEMPLATE_VERSION=0.250.0 CORE_HEALTH_URL="$URL" PREFLIGHT_WAIT_SECONDS=10 PREFLIGHT_INITIAL_DELAY=1
|
|
217
|
+
_assert_exit "500 then healthy within window" 0
|
|
218
|
+
_assert_output_contains "500 then healthy — logs the retry" "retrying in"
|
|
219
|
+
_assert_output_contains "500 then healthy — OK" "core is at version 0.287.12"
|
|
220
|
+
|
|
221
|
+
# 4c. 500 for the whole window — refuses after retrying.
|
|
222
|
+
cat > "$STUB_DIR/curl" <<'STUB'
|
|
223
|
+
#!/usr/bin/env sh
|
|
224
|
+
outfile=""
|
|
225
|
+
prev=""
|
|
226
|
+
for a in "$@"; do
|
|
227
|
+
case "$prev" in
|
|
228
|
+
-o) outfile="$a" ;;
|
|
229
|
+
esac
|
|
230
|
+
prev="$a"
|
|
231
|
+
done
|
|
232
|
+
printf 'oops' > "$outfile"
|
|
233
|
+
printf '500'
|
|
234
|
+
exit 0
|
|
235
|
+
STUB
|
|
236
|
+
chmod +x "$STUB_DIR/curl"
|
|
237
|
+
_run CORE_MIN_TEMPLATE_VERSION=0.250.0 CORE_HEALTH_URL="$URL" PREFLIGHT_WAIT_SECONDS=2 PREFLIGHT_INITIAL_DELAY=1 PREFLIGHT_MAX_DELAY=1
|
|
238
|
+
_assert_exit "500 for the whole window" 1
|
|
239
|
+
_assert_output_contains "500 whole window — logs retries" "retrying in"
|
|
240
|
+
_assert_output_contains "500 whole window — says missing" "no health response available"
|
|
241
|
+
|
|
242
|
+
# 4d. Healthy but below the minimum version — refuses immediately, no retry.
|
|
243
|
+
_write_stub_ok "0.208.1"
|
|
244
|
+
_run CORE_MIN_TEMPLATE_VERSION=0.250.0 CORE_HEALTH_URL="$URL" PREFLIGHT_WAIT_SECONDS=600 PREFLIGHT_INITIAL_DELAY=100
|
|
245
|
+
_assert_exit "below-minimum version refuses immediately" 1
|
|
246
|
+
if grep -qF "retrying in" "$OUT_FILE"; then
|
|
247
|
+
echo "FAIL: below-minimum version must not retry"; FAILURES=$((FAILURES + 1))
|
|
248
|
+
else
|
|
249
|
+
echo "PASS: below-minimum version did not retry"
|
|
250
|
+
fi
|
|
251
|
+
|
|
192
252
|
# 5. Health endpoint 404s — fails CLOSED, same "missing" message as
|
|
193
253
|
# scenario 4, never "core is behind".
|
|
194
254
|
_write_stub_404
|
|
@@ -83,6 +83,10 @@
|
|
|
83
83
|
# CORE_HEALTH_URL — where to fetch the instance's health document,
|
|
84
84
|
# typically "${CORE_API_URL}/api/v1/health".
|
|
85
85
|
# Required whenever a minimum is declared.
|
|
86
|
+
# PREFLIGHT_WAIT_SECONDS — how long to keep retrying an unreachable/5xx
|
|
87
|
+
# health endpoint (default 600).
|
|
88
|
+
# PREFLIGHT_INITIAL_DELAY / PREFLIGHT_MAX_DELAY — backoff bounds in seconds
|
|
89
|
+
# (default 5 doubling up to 60).
|
|
86
90
|
# PREFLIGHT_CURL — override the curl binary/wrapper (tests use
|
|
87
91
|
# this to point at a stub).
|
|
88
92
|
#
|
|
@@ -124,15 +128,49 @@ BODY_FILE=/tmp/core-version-preflight-body.$$
|
|
|
124
128
|
ERR_FILE=/tmp/core-version-preflight-err.$$
|
|
125
129
|
trap 'rm -f "$BODY_FILE" "$ERR_FILE"' EXIT
|
|
126
130
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
+
# A core deploy replaces the API over several minutes, and a health check in
|
|
132
|
+
# that window can return 5xx or fail to connect. Only a MISSING answer
|
|
133
|
+
# (transport failure or 5xx) is retried, with exponential backoff, for up to
|
|
134
|
+
# PREFLIGHT_WAIT_SECONDS (default 600); every attempt is logged. Any other
|
|
135
|
+
# answer (a 200 with a wrong version, a 404, ...) is final and never waits.
|
|
136
|
+
WAIT_SECONDS=${PREFLIGHT_WAIT_SECONDS:-600}
|
|
137
|
+
DELAY=${PREFLIGHT_INITIAL_DELAY:-5}
|
|
138
|
+
MAX_DELAY=${PREFLIGHT_MAX_DELAY:-60}
|
|
139
|
+
START=$(date +%s)
|
|
140
|
+
ATTEMPT=0
|
|
131
141
|
|
|
132
|
-
|
|
133
|
-
|
|
142
|
+
while :; do
|
|
143
|
+
ATTEMPT=$((ATTEMPT + 1))
|
|
144
|
+
HTTP_CODE=$("$CURL" -sS --max-time 15 \
|
|
145
|
+
-o "$BODY_FILE" -w '%{http_code}' "$URL" 2>"$ERR_FILE")
|
|
146
|
+
RC=$?
|
|
147
|
+
ERR=$(cat "$ERR_FILE" 2>/dev/null)
|
|
148
|
+
|
|
149
|
+
RETRYABLE=0
|
|
150
|
+
if [ "$RC" -ne 0 ]; then
|
|
151
|
+
RETRYABLE=1
|
|
152
|
+
else
|
|
153
|
+
case "$HTTP_CODE" in
|
|
154
|
+
5[0-9][0-9]) RETRYABLE=1 ;;
|
|
155
|
+
esac
|
|
156
|
+
fi
|
|
157
|
+
|
|
158
|
+
if [ "$RC" -eq 0 ] && [ "$HTTP_CODE" = "200" ]; then
|
|
159
|
+
break
|
|
160
|
+
fi
|
|
161
|
+
|
|
162
|
+
ELAPSED=$(($(date +%s) - START))
|
|
163
|
+
if [ "$RETRYABLE" -eq 1 ] && [ $((ELAPSED + DELAY)) -le "$WAIT_SECONDS" ]; then
|
|
164
|
+
echo "core-version-preflight: attempt $ATTEMPT got no healthy answer from $URL (curl exit $RC, http ${HTTP_CODE:-none}${ERR:+, $ERR}); core may be redeploying — retrying in ${DELAY}s (${ELAPSED}s of ${WAIT_SECONDS}s elapsed)."
|
|
165
|
+
sleep "$DELAY"
|
|
166
|
+
DELAY=$((DELAY * 2))
|
|
167
|
+
[ "$DELAY" -gt "$MAX_DELAY" ] && DELAY=$MAX_DELAY
|
|
168
|
+
continue
|
|
169
|
+
fi
|
|
170
|
+
|
|
171
|
+
echo "::error::core-version-preflight: no health response available at $URL after $ATTEMPT attempt(s) over ${ELAPSED}s (curl exit $RC, http ${HTTP_CODE:-none}${ERR:+, $ERR}). An absent or unreachable health endpoint is treated as NOT satisfied — this is expected on a down instance, a network issue, or a not-yet-deployed core — and is a DIFFERENT fact from 'core is behind version $MIN'. Refusing to deploy rather than assuming core is ready." >&2
|
|
134
172
|
exit 1
|
|
135
|
-
|
|
173
|
+
done
|
|
136
174
|
|
|
137
175
|
ACTUAL=$(command -v jq >/dev/null 2>&1 && jq -r 'if (.version | type) == "string" then .version else empty end' "$BODY_FILE" 2>/dev/null)
|
|
138
176
|
|
|
@@ -185,10 +185,70 @@ _assert_output_contains "core behind — names required" "at least 0.250.0"
|
|
|
185
185
|
# CLOSED, and says the health endpoint was missing rather than that core
|
|
186
186
|
# is behind.
|
|
187
187
|
_write_stub_unreachable
|
|
188
|
-
_run CORE_MIN_TEMPLATE_VERSION=0.250.0 CORE_HEALTH_URL="$URL"
|
|
188
|
+
_run CORE_MIN_TEMPLATE_VERSION=0.250.0 CORE_HEALTH_URL="$URL" PREFLIGHT_WAIT_SECONDS=0
|
|
189
189
|
_assert_exit "health endpoint unreachable" 1
|
|
190
190
|
_assert_output_contains "health endpoint unreachable — says missing, not behind" "no health response available"
|
|
191
191
|
|
|
192
|
+
# 4b. 500 first, then healthy within the window — passes after retrying.
|
|
193
|
+
COUNT_FILE=$STUB_DIR/count
|
|
194
|
+
: > "$COUNT_FILE"
|
|
195
|
+
cat > "$STUB_DIR/curl" <<STUB
|
|
196
|
+
#!/usr/bin/env sh
|
|
197
|
+
outfile=""
|
|
198
|
+
prev=""
|
|
199
|
+
for a in "\$@"; do
|
|
200
|
+
case "\$prev" in
|
|
201
|
+
-o) outfile="\$a" ;;
|
|
202
|
+
esac
|
|
203
|
+
prev="\$a"
|
|
204
|
+
done
|
|
205
|
+
echo x >> "$COUNT_FILE"
|
|
206
|
+
if [ "\$(wc -l < "$COUNT_FILE")" -le 1 ]; then
|
|
207
|
+
printf 'oops' > "\$outfile"
|
|
208
|
+
printf '500'
|
|
209
|
+
else
|
|
210
|
+
printf '{"status": "ok", "version": "0.287.12"}' > "\$outfile"
|
|
211
|
+
printf '200'
|
|
212
|
+
fi
|
|
213
|
+
exit 0
|
|
214
|
+
STUB
|
|
215
|
+
chmod +x "$STUB_DIR/curl"
|
|
216
|
+
_run CORE_MIN_TEMPLATE_VERSION=0.250.0 CORE_HEALTH_URL="$URL" PREFLIGHT_WAIT_SECONDS=10 PREFLIGHT_INITIAL_DELAY=1
|
|
217
|
+
_assert_exit "500 then healthy within window" 0
|
|
218
|
+
_assert_output_contains "500 then healthy — logs the retry" "retrying in"
|
|
219
|
+
_assert_output_contains "500 then healthy — OK" "core is at version 0.287.12"
|
|
220
|
+
|
|
221
|
+
# 4c. 500 for the whole window — refuses after retrying.
|
|
222
|
+
cat > "$STUB_DIR/curl" <<'STUB'
|
|
223
|
+
#!/usr/bin/env sh
|
|
224
|
+
outfile=""
|
|
225
|
+
prev=""
|
|
226
|
+
for a in "$@"; do
|
|
227
|
+
case "$prev" in
|
|
228
|
+
-o) outfile="$a" ;;
|
|
229
|
+
esac
|
|
230
|
+
prev="$a"
|
|
231
|
+
done
|
|
232
|
+
printf 'oops' > "$outfile"
|
|
233
|
+
printf '500'
|
|
234
|
+
exit 0
|
|
235
|
+
STUB
|
|
236
|
+
chmod +x "$STUB_DIR/curl"
|
|
237
|
+
_run CORE_MIN_TEMPLATE_VERSION=0.250.0 CORE_HEALTH_URL="$URL" PREFLIGHT_WAIT_SECONDS=2 PREFLIGHT_INITIAL_DELAY=1 PREFLIGHT_MAX_DELAY=1
|
|
238
|
+
_assert_exit "500 for the whole window" 1
|
|
239
|
+
_assert_output_contains "500 whole window — logs retries" "retrying in"
|
|
240
|
+
_assert_output_contains "500 whole window — says missing" "no health response available"
|
|
241
|
+
|
|
242
|
+
# 4d. Healthy but below the minimum version — refuses immediately, no retry.
|
|
243
|
+
_write_stub_ok "0.208.1"
|
|
244
|
+
_run CORE_MIN_TEMPLATE_VERSION=0.250.0 CORE_HEALTH_URL="$URL" PREFLIGHT_WAIT_SECONDS=600 PREFLIGHT_INITIAL_DELAY=100
|
|
245
|
+
_assert_exit "below-minimum version refuses immediately" 1
|
|
246
|
+
if grep -qF "retrying in" "$OUT_FILE"; then
|
|
247
|
+
echo "FAIL: below-minimum version must not retry"; FAILURES=$((FAILURES + 1))
|
|
248
|
+
else
|
|
249
|
+
echo "PASS: below-minimum version did not retry"
|
|
250
|
+
fi
|
|
251
|
+
|
|
192
252
|
# 5. Health endpoint 404s — fails CLOSED, same "missing" message as
|
|
193
253
|
# scenario 4, never "core is behind".
|
|
194
254
|
_write_stub_404
|