Download tools/predeploy.sh from gamer-forums/archive-db: direct link, hf CLI and curl.
- Browser
- Download file 3.49 kB
-
https://huggingface.co/datasets/gamer-forums/archive-db/resolve/main/tools/predeploy.sh
- Command line
-
hf download hf://datasets/gamer-forums/archive-db/tools/predeploy.sh
-
curl -L -o predeploy.sh https://huggingface.co/datasets/gamer-forums/archive-db/resolve/main/tools/predeploy.sh
3.49 kB
| # predeploy.sh β gate that runs before every push to the Space. | |
| # | |
| # Catches the classes of bugs we've actually hit in production: | |
| # 1. Syntax / import errors in server.py | |
| # 2. SQLite "attempt to write a readonly database" β PRAGMA writes, | |
| # WAL lock file creation, anything that needs a writable mount | |
| # 3. 500s on common endpoints (top_hated + year filter was our worst) | |
| # | |
| # How: chmod the local posts.db to 0444 (true read-only), spin up uvicorn | |
| # on a private test port (8799), run tests/smoke.py, then restore perms. | |
| # trap ensures perms are restored even if the test suite errors out. | |
| # | |
| # Usage: | |
| # ./predeploy.sh # run gates, exit 0 on success | |
| # ./predeploy.sh --skip-perms # skip the chmod step (DB already RO) | |
| # | |
| # deploy.sh push calls this automatically. | |
| set -uo pipefail | |
| cd "$(dirname "$0")" | |
| DB="$(pwd)/posts.db" | |
| PORT=8799 | |
| TEST_BASE="http://127.0.0.1:${PORT}" | |
| SERVER_LOG="/tmp/predeploy_server.log" | |
| SERVER_PID="" | |
| ORIG_PERMS="" | |
| red() { printf '\033[31m%s\033[0m\n' "$*"; } | |
| green() { printf '\033[32m%s\033[0m\n' "$*"; } | |
| yellow() { printf '\033[33m%s\033[0m\n' "$*"; } | |
| cleanup() { | |
| local status=$? | |
| if [ -n "$SERVER_PID" ] && kill -0 "$SERVER_PID" 2>/dev/null; then | |
| kill "$SERVER_PID" 2>/dev/null || true | |
| wait "$SERVER_PID" 2>/dev/null || true | |
| fi | |
| if [ -n "$ORIG_PERMS" ] && [ -f "$DB" ]; then | |
| chmod "$ORIG_PERMS" "$DB" | |
| fi | |
| exit $status | |
| } | |
| trap cleanup EXIT INT TERM | |
| # ---- gate 1: syntax / import ---- | |
| echo "βΆ syntax check" | |
| if ! python3 -m py_compile server.py 2>&1; then | |
| red "β server.py syntax check FAILED" | |
| exit 1 | |
| fi | |
| green "β server.py compiles" | |
| echo "βΆ import check (catches top-level errors)" | |
| if ! (cd .. && python3 -c "import search.server" 2>&1); then | |
| red "β server.py import FAILED" | |
| exit 1 | |
| fi | |
| green "β server.py imports cleanly" | |
| # ---- gate 1b: parser unit tests (fast, no server needed) ---- | |
| echo "βΆ parser unit tests" | |
| if ! python3 tests/test_parsers.py 2>&1 | tail -5; then | |
| red "β parser unit tests FAILED" | |
| exit 1 | |
| fi | |
| green "β parser unit tests pass" | |
| # ---- gate 2: smoke tests against RO DB ---- | |
| if [ ! -f "$DB" ]; then | |
| yellow "β posts.db not present, skipping runtime smoke tests" | |
| exit 0 | |
| fi | |
| if [ "${1:-}" != "--skip-perms" ]; then | |
| ORIG_PERMS=$(stat -f "%Lp" "$DB" 2>/dev/null || stat -c "%a" "$DB") | |
| echo "βΆ chmod 0444 posts.db (orig perms: $ORIG_PERMS β will restore on exit)" | |
| chmod 0444 "$DB" | |
| fi | |
| echo "βΆ booting test server on port $PORT" | |
| # Use a fresh process group so cleanup can kill the whole tree if needed. | |
| (cd .. && python3 -m uvicorn search.server:app --host 127.0.0.1 --port "$PORT" --log-level warning) \ | |
| > "$SERVER_LOG" 2>&1 & | |
| SERVER_PID=$! | |
| # Wait up to 15s for the server to come up. | |
| for i in $(seq 1 30); do | |
| if curl -s -o /dev/null -m 1 "$TEST_BASE/api/stats"; then | |
| break | |
| fi | |
| if ! kill -0 "$SERVER_PID" 2>/dev/null; then | |
| red "β test server died during startup" | |
| echo "--- server log:" | |
| tail -30 "$SERVER_LOG" | |
| exit 1 | |
| fi | |
| sleep 0.5 | |
| done | |
| if ! curl -s -o /dev/null -m 2 "$TEST_BASE/api/stats"; then | |
| red "β test server never came up" | |
| echo "--- server log:" | |
| tail -30 "$SERVER_LOG" | |
| exit 1 | |
| fi | |
| green "β test server up" | |
| echo "βΆ running smoke tests" | |
| if ! TEST_BASE="$TEST_BASE" python3 tests/smoke.py; then | |
| red "β smoke tests FAILED" | |
| echo "--- server log:" | |
| tail -50 "$SERVER_LOG" | |
| exit 1 | |
| fi | |
| green "β all smoke tests passed" | |
| echo | |
| green "PREDEPLOY β safe to push" | |
| exit 0 | |