| |
| """ |
| Quick fix script for Docker build and runtime issues |
| """ |
|
|
| import os |
| import subprocess |
|
|
| def run_command(command, description): |
| """Run a command and handle errors""" |
| print(f"π {description}...") |
| try: |
| result = subprocess.run(command, shell=True, check=True, capture_output=True, text=True) |
| print(f"β
{description} completed successfully") |
| return result.stdout |
| except subprocess.CalledProcessError as e: |
| print(f"β {description} failed:") |
| print(f"Error: {e.stderr}") |
| return None |
|
|
| def main(): |
| print("π§ Docker Build & Runtime Fix for Devam Jersey Server") |
| print("=" * 60) |
| |
| print("\nπ¨ Issues encountered:") |
| print("1. β
BUILD: Package compatibility (FIXED)") |
| print("2. β RUNTIME: OpenCV libGL.so.1 error (NEW ISSUE)") |
| |
| print("\nπ Root Cause Analysis:") |
| print("- OpenCV is trying to load GUI libraries even with headless version") |
| print("- This happens when ultralytics imports cv2") |
| print("- The libGL.so.1 error indicates missing OpenGL libraries") |
| |
| print("\nπ Solutions Available:") |
| |
| print("\nπ Solution 1: Use Startup Script (Recommended)") |
| print("The Dockerfile now uses start_server.py which handles OpenCV better:") |
| print(" git add .") |
| print(" git commit -m 'Add OpenCV headless startup script'") |
| print(" git push") |
| |
| print("\nπ Solution 2: Use OpenCV-Fixed Dockerfile") |
| print("If Solution 1 doesn't work:") |
| print(" mv Dockerfile Dockerfile.backup") |
| print(" mv Dockerfile.opencv_fix Dockerfile") |
| print(" git add .") |
| print(" git commit -m 'Use OpenCV-compatible Dockerfile'") |
| print(" git push") |
| |
| print("\nπ Solution 3: Manual OpenCV Fix") |
| print("Edit requirements.txt and change:") |
| print(" opencv-python-headless>=4.8.0,<5.0.0") |
| print(" to:") |
| print(" opencv-python-headless==4.8.1.78") |
| |
| print("\nπ Solution 4: Alternative Base Image") |
| print("Try a different Python base:") |
| print(" FROM python:3.9-slim-bullseye") |
| print(" or") |
| print(" FROM python:3.9-buster") |
| |
| print("\nπ§ What I've Fixed:") |
| print("- β
Updated Dockerfile with bullseye base") |
| print("- β
Added environment variables for headless mode") |
| print("- β
Created start_server.py with OpenCV handling") |
| print("- β
Created Dockerfile.opencv_fix as backup") |
| print("- β
Updated requirements.txt with version constraints") |
| |
| print("\nπ‘ Pro Tips:") |
| print("- The startup script provides better error handling") |
| print("- OpenCV 4.8.1.78 is known to work well in Docker") |
| print("- Environment variables force headless mode") |
| print("- Monitor build logs after each fix attempt") |
| |
| print("\nπ After fixing, monitor:") |
| print("1. Build completion in HF Space") |
| print("2. Runtime logs for OpenCV errors") |
| print("3. API endpoint responses") |
| |
| print("\nπ If all else fails:") |
| print("- Consider using a different ML framework") |
| print("- Use Hugging Face's built-in inference endpoints") |
| print("- Deploy on a different platform (AWS, GCP, etc.)") |
|
|
| if __name__ == "__main__": |
| main() |
|
|