try deploy fix

This commit is contained in:
Dobromir Popov
2025-04-10 03:39:55 +03:00
parent bf43efe75d
commit ac9da25d64
2 changed files with 72 additions and 51 deletions

View File

@ -120,6 +120,27 @@ if [ "$UPDATE_CODE_FROM_GIT" = "true" ]; then
echo "Installing bcrypt package separately with build from source..." | tee -a /app/logs/deploy.txt
npm install bcrypt@latest --build-from-source --no-save --no-audit --no-fund || echo "Failed to install bcrypt, continuing anyway"
# Fix Prisma-specific issues
echo "Fixing Prisma-specific dependencies..." | tee -a /app/logs/deploy.txt
# Remove problematic Prisma nested dependencies
if [ -d "node_modules/@prisma" ]; then
echo "Cleaning up Prisma dependencies..." | tee -a /app/logs/deploy.txt
rm -rf node_modules/@prisma/internals/node_modules/@prisma/engines
rm -rf node_modules/@prisma/internals/node_modules/@prisma/engines-version
rm -rf node_modules/@prisma/client/node_modules/@prisma/engines-version
rm -rf node_modules/.prisma
fi
# Install specific Prisma versions known to work
echo "Installing specific Prisma versions..." | tee -a /app/logs/deploy.txt
npm uninstall prisma @prisma/client --no-save || true
npm install prisma@5.12.0 @prisma/client@5.12.0 --save-exact --no-audit --no-fund || echo "Failed to install Prisma, continuing anyway"
# Ensure Prisma engines are downloaded
echo "Generating Prisma client..." | tee -a /app/logs/deploy.txt
npx prisma generate --schema=./prisma/schema.prisma || echo "Failed to generate Prisma client, continuing anyway"
echo "\r\n\r\n Checking for changes in package files..."
# Determine if package.json or package-lock.json has changed
PACKAGE_CHANGE=0

View File

