CI: reuse unchanged work so a code-only deploy takes about 2 minutes instead of 8
Deploy / deploy (push) Successful in 7m52s
Deploy / deploy (push) Successful in 7m52s
The data build (download, ingest, work types: about 5 of the 8 minutes), npm ci, the Next.js compiler cache and the Postgres load are now cached under /opt/llm-survey/cache and redone only when their inputs change. Raw data is refreshed by a nightly run or by a manual run with refresh_data. Docs-only pushes and pushes already superseded by a newer commit on main skip the deploy. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FbMbJPadPzVwvt9rU9GBNo
This commit is contained in:
+44
-8
@@ -5,6 +5,12 @@
|
||||
# 3. build the site, load the data into Postgres (schema "next" -> swapped in as "live")
|
||||
# 4. switch /opt/llm-survey/current, (re)start systemd unit `llm-survey`, health-check
|
||||
# Port is never 3000 or 18131 (taken).
|
||||
# Caches under $ROOT/cache (a deploy that changes neither the data scripts nor the lockfile takes about 2 minutes, not 8):
|
||||
# export/<key> the JSON-lines export, keyed by a hash of the data scripts + data/labels (rebuilt when they change,
|
||||
# or when REFRESH_DATA=true: nightly run / manual run, which also re-download the raw sources)
|
||||
# loaded id of the export now in Postgres schema "live" (the load is skipped when it matches)
|
||||
# next Next.js compiler cache, linked into .next/cache
|
||||
# node_modules is reused from the current release when package-lock.json and the node version are unchanged.
|
||||
set -eu
|
||||
SHA="${1:?usage: deploy.sh <git-sha>}"
|
||||
APP=llm-survey
|
||||
@@ -54,22 +60,52 @@ fi
|
||||
|
||||
# ---- 2. release dir + data build ------------------------------------------------------
|
||||
REL="$ROOT/releases/$SHA"
|
||||
mkdir -p "$ROOT/releases" "$ROOT/cache/raw"
|
||||
mkdir -p "$ROOT/releases" "$ROOT/cache/raw" "$ROOT/cache/export" "$ROOT/cache/next"
|
||||
rm -rf "$REL"; mkdir -p "$REL"
|
||||
tar --exclude=.git --exclude=node_modules --exclude=.next -cf - . | tar -xf - -C "$REL"
|
||||
cd "$REL"
|
||||
mkdir -p build data
|
||||
ln -sfn "$ROOT/cache/raw" data/raw # raw downloads survive between releases
|
||||
[ -d data/raw/acl-anthology ] && git -C data/raw/acl-anthology pull --ff-only -q || true
|
||||
bash scripts/fetch_data.sh
|
||||
python3 scripts/ingest.py --raw data/raw --out build/papers.db
|
||||
python3 scripts/build_worktypes.py --db build/papers.db
|
||||
python3 scripts/export_jsonl.py --db build/papers.db --out build/export
|
||||
|
||||
# the export only depends on the data scripts, the hand labels and the raw sources
|
||||
KEY=$( { cat scripts/fetch_data.sh scripts/ingest.py scripts/taxonomy.py scripts/build_worktypes.py scripts/export_jsonl.py scripts/worktypes.json
|
||||
find data/labels -type f | sort | xargs cat; } | sha256sum | cut -c1-16)
|
||||
EXPORT="$ROOT/cache/export/$KEY"
|
||||
if [ "${REFRESH_DATA:-false}" != true ] && [ -f "$EXPORT/.complete" ]; then
|
||||
echo "data: reusing cached export $KEY (no data script changed; REFRESH_DATA is not set)"
|
||||
else
|
||||
echo "data: building export $KEY (refresh=${REFRESH_DATA:-false})"
|
||||
[ -d data/raw/acl-anthology ] && git -C data/raw/acl-anthology pull --ff-only -q || true
|
||||
bash scripts/fetch_data.sh
|
||||
python3 scripts/ingest.py --raw data/raw --out build/papers.db
|
||||
python3 scripts/build_worktypes.py --db build/papers.db
|
||||
python3 scripts/export_jsonl.py --db build/papers.db --out build/export
|
||||
rm -rf "$EXPORT"; cp -a build/export "$EXPORT"; touch "$EXPORT/.complete"
|
||||
ls -1dt "$ROOT"/cache/export/* | tail -n +3 | xargs -r rm -rf # keep the two newest
|
||||
fi
|
||||
EXPORT_ID=$(find "$EXPORT" -type f ! -name .complete | sort | xargs cat | sha256sum | cut -c1-16)
|
||||
|
||||
# ---- 3. site build + load into Postgres ----------------------------------------------
|
||||
npm ci --no-audit --no-fund
|
||||
LOCK=$( { cat package-lock.json; node -v; } | sha256sum | cut -c1-16)
|
||||
PREV=$(readlink -f "$ROOT/current" 2>/dev/null || true)
|
||||
if [ -n "$PREV" ] && [ "$PREV" != "$REL" ] && [ "$(cat "$PREV/node_modules/.lockhash" 2>/dev/null)" = "$LOCK" ]; then
|
||||
echo "node_modules: reusing the current release's (lockfile unchanged)"
|
||||
cp -al "$PREV/node_modules" node_modules # hard links: seconds, no extra disk
|
||||
else
|
||||
npm ci --no-audit --no-fund
|
||||
echo "$LOCK" > node_modules/.lockhash
|
||||
fi
|
||||
mkdir -p .next; ln -sfn "$ROOT/cache/next" .next/cache # compiler cache outlives the release
|
||||
export NEXT_TELEMETRY_DISABLED=1
|
||||
npm run build
|
||||
node scripts/load-pg.js --dir build/export
|
||||
|
||||
LIVE=$(PGPASSWORD=$PW psql -h 127.0.0.1 -p "$PGPORT" -U "$DB" -d "$DB" -qtAc "select 1 from information_schema.schemata where schema_name='live'" 2>/dev/null || true)
|
||||
if [ "$LIVE" = 1 ] && [ "$(cat "$ROOT/cache/loaded" 2>/dev/null)" = "$EXPORT_ID" ]; then
|
||||
echo "postgres: schema live already holds export $EXPORT_ID, load skipped"
|
||||
else
|
||||
node scripts/load-pg.js --dir "$EXPORT"
|
||||
echo "$EXPORT_ID" > "$ROOT/cache/loaded"
|
||||
fi
|
||||
rm -rf build
|
||||
|
||||
# ---- 4. switch + restart --------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user