Update deploy-to-opt.sh to enhance npm cache management by excluding .npm and .npm-cache directories, and setting a custom npm cache directory during dependency installation and client build.

This commit is contained in:
Torsten Schulz (local)
2025-12-04 17:01:51 +01:00
parent c63c26bfe4
commit 34df89c1ac
2 changed files with 75 additions and 3 deletions

View File

@@ -38,7 +38,7 @@ if [ ! -d "$TARGET_DIR" ]; then
echo "✓ Verzeichnis erstellt"
fi
# Kopiere Dateien (ausschließlich node_modules, .git, dist, logs)
# Kopiere Dateien (ausschließlich node_modules, .git, dist, logs, npm cache)
echo "Kopiere Dateien nach $TARGET_DIR..."
rsync -av --progress \
--exclude 'node_modules' \
@@ -48,6 +48,8 @@ rsync -av --progress \
--exclude 'docroot/dist' \
--exclude 'logs' \
--exclude '.env' \
--exclude '.npm-cache' \
--exclude '.npm' \
"$SOURCE_DIR/" "$TARGET_DIR/"
echo "✓ Dateien kopiert"
@@ -62,10 +64,22 @@ echo ""
echo "Führe Installation in $TARGET_DIR durch..."
cd "$TARGET_DIR"
# Repariere npm Cache für www-data falls nötig
echo ""
echo "Prüfe npm Cache-Berechtigungen..."
if [ -d "/var/www/.npm" ]; then
chown -R $USER:$GROUP "/var/www/.npm" 2>/dev/null || true
fi
# Setze npm Cache auf ein Verzeichnis im App-Verzeichnis
NPM_CACHE_DIR="$TARGET_DIR/.npm-cache"
mkdir -p "$NPM_CACHE_DIR"
chown -R $USER:$GROUP "$NPM_CACHE_DIR"
# Installiere Dependencies
echo ""
echo "Installiere Dependencies..."
sudo -u $USER bash -c "cd '$TARGET_DIR' && npm run install:all"
sudo -u $USER bash -c "cd '$TARGET_DIR' && npm config set cache '$NPM_CACHE_DIR' && npm run install:all"
if [ $? -ne 0 ]; then
echo "FEHLER: Installation der Dependencies fehlgeschlagen!"
@@ -77,7 +91,7 @@ echo "✓ Dependencies installiert"
# Baue Client
echo ""
echo "Baue Client für Production..."
sudo -u $USER bash -c "cd '$TARGET_DIR' && npm run build"
sudo -u $USER bash -c "cd '$TARGET_DIR' && npm config set cache '$NPM_CACHE_DIR' && cd client && npm config set cache '$NPM_CACHE_DIR' && cd .. && npm run build"
if [ $? -ne 0 ]; then
echo "FEHLER: Build fehlgeschlagen!"