diff --git a/scripts/deploy.sh b/scripts/deploy.sh index f050f69..00e0619 100644 --- a/scripts/deploy.sh +++ b/scripts/deploy.sh @@ -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/ hard-linked copy of the installed dependencies, keyed by package-lock.json + node version. set -eu SHA="${1:?usage: deploy.sh }" 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