fix: require backend JSON readiness before activating a release
continuous-integration/drone/push Build is failing Details

This commit is contained in:
mihir 2026-11-20 18:07:55 +05:30
parent f4dd351f87
commit 2992c9e8f2
3 changed files with 17 additions and 4 deletions

View File

@ -50,7 +50,8 @@ overwrite a published release. A file lock
serializes activation. An older build cannot replace a newer active build.
The `current` symlink changes atomically. HTTPS checks use the real hostname
resolved to loopback and verify the certificate, release marker, homepage,
`/workspace`, `/cart`, and `/api/v1/health/ready`. Failure restores the previous
`/workspace`, `/cart`, and `/api/v1/health/ready`. Readiness must return the backend's
`{"status":"ok"}` response. An HTML fallback fails verification. Failure restores the previous
current symlink, or removes the first activation if no release existed before it.
The last successful release is also retained at `previous`. Its assets can serve
requests from browser tabs opened before the update. Failed first deployments

View File

@ -80,8 +80,11 @@ mv -Tf "$temporary" current
served=$(curl --fail --silent --show-error --max-time 20 \
--resolve "$host:443:127.0.0.1" "https://$host/release.txt")
test "$served" = "$release_id"
for path in / /workspace /cart /api/v1/health/ready; do
for path in / /workspace /cart; do
curl --fail --silent --show-error --output /dev/null --max-time 20 \
--resolve "$host:443:127.0.0.1" "https://$host$path"
done
ready=$(curl --fail --silent --show-error --max-time 20 \
--resolve "$host:443:127.0.0.1" "https://$host/api/v1/health/ready")
test "$(printf '%s' "$ready" | tr -d '[:space:]')" = '{"status":"ok"}'
echo "Activated $release_id on $host"

View File

@ -15,11 +15,17 @@ case "$*" in
else
cat "$DEPLOY_TEST_ROOT/current/release.txt"
fi ;;
*health/ready*) test ! -f "$DEPLOY_TEST_ROOT/fail-health" ;;
*health/ready*)
test ! -f "$DEPLOY_TEST_ROOT/fail-health" || exit 1
if [ -f "$DEPLOY_TEST_ROOT/html-readiness" ]; then
echo '<html>Page not found</html>'
else
echo '{"status":"ok"}'
fi ;;
esac
MOCK
chmod +x "$fixture/bin/curl"
for release in 1-aaa 2-bbb 3-ccc; do
for release in 1-aaa 2-bbb 3-ccc 4-ddd; do
mkdir -p "$fixture/site/incoming/$release/dist"
printf '%s\n' "$release" > "$fixture/site/incoming/$release/dist/release.txt"
printf '<html>Test</html>\n' > "$fixture/site/incoming/$release/dist/index.html"
@ -62,4 +68,7 @@ test "$(cat "$fixture/site/current/index.html")" = legacy
rm "$fixture/site/fail-health"
deploy 3-ccc
test "$(cat "$fixture/site/previous/index.html")" = legacy
touch "$fixture/site/html-readiness"
if deploy 4-ddd; then echo 'Expected rollback when readiness serves HTML' >&2; exit 1; fi
test "$(cat "$fixture/site/current/release.txt")" = 3-ccc
printf 'Deployment activation, rollback and stale-build checks passed.\n'