da03 commited on
Commit
f2020b4
Β·
1 Parent(s): 0473ddc
Files changed (1) hide show
  1. Dockerfile +99 -102
Dockerfile CHANGED
@@ -30,107 +30,104 @@ WORKDIR $HOME/app
30
  # Copy the current directory contents into the container at $HOME/app setting the owner to the user
31
  COPY --chown=user . $HOME/app
32
 
33
- # Create a startup script for HF Spaces
34
- RUN cat > start_hf_spaces.sh << 'EOF'
35
- #!/bin/bash
36
- set -e
37
-
38
- echo "πŸš€ Starting Neural OS for HF Spaces"
39
- echo "===================================="
40
- echo "πŸ“ Current directory: $(pwd)"
41
- echo "πŸ“‹ Files in current directory:"
42
- ls -la
43
-
44
- # Check if required files exist
45
- if [[ ! -f "dispatcher.py" ]]; then
46
- echo "❌ Error: dispatcher.py not found"
47
- exit 1
48
- fi
49
-
50
- if [[ ! -f "worker.py" ]]; then
51
- echo "❌ Error: worker.py not found"
52
- exit 1
53
- fi
54
-
55
- if [[ ! -f "static/index.html" ]]; then
56
- echo "❌ Error: static/index.html not found"
57
- exit 1
58
- fi
59
-
60
- echo "βœ… All required files found"
61
-
62
- # Start dispatcher in background
63
- echo "🎯 Starting dispatcher..."
64
- python dispatcher.py --port 7860 > dispatcher.log 2>&1 &
65
- DISPATCHER_PID=$!
66
- echo "πŸ“Š Dispatcher PID: $DISPATCHER_PID"
67
-
68
- # Wait for dispatcher to start and check if it's running
69
- echo "⏳ Waiting for dispatcher to initialize..."
70
- sleep 5
71
-
72
- if ! kill -0 $DISPATCHER_PID 2>/dev/null; then
73
- echo "❌ Dispatcher failed to start"
74
- echo "πŸ“‹ Dispatcher log:"
75
- cat dispatcher.log
76
- exit 1
77
- fi
78
-
79
- # Test if dispatcher is responding
80
- echo "πŸ” Testing dispatcher health..."
81
- curl -f http://localhost:7860/ > /dev/null 2>&1
82
- if [ $? -eq 0 ]; then
83
- echo "βœ… Dispatcher is responding to HTTP requests"
84
- else
85
- echo "⚠️ Dispatcher HTTP test failed, but continuing..."
86
- fi
87
-
88
- # Start single worker
89
- echo "πŸ”§ Starting worker..."
90
- python worker.py --worker-address localhost:8001 --dispatcher-url http://localhost:7860 > worker.log 2>&1 &
91
- WORKER_PID=$!
92
- echo "πŸ“Š Worker PID: $WORKER_PID"
93
-
94
- # Wait for worker to initialize
95
- echo "⏳ Waiting for worker to initialize..."
96
- sleep 30
97
-
98
- # Check if worker is still running
99
- if ! kill -0 $WORKER_PID 2>/dev/null; then
100
- echo "❌ Worker failed to start"
101
- echo "πŸ“‹ Worker log:"
102
- cat worker.log
103
- echo "πŸ“‹ Dispatcher log:"
104
- cat dispatcher.log
105
- exit 1
106
- fi
107
-
108
- echo "βœ… System ready!"
109
- echo "🌍 Web interface: http://localhost:7860"
110
- echo "πŸ“Š Dispatcher PID: $DISPATCHER_PID"
111
- echo "πŸ“Š Worker PID: $WORKER_PID"
112
-
113
- # Function to cleanup
114
- cleanup() {
115
- echo "πŸ›‘ Shutting down..."
116
- kill $DISPATCHER_PID $WORKER_PID 2>/dev/null || true
117
- exit 0
118
- }
119
-
120
- trap cleanup SIGINT SIGTERM
121
-
122
- # Keep the script running by following the dispatcher log
123
- echo "πŸ“‹ Following dispatcher log (Ctrl+C to stop):"
124
- tail -f dispatcher.log &
125
- TAIL_PID=$!
126
-
127
- # Wait for dispatcher (main process)
128
- wait $DISPATCHER_PID
129
-
130
- # Clean up tail process
131
- kill $TAIL_PID 2>/dev/null || true
132
- EOF
133
-
134
- RUN chmod +x start_hf_spaces.sh
135
 
136
  CMD ["bash", "start_hf_spaces.sh"]
 
30
  # Copy the current directory contents into the container at $HOME/app setting the owner to the user
