rag-kb-system / scripts /deploy_to_hf.sh
duqing2026's picture
同步 hf
9ed89c8
#!/bin/bash
# Configuration
MAX_RETRIES=3
LOG_FILE="deploy.log"
REMOTE_URL="git@hf.co:spaces/duqing2026/rag-kb-demo"
# Function to log messages
log_message() {
local timestamp=$(date "+%Y-%m-%d %H:%M:%S")
echo "[$timestamp] $1" | tee -a "$LOG_FILE"
}
# 1. Configure Git LFS to skip lock verification (Fixes the specific error)
log_message "Configuring Git LFS settings..."
git config lfs.locksverify false
git config lfs.https://hf.co/spaces/duqing2026/rag-kb-demo.git/info/lfs.locksverify false
# 2. Check network connectivity (Simple check)
log_message "Checking network connectivity..."
if ping -c 1 hf.co &> /dev/null; then
log_message "Network connection to hf.co confirmed."
else
log_message "Warning: Could not ping hf.co, but proceeding with push attempt..."
fi
# 3. Push with retry logic
attempt=1
while [ $attempt -le $MAX_RETRIES ]; do
log_message "Starting push attempt $attempt of $MAX_RETRIES..."
# Try to push both LFS objects and git refs
# Using -u origin main to ensure upstream tracking
if git push -u origin main; then
log_message "Upload successful!"
exit 0
else
exit_code=$?
log_message "Upload failed with exit code $exit_code."
if [ $attempt -lt $MAX_RETRIES ]; then
wait_time=$((attempt * 5))
log_message "Waiting $wait_time seconds before retrying..."
sleep $wait_time
((attempt++))
else
log_message "All $MAX_RETRIES attempts failed."
# 4. Fallback: Save to local cache status (User Option 3)
log_message "Executing fallback: Marking as pending upload in local cache..."
# Create status file
cat > upload_status.json <<EOF
{
"status": "pending_upload",
"last_attempt": "$(date -u +"%Y-%m-%dT%H:%M:%SZ")",
"retry_count": $MAX_RETRIES,
"error_log": "$LOG_FILE",
"reason": "Network connection refused after multiple retries"
}
EOF
log_message "Status saved to upload_status.json"
log_message "Deployment process completed with pending status."
exit 0 # Exit cleanly as we handled the error gracefully
fi
fi
done