Improve production deployment script to handle local changes with git stash
This commit is contained in:
@@ -6,24 +6,42 @@
|
||||
echo "=== Harheimer TC Deployment ==="
|
||||
echo ""
|
||||
|
||||
# 1. Git Pull
|
||||
echo "1. Pulling latest changes from git..."
|
||||
# 1. Handle local changes and Git Pull
|
||||
echo "1. Handling local changes and pulling latest from git..."
|
||||
|
||||
# Stash any local changes (including production data)
|
||||
echo " Stashing local changes..."
|
||||
git stash push -m "Production deployment stash $(date)"
|
||||
|
||||
# Pull latest changes
|
||||
echo " Pulling latest changes..."
|
||||
git pull
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "ERROR: Git pull failed!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 2. Backup Production Data
|
||||
# 2. Backup Production Data (from stash)
|
||||
echo ""
|
||||
echo "2. Backing up production data..."
|
||||
echo "2. Backing up production data from stash..."
|
||||
|
||||
# Create backup directory
|
||||
mkdir -p .backup
|
||||
|
||||
# Try to restore stashed data temporarily to backup it
|
||||
echo " Restoring stashed data for backup..."
|
||||
git stash show -p | git apply --index 2>/dev/null || echo " No stashed data to restore"
|
||||
|
||||
# Backup production data
|
||||
cp -r server/data .backup/data_backup 2>/dev/null || echo " No server/data to backup"
|
||||
cp public/data/termine.csv .backup/termine.csv 2>/dev/null || echo " No termine.csv to backup"
|
||||
cp public/data/mannschaften.csv .backup/mannschaften.csv 2>/dev/null || echo " No mannschaften.csv to backup"
|
||||
cp public/data/spielsysteme.csv .backup/spielsysteme.csv 2>/dev/null || echo " No spielsysteme.csv to backup"
|
||||
cp public/data/vereinsmeisterschaften.csv .backup/vereinsmeisterschaften.csv 2>/dev/null || echo " No vereinsmeisterschaften.csv to backup"
|
||||
|
||||
# Reset any changes from stash restore
|
||||
git reset --hard HEAD
|
||||
|
||||
# 3. Install dependencies
|
||||
echo ""
|
||||
echo "3. Installing dependencies..."
|
||||
@@ -56,11 +74,15 @@ cp .backup/mannschaften.csv public/data/mannschaften.csv 2>/dev/null || echo "No
|
||||
cp .backup/spielsysteme.csv public/data/spielsysteme.csv 2>/dev/null || echo "No spielsysteme.csv to restore"
|
||||
cp .backup/vereinsmeisterschaften.csv public/data/vereinsmeisterschaften.csv 2>/dev/null || echo "No vereinsmeisterschaften.csv to restore"
|
||||
|
||||
# 7. Cleanup backup
|
||||
# 7. Cleanup backup and stash
|
||||
echo ""
|
||||
echo "7. Cleaning up backup..."
|
||||
echo "7. Cleaning up backup and stash..."
|
||||
rm -rf .backup
|
||||
|
||||
# Clear the deployment stash (keep other stashes)
|
||||
echo " Clearing deployment stash..."
|
||||
git stash list | grep "Production deployment stash" | head -1 | cut -d: -f1 | xargs -r git stash drop
|
||||
|
||||
# 8. Restart PM2
|
||||
echo ""
|
||||
echo "8. Restarting PM2..."
|
||||
|
||||
Reference in New Issue
Block a user