merge permits folder instead of only keeping server's

This commit is contained in:
Dobromir Popov
2025-04-10 02:04:53 +03:00
parent 8f066c17e7
commit fe96003eee

View File

@ -30,17 +30,17 @@ if [ "$UPDATE_CODE_FROM_GIT" = "true" ]; then
# Backup permits folder if it exists # Backup permits folder if it exists
mkdir -p /tmp/content mkdir -p /tmp/content
if [ -d "/app/public/content/permits" ]; then if [ -d "/app/public/content/permits" ]; then
echo "Backing up permits folder..." | tee -a /app/logs/deploy.txt echo "Backing up server permits folder..." | tee -a /app/logs/deploy.txt
cp -r /app/public/content/permits /tmp/content/ cp -r /app/public/content/permits /tmp/content/
echo "Permits folder backed up successfully." | tee -a /app/logs/deploy.txt echo "Server permits folder backed up successfully." | tee -a /app/logs/deploy.txt
ls -la /tmp/content/permits >> /app/logs/deploy.txt 2>&1 ls -la /tmp/content/permits >> /app/logs/deploy.txt 2>&1
else else
echo "Permits folder not found, will create it after deployment." | tee -a /app/logs/deploy.txt echo "Server permits folder not found, will create it after deployment." | tee -a /app/logs/deploy.txt
mkdir -p /tmp/content/permits mkdir -p /tmp/content/permits
fi fi
# Run rsync with verbose output and itemize-changes # Run rsync with verbose output and itemize-changes, excluding the permits folder
echo "Running rsync..." | tee -a /app/logs/deploy.txt echo "Running rsync for main codebase..." | tee -a /app/logs/deploy.txt
rsync -av --itemize-changes \ rsync -av --itemize-changes \
--exclude='package.json' \ --exclude='package.json' \
--exclude='package-lock.json' \ --exclude='package-lock.json' \
@ -48,33 +48,37 @@ if [ "$UPDATE_CODE_FROM_GIT" = "true" ]; then
--exclude='/public/content/uploads' \ --exclude='/public/content/uploads' \
/tmp/clone/ /app/ >> /app/logs/deploy.txt 2>&1 /tmp/clone/ /app/ >> /app/logs/deploy.txt 2>&1
# Check rsync exit status # Check if the Git project contains a permits folder
if [ $? -ne 0 ]; then if [ -d "/tmp/clone/public/content/permits" ] && [ "$(ls -A /tmp/clone/public/content/permits)" ]; then
echo "Rsync failed: Issue synchronizing files" | tee -a /app/logs/deploy.txt echo "Found permits files in Git project, preparing to merge..." | tee -a /app/logs/deploy.txt
cat /app/logs/deploy.txt # Display the log contents # Create a temporary directory for Git project permits files
mkdir -p /tmp/git_permits
cp -r /tmp/clone/public/content/permits/* /tmp/git_permits/ 2>/dev/null || true
ls -la /tmp/git_permits >> /app/logs/deploy.txt 2>&1
else else
echo "Rsync completed successfully" | tee -a /app/logs/deploy.txt echo "No permits files found in Git project." | 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 fi
# Restore permits folder # Restore/merge permits folder
echo "Restoring permits folder..." | tee -a /app/logs/deploy.txt echo "Restoring and merging permits folders..." | tee -a /app/logs/deploy.txt
# Always ensure the destination directory exists # Ensure the destination directory exists
mkdir -p /app/public/content mkdir -p /app/public/content/permits
# Make sure the backed up permits exist before copying
# First restore the server permits
if [ -d "/tmp/content/permits" ]; then if [ -d "/tmp/content/permits" ]; then
cp -r /tmp/content/permits /app/public/content/ cp -r /tmp/content/permits/* /app/public/content/permits/ 2>/dev/null || true
echo "Permits folder restored successfully." | tee -a /app/logs/deploy.txt echo "Server permits restored." | tee -a /app/logs/deploy.txt
ls -la /app/public/content/permits >> /app/logs/deploy.txt 2>&1 fi
else
echo "ERROR: Backup permits folder not found. Creating empty directory." | tee -a /app/logs/deploy.txt # Then merge in the Git project permits (will overwrite if same filename)
mkdir -p /app/public/content/permits if [ -d "/tmp/git_permits" ] && [ "$(ls -A /tmp/git_permits)" ]; then
cp -r /tmp/git_permits/* /app/public/content/permits/ 2>/dev/null || true
echo "Git project permits merged." | tee -a /app/logs/deploy.txt
fi fi
# Check contents after restoration # Check contents after restoration and merge
echo "Contents of /app/public/content after restoration:" >> /app/logs/deploy.txt echo "Contents of merged permits folder:" >> /app/logs/deploy.txt
ls -la /app/public/content >> /app/logs/deploy.txt 2>&1 ls -la /app/public/content/permits >> /app/logs/deploy.txt 2>&1
######################################################################################## ########################################################################################