da03 commited on
Commit
0d2a979
Β·
1 Parent(s): c80bb33
Files changed (1) hide show
  1. Dockerfile +105 -95
Dockerfile CHANGED
@@ -65,98 +65,108 @@ RUN echo "user ALL=(ALL) NOPASSWD: /usr/sbin/nginx, /usr/sbin/nginx -t, /usr/sbi
65
  USER user
66
 
67
  # Create a startup script for HF Spaces with nginx
68
- RUN echo '#!/bin/bash' > start_hf_spaces.sh && \
69
- echo 'set -e' >> start_hf_spaces.sh && \
70
- echo '' >> start_hf_spaces.sh && \
71
- echo 'echo "πŸš€ Starting Neural OS for HF Spaces with nginx proxy"' >> start_hf_spaces.sh && \
72
- echo 'echo "===================================="' >> start_hf_spaces.sh && \
73
- echo 'echo "πŸ“ Current directory: $(pwd)"' >> start_hf_spaces.sh && \
74
- echo 'echo "πŸ“‹ Files in current directory:"' >> start_hf_spaces.sh && \
75
- echo 'ls -la' >> start_hf_spaces.sh && \
76
- echo '' >> start_hf_spaces.sh && \
77
- echo '# Check if required files exist' >> start_hf_spaces.sh && \
78
- echo 'if [[ ! -f "dispatcher.py" ]]; then' >> start_hf_spaces.sh && \
79
- echo ' echo "❌ Error: dispatcher.py not found"' >> start_hf_spaces.sh && \
80
- echo ' exit 1' >> start_hf_spaces.sh && \
81
- echo 'fi' >> start_hf_spaces.sh && \
82
- echo '' >> start_hf_spaces.sh && \
83
- echo 'if [[ ! -f "worker.py" ]]; then' >> start_hf_spaces.sh && \
84
- echo ' echo "❌ Error: worker.py not found"' >> start_hf_spaces.sh && \
85
- echo ' exit 1' >> start_hf_spaces.sh && \
86
- echo 'fi' >> start_hf_spaces.sh && \
87
- echo '' >> start_hf_spaces.sh && \
88
- echo 'if [[ ! -f "static/index.html" ]]; then' >> start_hf_spaces.sh && \
89
- echo ' echo "❌ Error: static/index.html not found"' >> start_hf_spaces.sh && \
90
- echo ' exit 1' >> start_hf_spaces.sh && \
91
- echo 'fi' >> start_hf_spaces.sh && \
92
- echo '' >> start_hf_spaces.sh && \
93
- echo 'echo "βœ… All required files found"' >> start_hf_spaces.sh && \
94
- echo '' >> start_hf_spaces.sh && \
95
- echo '# Start nginx' >> start_hf_spaces.sh && \
96
- echo 'echo "🌐 Starting nginx proxy..."' >> start_hf_spaces.sh && \
97
- echo 'sudo nginx -t && sudo nginx' >> start_hf_spaces.sh && \
98
- echo '' >> start_hf_spaces.sh && \
99
- echo '# Start dispatcher on port 8080 (behind nginx)' >> start_hf_spaces.sh && \
100
- echo 'echo "🎯 Starting dispatcher..."' >> start_hf_spaces.sh && \
101
- echo 'python dispatcher.py --port 8080 > dispatcher.log 2>&1 &' >> start_hf_spaces.sh && \
102
- echo 'DISPATCHER_PID=$!' >> start_hf_spaces.sh && \
103
- echo 'echo "πŸ“Š Dispatcher PID: $DISPATCHER_PID"' >> start_hf_spaces.sh && \
104
- echo '' >> start_hf_spaces.sh && \
105
- echo '# Wait for dispatcher to start' >> start_hf_spaces.sh && \
106
- echo 'echo "⏳ Waiting for dispatcher to initialize..."' >> start_hf_spaces.sh && \
107
- echo 'sleep 5' >> start_hf_spaces.sh && \
108
- echo '' >> start_hf_spaces.sh && \
109
- echo '# Test if dispatcher is responding' >> start_hf_spaces.sh && \
110
- echo 'echo "πŸ” Testing dispatcher health (via nginx)..."' >> start_hf_spaces.sh && \
111
- echo 'curl -f http://localhost:7860/ > /dev/null 2>&1' >> start_hf_spaces.sh && \
112
- echo 'if [ $? -eq 0 ]; then' >> start_hf_spaces.sh && \
113
- echo ' echo "βœ… Nginx proxy is working"' >> start_hf_spaces.sh && \
114
- echo 'else' >> start_hf_spaces.sh && \
115
- echo ' echo "⚠️ Nginx proxy test failed"' >> start_hf_spaces.sh && \
116
- echo 'fi' >> start_hf_spaces.sh && \
117
- echo '' >> start_hf_spaces.sh && \
118
- echo '# Start worker' >> start_hf_spaces.sh && \
119
- echo 'echo "πŸ”§ Starting worker..."' >> start_hf_spaces.sh && \
120
- echo 'python worker.py --worker-address localhost:8001 --dispatcher-url http://localhost:8080 > worker.log 2>&1 &' >> start_hf_spaces.sh && \
121
- echo 'WORKER_PID=$!' >> start_hf_spaces.sh && \
122
- echo 'echo "πŸ“Š Worker PID: $WORKER_PID"' >> start_hf_spaces.sh && \
123
- echo '' >> start_hf_spaces.sh && \
124
- echo '# Wait for worker to initialize' >> start_hf_spaces.sh && \
125
- echo 'echo "⏳ Waiting for worker to initialize..."' >> start_hf_spaces.sh && \
126
- echo 'sleep 30' >> start_hf_spaces.sh && \
127
- echo '' >> start_hf_spaces.sh && \
128
- echo '# Check if worker is running' >> start_hf_spaces.sh && \
129
- echo 'if ! kill -0 $WORKER_PID 2>/dev/null; then' >> start_hf_spaces.sh && \
130
- echo ' echo "❌ Worker failed to start"' >> start_hf_spaces.sh && \
131
- echo ' echo "πŸ“‹ Worker log:"' >> start_hf_spaces.sh && \
132
- echo ' tail -n 50 worker.log' >> start_hf_spaces.sh && \
133
- echo ' echo "πŸ“‹ Dispatcher log:"' >> start_hf_spaces.sh && \
134
- echo ' tail -n 50 dispatcher.log' >> start_hf_spaces.sh && \
135
- echo ' exit 1' >> start_hf_spaces.sh && \
136
- echo 'fi' >> start_hf_spaces.sh && \
137
- echo '' >> start_hf_spaces.sh && \
138
- echo 'echo "βœ… System ready!"' >> start_hf_spaces.sh && \
139
- echo 'echo "🌍 Web interface: http://localhost:7860 (via nginx)"' >> start_hf_spaces.sh && \
140
- echo 'echo "🎯 Dispatcher: http://localhost:8080 (direct)"' >> start_hf_spaces.sh && \
141
- echo 'echo "πŸ“Š Dispatcher PID: $DISPATCHER_PID"' >> start_hf_spaces.sh && \
142
- echo 'echo "πŸ“Š Worker PID: $WORKER_PID"' >> start_hf_spaces.sh && \
143
- echo '' >> start_hf_spaces.sh && \
144
- echo '# Function to cleanup' >> start_hf_spaces.sh && \
145
- echo 'cleanup() {' >> start_hf_spaces.sh && \
146
- echo ' echo "πŸ›‘ Shutting down..."' >> start_hf_spaces.sh && \
147
- echo ' kill $DISPATCHER_PID $WORKER_PID 2>/dev/null || true' >> start_hf_spaces.sh && \
148
- echo ' sudo nginx -s quit 2>/dev/null || true' >> start_hf_spaces.sh && \
149
- echo ' exit 0' >> start_hf_spaces.sh && \
150
- echo '}' >> start_hf_spaces.sh && \
151
- echo '' >> start_hf_spaces.sh && \
152
- echo 'trap cleanup SIGINT SIGTERM' >> start_hf_spaces.sh && \
153
- echo '' >> start_hf_spaces.sh && \
154
- echo '# Keep the script running' >> start_hf_spaces.sh && \
155
- echo 'echo "πŸ“‹ Following logs (Ctrl+C to stop):"' >> start_hf_spaces.sh && \
156
- echo 'tail -f dispatcher.log worker.log &' >> start_hf_spaces.sh && \
157
- echo 'TAIL_PID=$!' >> start_hf_spaces.sh && \
158
- echo 'wait $DISPATCHER_PID' >> start_hf_spaces.sh && \
159
- echo 'kill $TAIL_PID 2>/dev/null || true' >> start_hf_spaces.sh && \
160
- chmod +x start_hf_spaces.sh
161
-
162
- CMD ["bash", "start_hf_spaces.sh"]
 
 
 
 
 
 
 
 
 
 
 
