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