@ -1,72 +1,72 @@
#!/bin/bash
# Script to fix npm installation issues in a running container
# Run this script inside the container if you encounter npm package problems
# Fix npm and Prisma dependency issues
# Run this script when connected to the container to resolve installation problems
set -e
echo "====================================================="
echo "Running npm dependency fix script"
echo "====================================================="
LOG_FILE="/app/logs/npm-fix.log"
echo "[$(date)] Starting npm fix script" | tee -a $LOG_FILE
# Navigate to app directory
cd /app
echo "[$(date)] Working in directory: $(pwd)" | tee -a $LOG_FILE
# Create logs directory if it doesn't exist
mkdir -p /app/logs
LOG_FILE="/app/logs/npm-fix.log"
# Clean up problematic packages
echo "[$(date)] Removing problematic packages..." | tee -a $LOG_FILE
rm -rf node_modules/abbrev 2>/dev/null || true
rm -rf node_modules/bcrypt 2>/dev/null || true
rm -rf node_modules/.prisma 2>/dev/null || true
echo "Starting npm fix at $(date)" > "$LOG_FILE"
# Check for Node.js version
NODE_VERSION=$(node -v)
echo "Node.js version: $NODE_VERSION" | tee -a "$LOG_FILE"
# Clean up node_modules
echo "Cleaning up node_modules..." | tee -a "$LOG_FILE"
# Remove specific problematic packages
echo "Removing problematic packages..." | tee -a "$LOG_FILE"
rm -rf node_modules/abbrev
rm -rf node_modules/bcrypt
rm -rf node_modules/node-pre-gyp
rm -rf node_modules/.bin/node-pre-gyp
# Clean up Prisma nested modules
echo "[$(date)] Cleaning up Prisma dependencies..." | tee -a $LOG_FILE
rm -rf node_modules/@prisma/internals/node_modules/@prisma/engines 2>/dev/null || true
rm -rf node_modules/@prisma/internals/node_modules/@prisma/engines-version 2>/dev/null || true
rm -rf node_modules/@prisma/client/node_modules/@prisma/engines-version 2>/dev/null || true
# Clean npm cache
echo "Cleaning npm cache..." | tee -a "$LOG_FILE"
echo "[$(date)] Cleaning npm cache..." | tee -a $LOG_FILE
npm cache clean --force
# Install specific problematic packages individually
echo "Installing problematic packages individually..." | tee -a "$LOG_FILE"
# Fix nested node_modules issues
echo "[$(date)] Removing nested node_modules..." | tee -a $LOG_FILE
find node_modules -type d -name "node_modules" -not -path "node_modules" -exec rm -rf {} + 2>/dev/null || true
echo "Installing abbrev..." | tee -a "$LOG_FILE"
npm install abbrev@latest --no-save --no-audit --no-fund || echo "Failed to install abbrev" | tee -a "$LOG_FILE"
# Install critical packages individually
echo "[$(date)] Installing critical packages individually..." | tee -a $LOG_FILE
npm install abbrev@latest --no-save --no-audit --no-fund | tee -a $LOG_FILE
npm install bcrypt@latest --build-from-source --no-save --no-audit --no-fund | tee -a $LOG_FILE
echo "Installing bcrypt..." | tee -a "$LOG_FILE"
npm install bcrypt@latest --build-from-source --no-save --no-audit --no-fund || echo "Failed to install bcrypt" | tee -a "$LOG_FILE"
# Install specific Prisma versions
echo "[$(date)] Installing specific Prisma versions..." | tee -a $LOG_FILE
npm uninstall prisma @prisma/client --no-save | tee -a $LOG_FILE
npm install prisma@5.12.0 @prisma/client@5.12.0 --save-exact --no-audit --no-fund | tee -a $LOG_FILE
# Try reinstalling all dependencies
echo "Reinstalling all dependencies..." | tee -a "$LOG_FILE"
npm install --production --no-optional --legacy-peer-deps ||
npm install --production --no-optional --force ||
npm install --production --no-optional --no-package-lock ||
echo "WARNING: All npm install attempts failed" | tee -a "$LOG_FILE"
# Reinstall all dependencies with safer options
echo "[$(date)] Reinstalling all dependencies..." | tee -a $LOG_FILE
npm install --production --no-optional --legacy-peer-deps | tee -a $LOG_FILE
# Generate Prisma client
echo "Generating Prisma client..." | tee -a "$LOG_FILE"
npx prisma generate || echo "Failed to generate Prisma client" | tee -a "$LOG_FILE"
echo "[$(date)] Generating Prisma client..." | tee -a $LOG_FILE
npx prisma generate | tee -a $LOG_FILE
# Build Next.js application
echo "Building Next.js application..." | tee -a "$LOG_FILE"
npx next build || echo "Failed to build Next.js application" | tee -a "$LOG_FILE"
# Rebuild Next.js
echo "[$(date)] Building Next.js application..." | tee -a $LOG_FILE
npx next build | tee -a $LOG_FILE
echo "====================================================="
echo "Fix script completed at $(date)" | tee -a "$LOG_FILE"
echo "Check $LOG_FILE for detailed output"
echo "====================================================="
echo "[$(date)] Fix script completed. Check for any errors above." | tee -a $LOG_FILE
echo "[$(date)] You may need to restart the application now: npm start" | tee -a $LOG_FILE
echo "To restart the application, run:"
echo "1. Find the process ID: ps aux | grep 'npm start'"
echo "2. Kill the process: kill <PID>"
echo "3. Restart: npm start"
echo "Or use: pkill -f 'npm start' && npm start"
echo "====================================================="
# Print instructions for running the script in the background
cat << "EOF"
To run this script in the background (detached from terminal):
nohup /app/_deploy/fix-npm-issues.sh > /app/logs/npm-fix.log 2>&1 &
To monitor progress:
tail -f /app/logs/npm-fix.log
To restart the application after fixing:
pkill -f "npm start" || true
nohup npm start > /app/logs/app.log 2>&1 &
EOF