#!/usr/bin/env python3 """ 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()