Repository navigation
Expand file tree
/
Copy pathrun.sh
More file actions
executable file
·53 lines (49 loc) · 2.2 KB
/
Copy pathrun.sh
File metadata and controls
executable file
·53 lines (49 loc) · 2.2 KB
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
#!/bin/sh
# Runs the clicks survey against a fresh Lens: a new database and data folder, the stand-in model, the web installer.
# From the repository root, after `make env`, `uv sync` in fastapi_backend and `pnpm build` in nextjs-frontend
# (make clicks does all three):
# ci/clicks/run.sh [--compare ci/clicks/baseline.json] [--only id,id]
# Ports 3000 (web app), 8000 (API), 3990 (installer) and 11434 (stand-in model) must be free.
set -eu
here=$(cd "$(dirname "$0")" && pwd)
repo=$(cd "$here/../.." && pwd)
tmp=$(mktemp -d)
pids=""
stop() {
for p in $pids; do kill "$p" 2>/dev/null || true; done
# Wait for them to exit (30 seconds, then forced), so a run straight after this one (the phone survey after the
# computer's in CI) gets the ports, rather than this run's API answering it with its accounts already made
for p in $pids; do
(sleep 30 && kill -9 "$p") >/dev/null 2>&1 &
w=$!
wait "$p" 2>/dev/null || true
kill "$w" 2>/dev/null || true
done
rm -rf "$tmp" 2>/dev/null || { sleep 2; rm -rf "$tmp" || true; }
}
trap stop EXIT INT TERM
# The containers' configuration, pointed at the temporary folder, with the jobs run by the API itself
mkdir -p "$tmp/audio/podcasts" "$tmp/audio/interviews"
sed -e "s#/data#$tmp/data#; s#/audio#$tmp/audio#g; s#inline: 0#inline: 1#" \
"$repo/fastapi_backend/docker/archive.yaml" >"$tmp/archive.yaml"
(cd "$repo/fastapi_backend" && ARCHIVE_CONFIG="$tmp/archive.yaml" LENS_SETUP_CODE=survey-code RUN_BACKGROUND=true \
exec .venv/bin/uvicorn app.main:app --host 127.0.0.1 --port 8000 >"$tmp/backend.log" 2>&1) &
pids="$pids $!"
(cd "$repo/nextjs-frontend" && exec node_modules/.bin/next start -p 3000 >"$tmp/frontend.log" 2>&1) &
pids="$pids $!"
for url in http://127.0.0.1:8000/api/v1/auth/status http://127.0.0.1:3000/login; do
i=0
until curl -fsS -o /dev/null "$url"; do
i=$((i + 1))
if [ $i -gt 120 ]; then
echo "$url didn't answer; the logs:" >&2
tail -50 "$tmp/backend.log" "$tmp/frontend.log" >&2
exit 1
fi
sleep 1
done
done
status=0
LENS_SURVEY_DIR="$tmp/install" LENS_SURVEY_BACKEND_LOG="$tmp/backend.log" node "$here/survey.mjs" "$@" || status=$?
if [ $status -ne 0 ]; then tail -40 "$tmp/backend.log" >&2; fi
exit $status