Spaces:
Runtime error
Runtime error
File size: 2,058 Bytes
32d4b56 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
#!/bin/bash
# Define the repository and branch
REPO_URL="https://github.com/UnseenSeven/GEMFINDER.git"
BRANCH="main"
APP_DIR="~/ai-dreams-x"
# Function to update the app.py file to remove the deprecated import
function fix_imports() {
# Navigate to the app directory
cd $APP_DIR
# Ensure the correct import
sed -i 's/from werkzeug.urls import url_quote/from urllib.parse import quote as url_quote/' app.py
# Stage and commit the changes
git add app.py
git commit -m "Remove deprecated Werkzeug import and use urllib.parse.quote"
git push origin $BRANCH
}
# Function to deploy the application
function deploy_app() {
cd $APP_DIR
# Force a new deployment by making a dummy change
touch deploy_trigger.txt
git add deploy_trigger.txt
git commit -m "Trigger redeployment"
git push origin $BRANCH
}
# Function to check deployment status
function check_deployment() {
# Check logs for specific errors
ERROR_LOG=$(render logs ai-dreams-x | grep "ImportError: cannot import name 'url_quote'")
if [ -n "$ERROR_LOG" ]; then
echo "Found ImportError, attempting to fix..."
return 1
else
echo "No ImportError found. Checking for other issues..."
return 0
fi
}
# Function to clean and redeploy
function clean_redeploy() {
# Clean and reinstall dependencies
rm -rf .venv
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
# Run the deployment
deploy_app
}
# Main loop
while true; do
# Pull latest changes
git pull origin $BRANCH
# Fix imports
fix_imports
# Deploy the application
deploy_app
# Wait for a few seconds to let deployment finish
sleep 60
# Check deployment status
check_deployment
DEPLOY_STATUS=$?
if [ $DEPLOY_STATUS -eq 0 ]; then
echo "Deployment successful!"
break
else
echo "Deployment failed. Retrying..."
clean_redeploy
fi
# Wait a bit before retrying
sleep 30
done
|