Scope npm install lock to bootstrap phase only

This commit is contained in:
Ruslan Bakiev
2026-02-20 00:41:56 +07:00
parent 7f74d5f611
commit 938c06240e
2 changed files with 43 additions and 35 deletions

View File

@@ -6,7 +6,6 @@ cd "$(dirname "$0")/.."
# Serialize dependency install when multiple containers share the same workspace. # Serialize dependency install when multiple containers share the same workspace.
LOCK_FILE=/app/Frontend/.npm-install.lock LOCK_FILE=/app/Frontend/.npm-install.lock
exec 9>"$LOCK_FILE" exec 9>"$LOCK_FILE"
flock 9
# Prevent path leakage between host Nuxt build cache and Docker runtime. # Prevent path leakage between host Nuxt build cache and Docker runtime.
# If any cache contains absolute /Users/... imports, Nitro dev runtime can break in /app. # If any cache contains absolute /Users/... imports, Nitro dev runtime can break in /app.
@@ -15,24 +14,29 @@ find .nuxt -mindepth 1 -maxdepth 1 -exec rm -rf {} + || true
find .output -mindepth 1 -maxdepth 1 -exec rm -rf {} + || true find .output -mindepth 1 -maxdepth 1 -exec rm -rf {} + || true
rm -rf node_modules/.cache node_modules/.vite rm -rf node_modules/.cache node_modules/.vite
# Install deps (container starts from a clean image). # Only installation steps are serialized; runtime must not hold the lock.
# This workspace has mixed Apollo/Nuxt peer graphs; keep install deterministic in Docker. (
npm install --legacy-peer-deps flock 9
# sharp is a native module and can break when cached node_modules were installed # Install deps (container starts from a clean image).
# for a different CPU variant (for example arm64v8). Force a local rebuild. # This workspace has mixed Apollo/Nuxt peer graphs; keep install deterministic in Docker.
ARCH="$(uname -m)" npm install --legacy-peer-deps
if [ "$ARCH" = "aarch64" ] || [ "$ARCH" = "arm64" ]; then
npm rebuild sharp --platform=linux --arch=arm64v8 \ # sharp is a native module and can break when cached node_modules were installed
|| npm rebuild sharp --platform=linux --arch=arm64 \ # for a different CPU variant (for example arm64v8). Force a local rebuild.
|| npm install sharp --platform=linux --arch=arm64v8 --save-exact=false \ ARCH="$(uname -m)"
|| npm install sharp --platform=linux --arch=arm64 --save-exact=false if [ "$ARCH" = "aarch64" ] || [ "$ARCH" = "arm64" ]; then
elif [ "$ARCH" = "x86_64" ] || [ "$ARCH" = "amd64" ]; then npm rebuild sharp --platform=linux --arch=arm64v8 \
npm rebuild sharp --platform=linux --arch=x64 \ || npm rebuild sharp --platform=linux --arch=arm64 \
|| npm install sharp --platform=linux --arch=x64 --save-exact=false || npm install sharp --platform=linux --arch=arm64v8 --save-exact=false \
else || npm install sharp --platform=linux --arch=arm64 --save-exact=false
npm rebuild sharp || true elif [ "$ARCH" = "x86_64" ] || [ "$ARCH" = "amd64" ]; then
fi npm rebuild sharp --platform=linux --arch=x64 \
|| npm install sharp --platform=linux --arch=x64 --save-exact=false
else
npm rebuild sharp || true
fi
)
# Wait until PostgreSQL is reachable before applying schema. # Wait until PostgreSQL is reachable before applying schema.
until node -e "const u=new URL(process.env.DATABASE_URL||''); const net=require('net'); const s=net.createConnection({host:u.hostname,port:Number(u.port||5432)}); s.on('connect',()=>{s.end(); process.exit(0);}); s.on('error',()=>process.exit(1)); setTimeout(()=>process.exit(1), 1000);" ; do until node -e "const u=new URL(process.env.DATABASE_URL||''); const net=require('net'); const s=net.createConnection({host:u.hostname,port:Number(u.port||5432)}); s.on('connect',()=>{s.end(); process.exit(0);}); s.on('error',()=>process.exit(1)); setTimeout(()=>process.exit(1), 1000);" ; do

View File

@@ -6,24 +6,28 @@ cd "$(dirname "$0")/.."
# Serialize dependency install when multiple containers share the same workspace. # Serialize dependency install when multiple containers share the same workspace.
LOCK_FILE=/app/Frontend/.npm-install.lock LOCK_FILE=/app/Frontend/.npm-install.lock
exec 9>"$LOCK_FILE" exec 9>"$LOCK_FILE"
flock 9
# Worker container starts from clean image. # Only dependency bootstrap is serialized; worker runtime must not hold the lock.
# Install deps without frontend postinstall hooks (nuxt prepare) to keep worker lean/stable. (
npm install --ignore-scripts --legacy-peer-deps flock 9
ARCH="$(uname -m)"
if [ "$ARCH" = "aarch64" ] || [ "$ARCH" = "arm64" ]; then # Worker container starts from clean image.
npm rebuild sharp --platform=linux --arch=arm64v8 \ # Install deps without frontend postinstall hooks (nuxt prepare) to keep worker lean/stable.
|| npm rebuild sharp --platform=linux --arch=arm64 \ npm install --ignore-scripts --legacy-peer-deps
|| npm install sharp --platform=linux --arch=arm64v8 --save-exact=false \ ARCH="$(uname -m)"
|| npm install sharp --platform=linux --arch=arm64 --save-exact=false if [ "$ARCH" = "aarch64" ] || [ "$ARCH" = "arm64" ]; then
elif [ "$ARCH" = "x86_64" ] || [ "$ARCH" = "amd64" ]; then npm rebuild sharp --platform=linux --arch=arm64v8 \
npm rebuild sharp --platform=linux --arch=x64 \ || npm rebuild sharp --platform=linux --arch=arm64 \
|| npm install sharp --platform=linux --arch=x64 --save-exact=false || npm install sharp --platform=linux --arch=arm64v8 --save-exact=false \
else || npm install sharp --platform=linux --arch=arm64 --save-exact=false
npm rebuild sharp || true elif [ "$ARCH" = "x86_64" ] || [ "$ARCH" = "amd64" ]; then
fi npm rebuild sharp --platform=linux --arch=x64 \
npx prisma generate || npm install sharp --platform=linux --arch=x64 --save-exact=false
else
npm rebuild sharp || true
fi
npx prisma generate
)
# Ensure DB is reachable before the worker starts consuming jobs. # Ensure DB is reachable before the worker starts consuming jobs.
until node -e "const u=new URL(process.env.DATABASE_URL||''); const net=require('net'); const s=net.createConnection({host:u.hostname,port:Number(u.port||5432)}); s.on('connect',()=>{s.end(); process.exit(0);}); s.on('error',()=>process.exit(1)); setTimeout(()=>process.exit(1), 1000);" ; do until node -e "const u=new URL(process.env.DATABASE_URL||''); const net=require('net'); const s=net.createConnection({host:u.hostname,port:Number(u.port||5432)}); s.on('connect',()=>{s.end(); process.exit(0);}); s.on('error',()=>process.exit(1)); setTimeout(()=>process.exit(1), 1000);" ; do