From 7d6a959a51b5235a6e3c1f7d8a4686076c69db12 Mon Sep 17 00:00:00 2001 From: Dobromir Popov Date: Mon, 8 Jul 2024 00:46:52 +0300 Subject: [PATCH] new try --- _deploy/entrypoint.sh | 52 +++++++++++++++++++++++++++++++------------ 1 file changed, 38 insertions(+), 14 deletions(-) diff --git a/_deploy/entrypoint.sh b/_deploy/entrypoint.sh index 24e9f27..3013e65 100644 --- a/_deploy/entrypoint.sh +++ b/_deploy/entrypoint.sh @@ -10,8 +10,10 @@ if [ "$UPDATE_CODE_FROM_GIT" = "true" ]; then mkdir /tmp/clone mkdir -p /app/logs + # Clear previous log + echo "Starting sync process at $(date)" > /app/logs/deploy.txt # Clone the repository - echo "\r\n\r\n Cloning repository..." | tee -a /app/logs/deploy.txt + echo "\r\n\r\n Cloning repository..." | tee -a logs/deploy.txt git clone -b ${GIT_BRANCH:-main} --depth 1 https://$GIT_USERNAME:${GIT_PASSWORD//@/%40}@git.d-popov.com/popov/mwitnessing.git /tmp/clone || exit 1 # Synchronize all files except package.json, package-lock.json, and the contents of /public/content @@ -19,22 +21,44 @@ if [ "$UPDATE_CODE_FROM_GIT" = "true" ]; then echo "\r\n\r\n Synchronizing files..." # rsync -av --update --exclude '/public/content' --exclude 'package.json' --exclude 'package-lock.json' /tmp/clone/ /app/ || echo "Rsync failed: Issue synchronizing files" | tee -a /app/logs/deploy.txt - # Clear previous log - echo "Starting sync process at $(date)" > /app/logs/deploy.txt +if [ -d "/app/public/content/permits" ]; then + mv /app/public/content/permits /tmp/content/permits + echo "Permits folder backed up successfully." | tee -a /app/logs/deploy.txt +else + echo "Permits folder not found, skipping backup." | tee -a /app/logs/deploy.txt +fi - # Run rsync with verbose output and itemize-changes - rsync -av --update --itemize-changes --exclude 'public/content' --exclude 'package.json' --exclude 'package-lock.json' /tmp/clone/ /app/ >> /app/logs/deploy.txt 2>&1 + # Run rsync with verbose output and itemize-changes +echo "Running rsync..." | tee -a /app/logs/deploy.txt +rsync -av --itemize-changes \ + --exclude='package.json' \ + --exclude='package-lock.json' \ + /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 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 +# Restore permits folder +echo "Restoring permits folder..." | tee -a /app/logs/deploy.txt +if [ -d "/tmp/content/permits" ]; then + # Ensure the destination directory exists + mkdir -p /app/public/content + mv /tmp/content/permits /app/public/content/permits + echo "Permits folder restored successfully." | tee -a /app/logs/deploy.txt +else + echo "No permits folder to restore." | 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 echo "\r\n\r\n Checking for changes in package files..."