65
  USER user
66
 
67
  # Create a startup script for HF Spaces with nginx
68
+ RUN echo '#!/bin/bash' > /start_hf_spaces.sh && \
69
+ echo 'set -e' >> /start_hf_spaces.sh && \
70
+ echo '' >> /start_hf_spaces.sh && \
71
+ echo 'echo "πŸš€ Starting Neural OS for HF Spaces with nginx proxy"' >> /start_hf_spaces.sh && \
72
+ echo 'echo "===================================="' >> /start_hf_spaces.sh && \
73
+ echo 'echo "πŸ“ Current directory: $(pwd)"' >> /start_hf_spaces.sh && \
74
+ echo 'cd /home/user/app' >> /start_hf_spaces.sh && \
75
+ echo 'echo "πŸ“‹ Files in current directory:"' >> /start_hf_spaces.sh && \
76
+ echo 'ls -la' >> /start_hf_spaces.sh && \
77
+ echo '' >> /start_hf_spaces.sh && \
78
+ echo '# Check if required files exist' >> /start_hf_spaces.sh && \
79
+ echo 'if [[ ! -f "dispatcher.py" ]]; then' >> /start_hf_spaces.sh && \
80
+ echo ' echo "❌ Error: dispatcher.py not found"' >> /start_hf_spaces.sh && \
81
+ echo ' exit 1' >> /start_hf_spaces.sh && \
82
+ echo 'fi' >> /start_hf_spaces.sh && \
83
+ echo '' >> /start_hf_spaces.sh && \
84
+ echo 'if [[ ! -f "worker.py" ]]; then' >> /start_hf_spaces.sh && \
85
+ echo ' echo "❌ Error: worker.py not found"' >> /start_hf_spaces.sh && \
86
+ echo ' exit 1' >> /start_hf_spaces.sh && \
87
+ echo 'fi' >> /start_hf_spaces.sh && \
88
+ echo '' >> /start_hf_spaces.sh && \
89
+ echo 'if [[ ! -f "static/index.html" ]]; then' >> /start_hf_spaces.sh && \
90
+ echo ' echo "❌ Error: static/index.html not found"' >> /start_hf_spaces.sh && \
91
+ echo ' exit 1' >> /start_hf_spaces.sh && \
92
+ echo 'fi' >> /start_hf_spaces.sh && \
93
+ echo '' >> /start_hf_spaces.sh && \
94
+ echo 'echo "βœ… All required files found"' >> /start_hf_spaces.sh && \
95
+ echo '' >> /start_hf_spaces.sh && \
96
+ echo '# Start nginx as root' >> /start_hf_spaces.sh && \
97
+ echo 'echo "🌐 Starting nginx proxy..."' >> /start_hf_spaces.sh && \
98
+ echo 'nginx -t && nginx' >> /start_hf_spaces.sh && \
99
+ echo '' >> /start_hf_spaces.sh && \
100
+ echo '# Start dispatcher as user' >> /start_hf_spaces.sh && \
101
+ echo 'echo "🎯 Starting dispatcher..."' >> /start_hf_spaces.sh && \
102
+ echo 'su - user -c "cd /home/user/app && python dispatcher.py --port 8080 > dispatcher.log 2>&1 &"' >> /start_hf_spaces.sh && \
103
+ echo 'sleep 2' >> /start_hf_spaces.sh && \
104
+ echo 'DISPATCHER_PID=$(pgrep -f "dispatcher.py")' >> /start_hf_spaces.sh && \
105
+ echo 'echo "πŸ“Š Dispatcher PID: $DISPATCHER_PID"' >> /start_hf_spaces.sh && \
106
+ echo '' >> /start_hf_spaces.sh && \
107
+ echo '# Wait for dispatcher to start' >> /start_hf_spaces.sh && \
108
+ echo 'echo "⏳ Waiting for dispatcher to initialize..."' >> /start_hf_spaces.sh && \
109
+ echo 'sleep 5' >> /start_hf_spaces.sh && \
110
+ echo '' >> /start_hf_spaces.sh && \
111
+ echo '# Test if dispatcher is responding' >> /start_hf_spaces.sh && \
112
+ echo 'echo "πŸ” Testing dispatcher health (via nginx)..."' >> /start_hf_spaces.sh && \
113
+ echo 'curl -f http://localhost:7860/ > /dev/null 2>&1' >> /start_hf_spaces.sh && \
114
+ echo 'if [ $? -eq 0 ]; then' >> /start_hf_spaces.sh && \
115
+ echo ' echo "βœ… Nginx proxy is working"' >> /start_hf_spaces.sh && \
116
+ echo 'else' >> /start_hf_spaces.sh && \
117
+ echo ' echo "⚠️ Nginx proxy test failed"' >> /start_hf_spaces.sh && \
118
+ echo 'fi' >> /start_hf_spaces.sh && \
119
+ echo '' >> /start_hf_spaces.sh && \
120
+ echo '# Start worker as user' >> /start_hf_spaces.sh && \
121
+ echo 'echo "πŸ”§ Starting worker..."' >> /start_hf_spaces.sh && \
122
+ echo 'su - user -c "cd /home/user/app && python worker.py --worker-address localhost:8001 --dispatcher-url http://localhost:8080 > worker.log 2>&1 &"' >> /start_hf_spaces.sh && \
123
+ echo 'sleep 2' >> /start_hf_spaces.sh && \
124
+ echo 'WORKER_PID=$(pgrep -f "worker.py")' >> /start_hf_spaces.sh && \
125
+ echo 'echo "πŸ“Š Worker PID: $WORKER_PID"' >> /start_hf_spaces.sh && \
126
+ echo '' >> /start_hf_spaces.sh && \
127
+ echo '# Wait for worker to initialize' >> /start_hf_spaces.sh && \
128
+ echo 'echo "⏳ Waiting for worker to initialize..."' >> /start_hf_spaces.sh && \
129
+ echo 'sleep 30' >> /start_hf_spaces.sh && \
130
+ echo '' >> /start_hf_spaces.sh && \
131
+ echo '# Check if worker is running' >> /start_hf_spaces.sh && \
132
+ echo 'if ! kill -0 $WORKER_PID 2>/dev/null; then' >> /start_hf_spaces.sh && \
133
+ echo ' echo "❌ Worker failed to start"' >> /start_hf_spaces.sh && \
134
+ echo ' echo "πŸ“‹ Worker log:"' >> /start_hf_spaces.sh && \
135
+ echo ' tail -n 50 /home/user/app/worker.log' >> /start_hf_spaces.sh && \
136
+ echo ' echo "πŸ“‹ Dispatcher log:"' >> /start_hf_spaces.sh && \
137
+ echo ' tail -n 50 /home/user/app/dispatcher.log' >> /start_hf_spaces.sh && \
138
+ echo ' exit 1' >> /start_hf_spaces.sh && \
139
+ echo 'fi' >> /start_hf_spaces.sh && \
140
+ echo '' >> /start_hf_spaces.sh && \
141
+ echo 'echo "βœ… System ready!"' >> /start_hf_spaces.sh && \
142
+ echo 'echo "🌍 Web interface: http://localhost:7860 (via nginx)"' >> /start_hf_spaces.sh && \
143
+ echo 'echo "🎯 Dispatcher: http://localhost:8080 (direct)"' >> /start_hf_spaces.sh && \
144
+ echo 'echo "πŸ“Š Dispatcher PID: $DISPATCHER_PID"' >> /start_hf_spaces.sh && \
145
+ echo 'echo "πŸ“Š Worker PID: $WORKER_PID"' >> /start_hf_spaces.sh && \
146
+ echo '' >> /start_hf_spaces.sh && \
147
+ echo '# Function to cleanup' >> /start_hf_spaces.sh && \
148
+ echo 'cleanup() {' >> /start_hf_spaces.sh && \
149
+ echo ' echo "πŸ›‘ Shutting down..."' >> /start_hf_spaces.sh && \
150
+ echo ' kill $DISPATCHER_PID $WORKER_PID 2>/dev/null || true' >> /start_hf_spaces.sh && \
151
+ echo ' nginx -s quit 2>/dev/null || true' >> /start_hf_spaces.sh && \
152
+ echo ' exit 0' >> /start_hf_spaces.sh && \
153
+ echo '}' >> /start_hf_spaces.sh && \
154
+ echo '' >> /start_hf_spaces.sh && \
155
+ echo 'trap cleanup SIGINT SIGTERM' >> /start_hf_spaces.sh && \
156
+ echo '' >> /start_hf_spaces.sh && \
157
+ echo '# Keep the script running' >> /start_hf_spaces.sh && \
158
+ echo 'echo "πŸ“‹ Following logs (Ctrl+C to stop):"' >> /start_hf_spaces.sh && \
159
+ echo 'tail -f /home/user/app/dispatcher.log /home/user/app/worker.log &' >> /start_hf_spaces.sh && \
160
+ echo 'TAIL_PID=$!' >> /start_hf_spaces.sh && \
161
+ echo 'wait $DISPATCHER_PID' >> /start_hf_spaces.sh && \
162
+ echo 'kill $TAIL_PID 2>/dev/null || true' >> /start_hf_spaces.sh && \
163
+ chmod +x /start_hf_spaces.sh
164
+
165
+ # Remove the old user-level startup script
166
+ USER user
167
+ RUN rm -f start_hf_spaces.sh
168
+
169
+ # Switch back to root for final startup
170
+ USER root
171
+
172
+ CMD ["/start_hf_spaces.sh"]