File size: 1,702 Bytes
594aa49
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""
Simple app.py that runs the Docker container for OpenCurro Backend
on Hugging Face Spaces
"""

import subprocess
import sys
import time

DOCKER_IMAGE_NAME = "opencurro-backend"
DOCKER_CONTAINER_NAME = "opencurro-backend-container"

def run_docker():
    """Build and run Docker container"""
    try:
        print("🐳 Building Docker image...")
        
        # Build Docker image
        build_cmd = [
            "docker", "build",
            "-f", "Dockerfile.hf-backend",
            "-t", DOCKER_IMAGE_NAME,
            "."
        ]
        
        result = subprocess.run(build_cmd, check=True)
        print("βœ… Docker image built successfully")
        
        # Remove old container if exists
        try:
            subprocess.run(
                ["docker", "rm", "-f", DOCKER_CONTAINER_NAME],
                capture_output=True
            )
        except:
            pass
        
        # Run Docker container
        print("πŸš€ Starting Docker container...")
        run_cmd = [
            "docker", "run",
            "--name", DOCKER_CONTAINER_NAME,
            "-p", "8000:8000",
            DOCKER_IMAGE_NAME
        ]
        
        subprocess.run(run_cmd, check=True)
    
    except subprocess.CalledProcessError as e:
        print(f"❌ Error: {e}")
        sys.exit(1)
    except KeyboardInterrupt:
        print("\nπŸ›‘ Shutting down...")
        subprocess.run(["docker", "stop", DOCKER_CONTAINER_NAME], capture_output=True)
        subprocess.run(["docker", "rm", DOCKER_CONTAINER_NAME], capture_output=True)

if __name__ == "__main__":
    print("🎯 OpenCurro AI Backend - Docker Runner")
    print("=" * 50)
    run_docker()