Some checks failed
Deploy to Production / Build and Deploy (push) Failing after 2m15s
Removed silent fallback that was hiding migration failures. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
85 lines
2.0 KiB
Bash
85 lines
2.0 KiB
Bash
#!/bin/bash
|
|
set -e
|
|
|
|
echo "🚀 Starting Document Translation API..."
|
|
|
|
# Wait for database to be ready (if DATABASE_URL is set)
|
|
if [ -n "$DATABASE_URL" ]; then
|
|
echo "⏳ Waiting for database to be ready..."
|
|
|
|
# Extract host and port from DATABASE_URL (handles postgresql+asyncpg:// and postgresql://)
|
|
DB_HOST=$(python -c "
|
|
import re
|
|
m = re.search(r'@([^:/]+)', '$DATABASE_URL')
|
|
print(m.group(1) if m else 'postgres')
|
|
")
|
|
DB_PORT=$(python -c "
|
|
import re
|
|
m = re.search(r'@[^:]+:(\d+)', '$DATABASE_URL')
|
|
print(m.group(1) if m else '5432')
|
|
")
|
|
|
|
echo " Connecting to ${DB_HOST}:${DB_PORT}..."
|
|
|
|
# Wait up to 30 seconds for database
|
|
for i in $(seq 1 30); do
|
|
if python -c "
|
|
import socket
|
|
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
try:
|
|
s.connect(('$DB_HOST', int('$DB_PORT')))
|
|
s.close()
|
|
exit(0)
|
|
except:
|
|
exit(1)
|
|
" 2>/dev/null; then
|
|
echo "✅ Database is ready!"
|
|
break
|
|
fi
|
|
echo " Waiting for database... ($i/30)"
|
|
sleep 1
|
|
done
|
|
|
|
# Run database migrations
|
|
echo "📦 Running database migrations..."
|
|
alembic upgrade head
|
|
echo "✅ Migrations applied successfully"
|
|
fi
|
|
|
|
# Wait for Redis if configured
|
|
if [ -n "$REDIS_URL" ]; then
|
|
echo "⏳ Waiting for Redis..."
|
|
REDIS_HOST=$(python -c "
|
|
import re
|
|
m = re.search(r'://([^:/]+)', '$REDIS_URL')
|
|
print(m.group(1) if m else 'redis')
|
|
")
|
|
REDIS_PORT=$(python -c "
|
|
import re
|
|
m = re.search(r'://[^:]+:(\d+)', '$REDIS_URL')
|
|
print(m.group(1) if m else '6379')
|
|
")
|
|
|
|
for i in $(seq 1 10); do
|
|
if python -c "
|
|
import socket
|
|
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
try:
|
|
s.connect(('$REDIS_HOST', int('$REDIS_PORT')))
|
|
s.close()
|
|
exit(0)
|
|
except:
|
|
exit(1)
|
|
" 2>/dev/null; then
|
|
echo "✅ Redis is ready!"
|
|
break
|
|
fi
|
|
echo " Waiting for Redis... ($i/10)"
|
|
sleep 1
|
|
done
|
|
fi
|
|
|
|
# Start the application
|
|
echo "🎯 Starting uvicorn..."
|
|
exec uvicorn main:app --host 0.0.0.0 --port ${PORT:-8000} --workers ${WORKERS:-4}
|