diff --git a/docs/STATIC-DEPLOYMENT.md b/docs/STATIC-DEPLOYMENT.md index c94f80e..73144ab 100644 --- a/docs/STATIC-DEPLOYMENT.md +++ b/docs/STATIC-DEPLOYMENT.md @@ -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 diff --git a/scripts/deploy-frontend.sh b/scripts/deploy-frontend.sh index f9590a6..c197a08 100644 --- a/scripts/deploy-frontend.sh +++ b/scripts/deploy-frontend.sh @@ -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" diff --git a/test/deployment.test.sh b/test/deployment.test.sh index ef8972e..66a9ae5 100644 --- a/test/deployment.test.sh +++ b/test/deployment.test.sh @@ -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 'Page not found' + 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 'Test\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'