CI: keep the node_modules cache outside the releases
Deploy / deploy (push) Successful in 3m45s

The first version looked for node_modules in the current release, which does not work when the same
commit is deployed again (its directory is replaced). Cache hard-linked installs under
/opt/llm-survey/cache/node_modules/<lock hash> instead.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FbMbJPadPzVwvt9rU9GBNo
This commit is contained in:
2026-10-24 00:05:07 +08:00
parent b705b7ab7e
commit 402a721790
+8 -6
View File
@@ -10,7 +10,7 @@
# 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.
# node_modules/<key> hard-linked copy of the installed dependencies, keyed by package-lock.json + node version.
set -eu
SHA="${1:?usage: deploy.sh <git-sha>}"
APP=llm-survey
@@ -87,13 +87,15 @@ EXPORT_ID=$(find "$EXPORT" -type f ! -name .complete | sort | xargs cat | sha256
# ---- 3. site build + load into Postgres ----------------------------------------------
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
NM="$ROOT/cache/node_modules/$LOCK"
if [ -f "$NM/.complete" ]; then
echo "node_modules: reusing cached install $LOCK (lockfile and node version unchanged)"
cp -al "$NM" node_modules && rm -f node_modules/.complete # hard links: seconds, no extra disk
else
npm ci --no-audit --no-fund
echo "$LOCK" > node_modules/.lockhash
mkdir -p "$ROOT/cache/node_modules"; rm -rf "$NM"
cp -al node_modules "$NM" && touch "$NM/.complete"
ls -1dt "$ROOT"/cache/node_modules/* | tail -n +3 | xargs -r rm -rf # keep the two newest
fi
mkdir -p .next; ln -sfn "$ROOT/cache/next" .next/cache # compiler cache outlives the release
export NEXT_TELEMETRY_DISABLED=1