Update Dockerfile
Browse files- Dockerfile +87 -26
Dockerfile
CHANGED
|
@@ -57,13 +57,6 @@ git config --global user.email "minecraft@huggingface.co"
|
|
| 57 |
git config --global user.name "Minecraft Bot"
|
| 58 |
git config --global init.defaultBranch main
|
| 59 |
|
| 60 |
-
# Check if this is a git repo, if not initialize
|
| 61 |
-
if [ ! -d .git ]; then
|
| 62 |
-
echo "๐ฆ Initializing git repository..."
|
| 63 |
-
git init
|
| 64 |
-
git remote add origin https://$GITHUB_TOKEN@github.com/Walukapah/mcserver.git
|
| 65 |
-
fi
|
| 66 |
-
|
| 67 |
# Ensure remote URL has token
|
| 68 |
git remote set-url origin https://$GITHUB_TOKEN@github.com/Walukapah/mcserver.git
|
| 69 |
|
|
@@ -82,7 +75,7 @@ echo "โ
Git configured successfully"
|
|
| 82 |
mkdir -p /app/logs
|
| 83 |
|
| 84 |
# ==========================================
|
| 85 |
-
# BACKUP SCRIPT (Fixed
|
| 86 |
# ==========================================
|
| 87 |
cat > /app/mcserver/backup.sh << 'BACKUPSCRIPT'
|
| 88 |
#!/bin/bash
|
|
@@ -104,7 +97,35 @@ if [ ! -d .git ]; then
|
|
| 104 |
exit 1
|
| 105 |
fi
|
| 106 |
|
| 107 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
if git diff --quiet && git diff --cached --quiet && [ -z "$(git ls-files --others --exclude-standard)" ]; then
|
| 109 |
echo "โน๏ธ No changes to backup"
|
| 110 |
exit 0
|
|
@@ -121,16 +142,47 @@ git commit -m "๐ฎ Auto backup: $(date '+%Y-%m-%d %H:%M:%S') | Server Data Back
|
|
| 121 |
exit 0
|
| 122 |
}
|
| 123 |
|
| 124 |
-
#
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
exit 1
|
| 130 |
-
}
|
| 131 |
|
| 132 |
-
|
| 133 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
BACKUPSCRIPT
|
| 135 |
|
| 136 |
chmod +x /app/mcserver/backup.sh
|
|
@@ -344,7 +396,7 @@ def start_minecraft():
|
|
| 344 |
threading.Thread(target=process_commands, daemon=True).start()
|
| 345 |
|
| 346 |
# ==========================================
|
| 347 |
-
# BACKUP API
|
| 348 |
# ==========================================
|
| 349 |
@app.route('/backup', methods=['POST'])
|
| 350 |
def manual_backup():
|
|
@@ -354,7 +406,7 @@ def manual_backup():
|
|
| 354 |
['/app/mcserver/backup.sh'],
|
| 355 |
capture_output=True,
|
| 356 |
text=True,
|
| 357 |
-
timeout=
|
| 358 |
cwd='/app/mcserver'
|
| 359 |
)
|
| 360 |
return {
|
|
@@ -376,15 +428,23 @@ def backup_status():
|
|
| 376 |
timeout=10,
|
| 377 |
cwd='/app/mcserver'
|
| 378 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 379 |
return {
|
| 380 |
'has_changes': len(result.stdout.strip()) > 0,
|
| 381 |
'status': result.stdout,
|
| 382 |
-
'branch':
|
| 383 |
-
|
| 384 |
-
capture_output=True,
|
| 385 |
-
text=True,
|
| 386 |
-
cwd='/app/mcserver'
|
| 387 |
-
).stdout.strip()
|
| 388 |
}
|
| 389 |
except Exception as e:
|
| 390 |
return {'error': str(e)}
|
|
@@ -1711,6 +1771,7 @@ echo "โจ๏ธ Real-time command typing preview enabled"
|
|
| 1711 |
echo "๐ Status modal with heartbeat icon added"
|
| 1712 |
echo "โ๏ธ GitHub Auto-backup every 5 minutes"
|
| 1713 |
echo "๐ง Manual backup button added to sidebar"
|
|
|
|
| 1714 |
echo "=========================================="
|
| 1715 |
|
| 1716 |
# Keep container alive
|
|
|
|
| 57 |
git config --global user.name "Minecraft Bot"
|
| 58 |
git config --global init.defaultBranch main
|
| 59 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
# Ensure remote URL has token
|
| 61 |
git remote set-url origin https://$GITHUB_TOKEN@github.com/Walukapah/mcserver.git
|
| 62 |
|
|
|
|
| 75 |
mkdir -p /app/logs
|
| 76 |
|
| 77 |
# ==========================================
|
| 78 |
+
# BACKUP SCRIPT (Fixed with Pull Before Push)
|
| 79 |
# ==========================================
|
| 80 |
cat > /app/mcserver/backup.sh << 'BACKUPSCRIPT'
|
| 81 |
#!/bin/bash
|
|
|
|
| 97 |
exit 1
|
| 98 |
fi
|
| 99 |
|
| 100 |
+
# ==========================================
|
| 101 |
+
# STEP 1: Fetch latest changes from GitHub
|
| 102 |
+
# ==========================================
|
| 103 |
+
echo "๐ Fetching latest changes from GitHub..."
|
| 104 |
+
git fetch origin main 2>&1 || git fetch origin master 2>&1 || {
|
| 105 |
+
echo "โ ๏ธ Warning: Could not fetch from remote"
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
# ==========================================
|
| 109 |
+
# STEP 2: Check for remote changes and pull if needed
|
| 110 |
+
# ==========================================
|
| 111 |
+
LOCAL=$(git rev-parse HEAD 2>/dev/null || echo "unknown")
|
| 112 |
+
REMOTE=$(git rev-parse origin/main 2>/dev/null || git rev-parse origin/master 2>/dev/null || echo "unknown")
|
| 113 |
+
|
| 114 |
+
if [ "$LOCAL" != "$REMOTE" ] && [ "$REMOTE" != "unknown" ]; then
|
| 115 |
+
echo "๐ฅ Remote has new changes, pulling first..."
|
| 116 |
+
# Stash local changes, pull, then apply stash
|
| 117 |
+
git stash push -m "auto-backup-stash" 2>/dev/null || true
|
| 118 |
+
git pull origin main --rebase 2>&1 || git pull origin master --rebase 2>&1 || {
|
| 119 |
+
echo "โ ๏ธ Warning: Pull failed, trying merge..."
|
| 120 |
+
git pull origin main 2>&1 || git pull origin master 2>&1 || true
|
| 121 |
+
}
|
| 122 |
+
# Try to pop stash
|
| 123 |
+
git stash pop 2>/dev/null || true
|
| 124 |
+
fi
|
| 125 |
+
|
| 126 |
+
# ==========================================
|
| 127 |
+
# STEP 3: Check for local changes
|
| 128 |
+
# ==========================================
|
| 129 |
if git diff --quiet && git diff --cached --quiet && [ -z "$(git ls-files --others --exclude-standard)" ]; then
|
| 130 |
echo "โน๏ธ No changes to backup"
|
| 131 |
exit 0
|
|
|
|
| 142 |
exit 0
|
| 143 |
}
|
| 144 |
|
| 145 |
+
# ==========================================
|
| 146 |
+
# STEP 4: Push with retry logic
|
| 147 |
+
# ==========================================
|
| 148 |
+
MAX_RETRIES=3
|
| 149 |
+
RETRY_COUNT=0
|
|
|
|
|
|
|
| 150 |
|
| 151 |
+
while [ $RETRY_COUNT -lt $MAX_RETRIES ]; do
|
| 152 |
+
# Fetch again to check if remote changed during commit
|
| 153 |
+
git fetch origin main 2>/dev/null || git fetch origin master 2>/dev/null || true
|
| 154 |
+
|
| 155 |
+
LOCAL=$(git rev-parse HEAD)
|
| 156 |
+
REMOTE=$(git rev-parse origin/main 2>/dev/null || git rev-parse origin/master 2>/dev/null || echo "unknown")
|
| 157 |
+
|
| 158 |
+
if [ "$LOCAL" != "$REMOTE" ] && [ "$REMOTE" != "unknown" ]; then
|
| 159 |
+
echo "๐ Remote changed during commit, pulling again..."
|
| 160 |
+
git stash push -m "auto-backup-stash-$RETRY_COUNT" 2>/dev/null || true
|
| 161 |
+
git pull origin main --rebase 2>&1 || git pull origin master --rebase 2>&1 || {
|
| 162 |
+
git pull origin main 2>&1 || git pull origin master 2>&1 || true
|
| 163 |
+
}
|
| 164 |
+
git stash pop 2>/dev/null || true
|
| 165 |
+
# Re-commit if needed
|
| 166 |
+
git add -A
|
| 167 |
+
git commit -m "๐ฎ Auto backup: $(date '+%Y-%m-%d %H:%M:%S') | Server Data Backup (retry $RETRY_COUNT)" || true
|
| 168 |
+
fi
|
| 169 |
+
|
| 170 |
+
# Try to push
|
| 171 |
+
if git push origin main 2>&1 || git push origin master 2>&1; then
|
| 172 |
+
echo "โ
[BACKUP] Successfully pushed to GitHub!"
|
| 173 |
+
echo ""
|
| 174 |
+
exit 0
|
| 175 |
+
fi
|
| 176 |
+
|
| 177 |
+
RETRY_COUNT=$((RETRY_COUNT + 1))
|
| 178 |
+
echo "โ ๏ธ Push failed, retrying... ($RETRY_COUNT/$MAX_RETRIES)"
|
| 179 |
+
sleep 2
|
| 180 |
+
done
|
| 181 |
+
|
| 182 |
+
echo "โ ERROR: Failed to push to GitHub after $MAX_RETRIES attempts!"
|
| 183 |
+
echo "๐ Local HEAD: $LOCAL"
|
| 184 |
+
echo "๐ Remote HEAD: $REMOTE"
|
| 185 |
+
exit 1
|
| 186 |
BACKUPSCRIPT
|
| 187 |
|
| 188 |
chmod +x /app/mcserver/backup.sh
|
|
|
|
| 396 |
threading.Thread(target=process_commands, daemon=True).start()
|
| 397 |
|
| 398 |
# ==========================================
|
| 399 |
+
# BACKUP API ENDPOINTS
|
| 400 |
# ==========================================
|
| 401 |
@app.route('/backup', methods=['POST'])
|
| 402 |
def manual_backup():
|
|
|
|
| 406 |
['/app/mcserver/backup.sh'],
|
| 407 |
capture_output=True,
|
| 408 |
text=True,
|
| 409 |
+
timeout=120,
|
| 410 |
cwd='/app/mcserver'
|
| 411 |
)
|
| 412 |
return {
|
|
|
|
| 428 |
timeout=10,
|
| 429 |
cwd='/app/mcserver'
|
| 430 |
)
|
| 431 |
+
branch_result = subprocess.run(
|
| 432 |
+
['git', 'branch', '--show-current'],
|
| 433 |
+
capture_output=True,
|
| 434 |
+
text=True,
|
| 435 |
+
cwd='/app/mcserver'
|
| 436 |
+
)
|
| 437 |
+
log_result = subprocess.run(
|
| 438 |
+
['git', 'log', '--oneline', '-5'],
|
| 439 |
+
capture_output=True,
|
| 440 |
+
text=True,
|
| 441 |
+
cwd='/app/mcserver'
|
| 442 |
+
)
|
| 443 |
return {
|
| 444 |
'has_changes': len(result.stdout.strip()) > 0,
|
| 445 |
'status': result.stdout,
|
| 446 |
+
'branch': branch_result.stdout.strip(),
|
| 447 |
+
'recent_commits': log_result.stdout.strip().split('\n') if log_result.stdout else []
|
|
|
|
|
|
|
|
|
|
|
|
|
| 448 |
}
|
| 449 |
except Exception as e:
|
| 450 |
return {'error': str(e)}
|
|
|
|
| 1771 |
echo "๐ Status modal with heartbeat icon added"
|
| 1772 |
echo "โ๏ธ GitHub Auto-backup every 5 minutes"
|
| 1773 |
echo "๐ง Manual backup button added to sidebar"
|
| 1774 |
+
echo "๐ Pull-before-push conflict resolution"
|
| 1775 |
echo "=========================================="
|
| 1776 |
|
| 1777 |
# Keep container alive
|