modifying /usr/local/bin/entrypoint.sh in the dockerfile as it is the real file
mwhitnessing.git renamed to mwitnessing.git
This commit is contained in:
@ -14,51 +14,58 @@ if [ "$UPDATE_CODE_FROM_GIT" = "true" ]; then
|
||||
echo "Starting sync process at $(date)" > /app/logs/deploy.txt
|
||||
# Clone the repository
|
||||
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
|
||||
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
|
||||
# rsync -av --filter='P /public/content/' --exclude 'package.json' --exclude 'package-lock.json' /tmp/clone/ /app/ || echo "Rsync failed: Issue synchronizing files"
|
||||
echo "\r\n\r\n Synchronizing files..."
|
||||
rsync -av /tmp/clone/_deploy/entrypoint.sh /app/entrypoint.sh || echo "Rsync failed: Issue copying entrypoint.sh"
|
||||
|
||||
|
||||
|
||||
# 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
|
||||
|
||||
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
|
||||
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
|
||||
########################################################################################
|
||||
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
|
||||
|
||||
# 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
|
||||
# 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
|
||||
|
||||
# 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 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 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
|
||||
# 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..."
|
||||
|
43
_deploy/entrypoint.staging.sh
Normal file
43
_deploy/entrypoint.staging.sh
Normal file
@ -0,0 +1,43 @@
|
||||
# Check if the environment variable to update code from git is set to true
|
||||
if [ "$UPDATE_CODE_FROM_GIT" = "true" ]; then
|
||||
# Install necessary packages
|
||||
apk add git nano rsync
|
||||
echo "Updating code from git.d-popov.com...(as '$GIT_USERNAME')"
|
||||
|
||||
# Remove the previous clone directory to ensure a fresh start
|
||||
rm -rf /tmp/clone
|
||||
mkdir /tmp/clone
|
||||
|
||||
# Clone the specific branch of the new repository
|
||||
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
|
||||
# Fetch the latest commit ID and message from the cloned repository
|
||||
GIT_COMMIT_ID=$(git -C /tmp/clone rev-parse HEAD)
|
||||
LAST_COMMIT_MESSAGE=$(git -C /tmp/clone log -1 --pretty=%B)
|
||||
echo "Current Git Commit: $LAST_COMMIT_MESSAGE: $GIT_COMMIT_ID"
|
||||
export GIT_COMMIT_ID
|
||||
|
||||
# Use rsync to synchronize the files to /app, including deletion of files not in the source
|
||||
rsync -av --delete --exclude '/public/content' /tmp/clone/ /app/ || echo "Rsync failed: Issue synchronizing files"
|
||||
# Copy .env files
|
||||
rsync -av /tmp/clone/.env* /app/ || echo "Rsync failed: Issue copying .env files"
|
||||
# Copy the entrypoint.sh if exists in the new structure
|
||||
[ -f /tmp/clone/entrypoint.sh ] && rsync -av /tmp/clone/entrypoint.sh /app/entrypoint.sh || echo "Rsync failed: Issue copying entrypoint.sh"
|
||||
chmod +x /app/entrypoint.sh
|
||||
|
||||
# Clean up the temporary clone directory
|
||||
rm -rf /tmp/clone
|
||||
|
||||
cd /app
|
||||
echo "Installing packages in /app"
|
||||
npm install --no-audit --no-fund --no-optional --omit=optional
|
||||
yes | npx prisma generate
|
||||
# Uncomment the next line if database migrations are necessary
|
||||
# npx prisma migrate deploy
|
||||
echo "Done cloning. Current Git Commit ID: $GIT_COMMIT_ID"
|
||||
# Uncomment the following lines for production deployment
|
||||
# npx next build
|
||||
# npx next start
|
||||
fi
|
||||
|
||||
echo "Running the main process"
|
||||
exec "$@"
|
Reference in New Issue
Block a user