scripts
This commit is contained in:
@ -48,6 +48,16 @@ if [ "$UPDATE_CODE_FROM_GIT" = "true" ]; then
|
||||
--exclude='/public/content/uploads' \
|
||||
/tmp/clone/ /app/ >> /app/logs/deploy.txt 2>&1
|
||||
|
||||
# Check rsync exit status
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Rsync failed: Issue synchronizing files" | tee -a /app/logs/deploy.txt
|
||||
cat /app/logs/deploy.txt # Display the log contents
|
||||
else
|
||||
echo "Rsync completed successfully" | tee -a /app/logs/deploy.txt
|
||||
echo "Last few lines of rsync log:" | tee -a /app/logs/deploy.txt
|
||||
tail -n 20 /app/logs/deploy.txt # Display the last 20 lines of the log
|
||||
fi
|
||||
|
||||
# Check if the Git project contains a permits folder
|
||||
if [ -d "/tmp/clone/public/content/permits" ] && [ "$(ls -A /tmp/clone/public/content/permits)" ]; then
|
||||
echo "Found permits files in Git project, preparing to merge..." | tee -a /app/logs/deploy.txt
|
||||
@ -82,6 +92,34 @@ if [ "$UPDATE_CODE_FROM_GIT" = "true" ]; then
|
||||
########################################################################################
|
||||
|
||||
|
||||
echo "\r\n\r\n Fixing problematic npm packages..." | tee -a /app/logs/deploy.txt
|
||||
cd /app
|
||||
|
||||
# Remove problematic node_modules if they exist
|
||||
if [ -d "node_modules/abbrev" ]; then
|
||||
echo "Removing problematic abbrev package..." | tee -a /app/logs/deploy.txt
|
||||
rm -rf node_modules/abbrev
|
||||
fi
|
||||
|
||||
if [ -d "node_modules/bcrypt" ]; then
|
||||
echo "Removing problematic bcrypt package..." | tee -a /app/logs/deploy.txt
|
||||
rm -rf node_modules/bcrypt
|
||||
fi
|
||||
|
||||
# Ensure clean node_modules state
|
||||
if [ -d "node_modules" ]; then
|
||||
echo "Cleaning up node_modules..." | tee -a /app/logs/deploy.txt
|
||||
find node_modules -type d -name "node_modules" -not -path "node_modules" -exec rm -rf {} + 2>/dev/null || true
|
||||
find node_modules -name "*.node" -type f -delete 2>/dev/null || true
|
||||
fi
|
||||
|
||||
# Install problematic packages individually
|
||||
echo "Installing abbrev package separately..." | tee -a /app/logs/deploy.txt
|
||||
npm install abbrev@latest --no-save --no-audit --no-fund || echo "Failed to install abbrev, continuing anyway"
|
||||
|
||||
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"
|
||||
|
||||
echo "\r\n\r\n Checking for changes in package files..."
|
||||
# Determine if package.json or package-lock.json has changed
|
||||
PACKAGE_CHANGE=0
|
||||
@ -91,18 +129,36 @@ if [ "$UPDATE_CODE_FROM_GIT" = "true" ]; then
|
||||
|
||||
# If package.json or package-lock.json has changed, copy them and reinstall node_modules
|
||||
if [ "$PACKAGE_CHANGE" -eq 1 ]; then
|
||||
echo "Package files have changed. Updating packages..."
|
||||
echo "Package files have changed. Updating packages..." | tee -a /app/logs/deploy.txt
|
||||
rsync -av /tmp/clone/package.json /app/package.json || echo "Rsync failed: Issue copying package.json"
|
||||
rsync -av /tmp/clone/package-lock.json /app/package-lock.json || echo "Rsync failed: Issue copying package-lock.json"
|
||||
|
||||
echo "Cleaning node_modules directory..." | tee -a /app/logs/deploy.txt
|
||||
rm -rf /app/node_modules
|
||||
yes | npx prisma generate
|
||||
|
||||
# Clean npm cache
|
||||
echo "Cleaning npm cache..." | tee -a /app/logs/deploy.txt
|
||||
npm cache clean --force
|
||||
|
||||
echo "Installing dependencies with safer options..." | tee -a /app/logs/deploy.txt
|
||||
# Try different installation strategies in case of failure
|
||||
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, continuing with deployment" | tee -a /app/logs/deploy.txt
|
||||
|
||||
# Generate Prisma client
|
||||
echo "Generating Prisma client..." | tee -a /app/logs/deploy.txt
|
||||
npx prisma generate || echo "WARNING: Prisma generate failed" | tee -a /app/logs/deploy.txt
|
||||
else
|
||||
echo "Package files have not changed. Skipping package installation."
|
||||
echo "Package files have not changed. Skipping package installation." | tee -a /app/logs/deploy.txt
|
||||
fi
|
||||
|
||||
cd /app
|
||||
npm install --no-audit --no-fund --no-optional --omit=optional
|
||||
npx next build
|
||||
|
||||
# Build the Next.js application
|
||||
echo "Building Next.js application..." | tee -a /app/logs/deploy.txt
|
||||
npx next build || echo "WARNING: Next.js build failed" | tee -a /app/logs/deploy.txt
|
||||
|
||||
# Clean up
|
||||
# rm -rf /tmp/clone
|
||||
|
72
_deploy/fix-npm-issues.sh
Normal file
72
_deploy/fix-npm-issues.sh
Normal file
@ -0,0 +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
|
||||
|
||||
set -e
|
||||
|
||||
echo "====================================================="
|
||||
echo "Running npm dependency fix script"
|
||||
echo "====================================================="
|
||||
|
||||
# Navigate to app directory
|
||||
cd /app
|
||||
|
||||
# Create logs directory if it doesn't exist
|
||||
mkdir -p /app/logs
|
||||
LOG_FILE="/app/logs/npm-fix.log"
|
||||
|
||||
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 npm cache
|
||||
echo "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"
|
||||
|
||||
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"
|
||||
|
||||
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"
|
||||
|
||||
# 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"
|
||||
|
||||
# Generate Prisma client
|
||||
echo "Generating Prisma client..." | tee -a "$LOG_FILE"
|
||||
npx prisma generate || echo "Failed to generate Prisma client" | 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"
|
||||
|
||||
echo "====================================================="
|
||||
echo "Fix script completed at $(date)" | tee -a "$LOG_FILE"
|
||||
echo "Check $LOG_FILE for detailed output"
|
||||
echo "====================================================="
|
||||
|
||||
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 "====================================================="
|
Reference in New Issue
Block a user