File size: 2,461 Bytes
c6af477 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | #!/usr/bin/env bash
# Harbor compile-executable v2 ABI (websitebench.harbor.compile-executable.v1).
#
# Takes no arguments. Runs a private, offline compile step and produces a root
# `executable` in this directory. The executable is the candidate delivery
# entry point: it binds $HOST:$PORT, writes runtime data only under $DATA_DIR,
# honours $SEED and $TZ, stays in the foreground, forwards SIGTERM to the
# server, and serves `/__websitebench/health` -> {"status":"ok"}.
set -Eeuo pipefail
if (( $# != 0 )); then
echo "compile.sh takes no arguments" >&2
exit 2
fi
candidate_root="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd -P)"
cd "$candidate_root"
# The runtime contract ships one directory up from the candidate root; copy it
# next to the executable so a materialised bundle stays self-contained.
mkdir -p backend
if [[ -f ../backend/runtime.json ]]; then
cp -f ../backend/runtime.json backend/runtime.json
fi
cat > executable <<'EXECUTABLE'
#!/usr/bin/env bash
set -Eeuo pipefail
: "${HOST:?HOST is required}"
: "${PORT:?PORT is required}"
: "${DATA_DIR:?DATA_DIR is required}"
: "${SEED:?SEED is required}"
: "${TZ:?TZ is required}"
case "$PORT" in
*[!0-9]*|'') echo "PORT must be numeric" >&2; exit 2 ;;
esac
case "$SEED" in
*[!0-9]*|'') echo "SEED must be a non-negative integer" >&2; exit 2 ;;
esac
app_root="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd -P)"
mkdir -p -- "$DATA_DIR"
data_dir="$(CDPATH= cd -- "$DATA_DIR" && pwd -P)"
# The runtime contract sits next to the executable when compiled, and one
# directory up in the working tree; prefer the compiled copy.
if [[ -f "$app_root/backend/runtime.json" ]]; then
runtime_contract="$app_root/backend/runtime.json"
else
runtime_contract="$app_root/../backend/runtime.json"
fi
export HOST PORT DATA_DIR SEED TZ
export PYTHONDONTWRITEBYTECODE=1
export PYTHONHASHSEED="$SEED"
export PYTHONPATH="$app_root${PYTHONPATH:+:$PYTHONPATH}"
export WEBSITEBENCH_DATA_DIR="$data_dir"
export WEBSITEBENCH_SEED="$SEED"
export WEBSITEBENCH_SITE_BACKEND_RUNTIME="$runtime_contract"
export WEBSITEBENCH_SITE_BACKEND_DATABASE="$data_dir/insureon.sqlite3"
# exec so the server is PID 1 of this process group and receives SIGTERM
# directly, satisfying the ABI's graceful-shutdown requirement.
exec "${PYTHON:-python3}" -m uvicorn app:APP --app-dir "$app_root" \
--host "$HOST" --port "$PORT" --log-level warning
EXECUTABLE
chmod 755 executable
echo "compiled $candidate_root/executable"
|