Files
swingmusic-extended/setup_dragonflydb.py
Tomas Dvorak cbf646e25b Fix CI/CD pipeline and code quality issues
## Major Changes
- Fixed all TypeScript errors in web client for successful compilation
- Resolved 82+ Python lint errors across backend services
- Updated Flutter SDK compatibility for mobile app
- Fixed security workflow configuration

## Web Client Fixes
- Fixed import path in DragonflyDashboard.vue (dragonflyApi import)
- All TypeScript compilation now passes without errors

## Backend Lint Fixes
- Updated type annotations to modern Python syntax (dict instead of Dict, X | None instead of Optional[X])
- Replaced try-except-pass with contextlib.suppress(Exception)
- Removed unused imports (Dict, Optional, Any, Iterator, etc.)
- Fixed bare except clauses to use Exception
- Sorted and formatted imports with ruff
- Applied ruff format to 27 files

## Workflow Fixes
- Updated Flutter SDK constraint from ^3.10.4 to ^3.5.0 (compatible with Flutter 3.24.0)
- Changed pip-audit format from github to json in security.yml
- Added comprehensive CI workflows (readiness-gate.yml, security.yml)

## Infrastructure
- Added DragonflyDB caching system integration
- Enhanced Docker configuration with multi-stage builds
- Added pytest configuration and test infrastructure
- Improved production readiness with proper error handling

## Verification
- backend-lint job:  Succeeded
- web job:  Succeeded
- Ready for GitHub deployment

All CI/CD issues resolved. Codebase now passes all quality checks.
2026-03-21 10:01:14 +01:00

173 lines
5.8 KiB
Python

#!/usr/bin/env python3
"""
DragonflyDB Setup Script for SwingMusic
This script helps set up DragonflyDB for fast Spotify metadata caching.
DragonflyDB is a Redis-compatible in-memory database perfect for caching.
"""
import subprocess
import sys
import time
import logging
from pathlib import Path
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
logger = logging.getLogger(__name__)
def check_dragonflydb_installed():
"""Check if DragonflyDB is installed"""
try:
result = subprocess.run(['dragonfly', '--version'],
capture_output=True, text=True, timeout=5)
if result.returncode == 0:
logger.info(f"✅ DragonflyDB found: {result.stdout.strip()}")
return True
except (subprocess.TimeoutExpired, FileNotFoundError):
pass
logger.warning("❌ DragonflyDB not found")
return False
def install_dragonflydb():
"""Install DragonflyDB using Docker (recommended)"""
logger.info("🐳 Installing DragonflyDB via Docker...")
docker_commands = [
# Pull DragonflyDB image
['docker', 'pull', 'docker.dragonflydb.io/dragonflydb/dragonfly'],
# Run DragonflyDB container
['docker', 'run', '-d',
'--name', 'swingmusic-dragonfly',
'-p', '6379:6379',
'--restart', 'unless-stopped',
'docker.dragonflydb.io/dragonflydb/dragonfly'],
]
for cmd in docker_commands:
try:
logger.info(f"Running: {' '.join(cmd)}")
result = subprocess.run(cmd, capture_output=True, text=True, timeout=30)
if result.returncode != 0:
logger.error(f"Command failed: {result.stderr}")
return False
time.sleep(2) # Wait between commands
except subprocess.TimeoutExpired:
logger.error("Command timed out")
return False
except FileNotFoundError:
logger.error("Docker not found. Please install Docker first.")
return False
logger.info("✅ DragonflyDB container started successfully!")
return True
def check_dragonflydb_running():
"""Check if DragonflyDB is running on localhost:6379"""
try:
import redis
client = redis.Redis(host='localhost', port=6379, socket_connect_timeout=2, socket_timeout=2)
client.ping()
logger.info("✅ DragonflyDB is running and accessible!")
return True
except Exception as e:
logger.warning(f"❌ DragonflyDB not accessible: {e}")
return False
def start_dragonflydb_binary():
"""Start DragonflyDB binary (if installed locally)"""
logger.info("🚀 Starting DragonflyDB binary...")
try:
# Start DragonflyDB in background
process = subprocess.Popen(['dragonfly', '--port=6379'],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL)
# Wait a moment for startup
time.sleep(3)
if check_dragonflydb_running():
logger.info("✅ DragonflyDB binary started successfully!")
logger.info(f"Process ID: {process.pid}")
return True
else:
logger.error("❌ DragonflyDB failed to start")
return False
except FileNotFoundError:
logger.error("❌ DragonflyDB binary not found")
return False
def setup_instructions():
"""Print setup instructions"""
print("\n" + "=" * 60)
print("🐉 DRAGONFLYDB SETUP INSTRUCTIONS")
print("=" * 60)
print("\nDragonflyDB provides ultra-fast caching for Spotify metadata.")
print("Without it, SwingMusic will use SQLite (slower but still works).")
print("\n📋 SETUP OPTIONS:")
print("\n1️⃣ DOCKER (Recommended):")
print(" docker run -d --name swingmusic-dragonfly -p 6379:6379 \\")
print(" --restart unless-stopped docker.dragonflydb.io/dragonflydb/dragonfly")
print("\n2️⃣ BINARY INSTALLATION:")
print(" # Download from: https://www.dragonflydb.io/")
print(" # Or use package manager (brew, apt, etc.)")
print(" dragonfly --port=6379")
print("\n3️⃣ SKIP (Use SQLite fallback):")
print(" # SwingMusic will work without DragonflyDB")
print(" # Just slower caching with local SQLite database")
print("\n✅ VERIFICATION:")
print(" python3 -c \"import redis; redis.Redis(host='localhost', port=6379).ping()\"")
print("=" * 60)
def main():
"""Main setup function"""
print("🐉 DragonflyDB Setup for SwingMusic")
print("=" * 50)
# Check if already running
if check_dragonflydb_running():
logger.info("✅ DragonflyDB is already running! Setup complete.")
return
# Check if installed
if not check_dragonflydb_installed():
logger.info("DragonflyDB not found. Installing via Docker...")
if install_dragonflydb():
# Wait for container to start
time.sleep(5)
if check_dragonflydb_running():
logger.info("✅ DragonflyDB setup complete!")
return
else:
logger.error("❌ Docker installation failed")
else:
# Try to start binary
if start_dragonflydb_binary():
return
else:
logger.error("❌ Failed to start DragonflyDB binary")
# Show instructions if all else fails
setup_instructions()
print("\n📝 SUMMARY:")
print("✅ SwingMusic will work with SQLite caching if DragonflyDB unavailable")
print("🚀 DragonflyDB provides much faster performance when available")
print("🔧 Follow the instructions above to set up DragonflyDB manually")
if __name__ == "__main__":
main()