Spaces:
Runtime error
Runtime error
da03
commited on
Commit
Β·
0d2a979
1
Parent(s):
c80bb33
- 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 '
|
75 |
-
echo '
|
76 |
-
echo '' >> start_hf_spaces.sh && \
|
77 |
-
echo '
|
78 |
-
echo '
|
79 |
-
echo '
|
80 |
-
echo '
|
81 |
-
echo '
|
82 |
-
echo '' >> start_hf_spaces.sh && \
|
83 |
-
echo '
|
84 |
-
echo '
|
85 |
-
echo '
|
86 |
-
echo '
|
87 |
-
echo '' >> start_hf_spaces.sh && \
|
88 |
-
echo '
|
89 |
-
echo '
|
90 |
-
echo '
|
91 |
-
echo '
|
92 |
-
echo '' >> start_hf_spaces.sh && \
|
93 |
-
echo '
|
94 |
-
echo '' >> start_hf_spaces.sh && \
|
95 |
-
echo '
|
96 |
-
echo '
|
97 |
-
echo '
|
98 |
-
echo '' >> start_hf_spaces.sh && \
|
99 |
-
echo '
|
100 |
-
echo '
|
101 |
-
echo '
|
102 |
-
echo '
|
103 |
-
echo '
|
104 |
-
echo '' >> start_hf_spaces.sh && \
|
105 |
-
echo '
|
106 |
-
echo '
|
107 |
-
echo '
|
108 |
-
echo '' >> start_hf_spaces.sh && \
|
109 |
-
echo '
|
110 |
-
echo '
|
111 |
-
echo '
|
112 |
-
echo '
|
113 |
-
echo '
|
114 |
-
echo '
|
115 |
-
echo ' echo "
|
116 |
-
echo '
|
117 |
-
echo '' >> start_hf_spaces.sh && \
|
118 |
-
echo '
|
119 |
-
echo '
|
120 |
-
echo '
|
121 |
-
echo '
|
122 |
-
echo '
|
123 |
-
echo '' >> start_hf_spaces.sh && \
|
124 |
-
echo '
|
125 |
-
echo 'echo "
|
126 |
-
echo '
|
127 |
-
echo '' >> start_hf_spaces.sh && \
|
128 |
-
echo '
|
129 |
-
echo '
|
130 |
-
echo '
|
131 |
-
echo '
|
132 |
-
echo '
|
133 |
-
echo ' echo "
|
134 |
-
echo '
|
135 |
-
echo '
|
136 |
-
echo '
|
137 |
-
echo '' >> start_hf_spaces.sh && \
|
138 |
-
echo '
|
139 |
-
echo '
|
140 |
-
echo '
|
141 |
-
echo 'echo "
|
142 |
-
echo 'echo "
|
143 |
-
echo '' >> start_hf_spaces.sh && \
|
144 |
-
echo '
|
145 |
-
echo '
|
146 |
-
echo '
|
147 |
-
echo '
|
148 |
-
echo '
|
149 |
-
echo '
|
150 |
-
echo '
|
151 |
-
echo '' >> start_hf_spaces.sh && \
|
152 |
-
echo '
|
153 |
-
echo '' >> start_hf_spaces.sh && \
|
154 |
-
echo '
|
155 |
-
echo '
|
156 |
-
echo '
|
157 |
-
echo '
|
158 |
-
echo '
|
159 |
-
echo '
|
160 |
-
|
161 |
-
|
162 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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"]
|