31
  COPY --chown=user . $HOME/app
32
 
33
+ # Create a startup script for HF Spaces using echo commands
34
+ RUN echo '#!/bin/bash' > start_hf_spaces.sh && \
35
+ echo 'set -e' >> start_hf_spaces.sh && \
36
+ echo '' >> start_hf_spaces.sh && \
37
+ echo 'echo "πŸš€ Starting Neural OS for HF Spaces"' >> start_hf_spaces.sh && \
38
+ echo 'echo "===================================="' >> start_hf_spaces.sh && \
39
+ echo 'echo "πŸ“ Current directory: $(pwd)"' >> start_hf_spaces.sh && \
40
+ echo 'echo "πŸ“‹ Files in current directory:"' >> start_hf_spaces.sh && \
41
+ echo 'ls -la' >> start_hf_spaces.sh && \
42
+ echo '' >> start_hf_spaces.sh && \
43
+ echo '# Check if required files exist' >> start_hf_spaces.sh && \
44
+ echo 'if [[ ! -f "dispatcher.py" ]]; then' >> start_hf_spaces.sh && \
45
+ echo ' echo "❌ Error: dispatcher.py not found"' >> start_hf_spaces.sh && \
46
+ echo ' exit 1' >> start_hf_spaces.sh && \
47
+ echo 'fi' >> start_hf_spaces.sh && \
48
+ echo '' >> start_hf_spaces.sh && \
49
+ echo 'if [[ ! -f "worker.py" ]]; then' >> start_hf_spaces.sh && \
50
+ echo ' echo "❌ Error: worker.py not found"' >> start_hf_spaces.sh && \
51
+ echo ' exit 1' >> start_hf_spaces.sh && \
52
+ echo 'fi' >> start_hf_spaces.sh && \
53
+ echo '' >> start_hf_spaces.sh && \
54
+ echo 'if [[ ! -f "static/index.html" ]]; then' >> start_hf_spaces.sh && \
55
+ echo ' echo "❌ Error: static/index.html not found"' >> start_hf_spaces.sh && \
56
+ echo ' exit 1' >> start_hf_spaces.sh && \
57
+ echo 'fi' >> start_hf_spaces.sh && \
58
+ echo '' >> start_hf_spaces.sh && \
59
+ echo 'echo "βœ… All required files found"' >> start_hf_spaces.sh && \
60
+ echo '' >> start_hf_spaces.sh && \
61
+ echo '# Start dispatcher in background' >> start_hf_spaces.sh && \
62
+ echo 'echo "🎯 Starting dispatcher..."' >> start_hf_spaces.sh && \
63
+ echo 'python dispatcher.py --port 7860 > dispatcher.log 2>&1 &' >> start_hf_spaces.sh && \
64
+ echo 'DISPATCHER_PID=$!' >> start_hf_spaces.sh && \
65
+ echo 'echo "πŸ“Š Dispatcher PID: $DISPATCHER_PID"' >> start_hf_spaces.sh && \
66
+ echo '' >> start_hf_spaces.sh && \
67
+ echo '# Wait for dispatcher to start and check if it is running' >> start_hf_spaces.sh && \
68
+ echo 'echo "⏳ Waiting for dispatcher to initialize..."' >> start_hf_spaces.sh && \
69
+ echo 'sleep 5' >> start_hf_spaces.sh && \
70
+ echo '' >> start_hf_spaces.sh && \
71
+ echo 'if ! kill -0 $DISPATCHER_PID 2>/dev/null; then' >> start_hf_spaces.sh && \
72
+ echo ' echo "❌ Dispatcher failed to start"' >> start_hf_spaces.sh && \
73
+ echo ' echo "πŸ“‹ Dispatcher log:"' >> start_hf_spaces.sh && \
74
+ echo ' cat dispatcher.log' >> start_hf_spaces.sh && \
75
+ echo ' exit 1' >> start_hf_spaces.sh && \
76
+ echo 'fi' >> start_hf_spaces.sh && \
77
+ echo '' >> start_hf_spaces.sh && \
78
+ echo '# Test if dispatcher is responding' >> start_hf_spaces.sh && \
79
+ echo 'echo "πŸ” Testing dispatcher health..."' >> start_hf_spaces.sh && \
80
+ echo 'curl -f http://localhost:7860/ > /dev/null 2>&1' >> start_hf_spaces.sh && \
81
+ echo 'if [ $? -eq 0 ]; then' >> start_hf_spaces.sh && \
82
+ echo ' echo "βœ… Dispatcher is responding to HTTP requests"' >> start_hf_spaces.sh && \
83
+ echo 'else' >> start_hf_spaces.sh && \
84
+ echo ' echo "⚠️ Dispatcher HTTP test failed, but continuing..."' >> start_hf_spaces.sh && \
85
+ echo 'fi' >> start_hf_spaces.sh && \
86
+ echo '' >> start_hf_spaces.sh && \
87
+ echo '# Start single worker' >> start_hf_spaces.sh && \
88
+ echo 'echo "πŸ”§ Starting worker..."' >> start_hf_spaces.sh && \
89
+ echo 'python worker.py --worker-address localhost:8001 --dispatcher-url http://localhost:7860 > worker.log 2>&1 &' >> start_hf_spaces.sh && \
90
+ echo 'WORKER_PID=$!' >> start_hf_spaces.sh && \
91
+ echo 'echo "πŸ“Š Worker PID: $WORKER_PID"' >> start_hf_spaces.sh && \
92
+ echo '' >> start_hf_spaces.sh && \
93
+ echo '# Wait for worker to initialize' >> start_hf_spaces.sh && \
94
+ echo 'echo "⏳ Waiting for worker to initialize..."' >> start_hf_spaces.sh && \
95
+ echo 'sleep 30' >> start_hf_spaces.sh && \
96
+ echo '' >> start_hf_spaces.sh && \
97
+ echo '# Check if worker is still running' >> start_hf_spaces.sh && \
98
+ echo 'if ! kill -0 $WORKER_PID 2>/dev/null; then' >> start_hf_spaces.sh && \
99
+ echo ' echo "❌ Worker failed to start"' >> start_hf_spaces.sh && \
100
+ echo ' echo "πŸ“‹ Worker log:"' >> start_hf_spaces.sh && \
101
+ echo ' cat worker.log' >> start_hf_spaces.sh && \
102
+ echo ' echo "πŸ“‹ Dispatcher log:"' >> start_hf_spaces.sh && \
103
+ echo ' cat dispatcher.log' >> start_hf_spaces.sh && \
104
+ echo ' exit 1' >> start_hf_spaces.sh && \
105
+ echo 'fi' >> start_hf_spaces.sh && \
106
+ echo '' >> start_hf_spaces.sh && \
107
+ echo 'echo "βœ… System ready!"' >> start_hf_spaces.sh && \
108
+ echo 'echo "🌍 Web interface: http://localhost:7860"' >> start_hf_spaces.sh && \
109
+ echo 'echo "πŸ“Š Dispatcher PID: $DISPATCHER_PID"' >> start_hf_spaces.sh && \
110
+ echo 'echo "πŸ“Š Worker PID: $WORKER_PID"' >> start_hf_spaces.sh && \
111
+ echo '' >> start_hf_spaces.sh && \
112
+ echo '# Function to cleanup' >> start_hf_spaces.sh && \
113
+ echo 'cleanup() {' >> start_hf_spaces.sh && \
114
+ echo ' echo "πŸ›‘ Shutting down..."' >> start_hf_spaces.sh && \
115
+ echo ' kill $DISPATCHER_PID $WORKER_PID 2>/dev/null || true' >> start_hf_spaces.sh && \
116
+ echo ' exit 0' >> start_hf_spaces.sh && \
117
+ echo '}' >> start_hf_spaces.sh && \
118
+ echo '' >> start_hf_spaces.sh && \
119
+ echo 'trap cleanup SIGINT SIGTERM' >> start_hf_spaces.sh && \
120
+ echo '' >> start_hf_spaces.sh && \
121
+ echo '# Keep the script running by following the dispatcher log' >> start_hf_spaces.sh && \
122
+ echo 'echo "πŸ“‹ Following dispatcher log (Ctrl+C to stop):"' >> start_hf_spaces.sh && \
123
+ echo 'tail -f dispatcher.log &' >> start_hf_spaces.sh && \
124
+ echo 'TAIL_PID=$!' >> start_hf_spaces.sh && \
125
+ echo '' >> start_hf_spaces.sh && \
126
+ echo '# Wait for dispatcher (main process)' >> start_hf_spaces.sh && \
127
+ echo 'wait $DISPATCHER_PID' >> start_hf_spaces.sh && \
128
+ echo '' >> start_hf_spaces.sh && \
129
+ echo '# Clean up tail process' >> start_hf_spaces.sh && \
130
+ echo 'kill $TAIL_PID 2>/dev/null || true' >> start_hf_spaces.sh && \
131
+ chmod +x start_hf_spaces.sh
 
 
 
132
 
133
  CMD ["bash", "start_hf_spaces.sh"]