This commit is contained in:
Dobromir Popov
2025-04-10 03:18:40 +03:00
parent 0d3914f3c6
commit bf43efe75d
2 changed files with 133 additions and 5 deletions

View File

@ -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