Spaces:
Runtime error
Runtime error
da03
commited on
Commit
Β·
f2020b4
1
Parent(s):
0473ddc
- 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
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
echo "
|
39 |
-
echo "
|
40 |
-
echo "
|
41 |
-
echo
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
echo
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
echo
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
echo
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
echo
|
61 |
-
|
62 |
-
|
63 |
-
echo
|
64 |
-
|
65 |
-
DISPATCHER_PID
|
66 |
-
echo
|
67 |
-
|
68 |
-
|
69 |
-
echo
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
echo "
|
74 |
-
echo
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
echo
|
81 |
-
|
82 |
-
|
83 |
-
echo
|
84 |
-
|
85 |
-
echo
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
echo
|
90 |
-
|
91 |
-
WORKER_PID
|
92 |
-
echo
|
93 |
-
|
94 |
-
|
95 |
-
echo
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
echo "
|
101 |
-
echo
|
102 |
-
|
103 |
-
echo
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
echo "
|
109 |
-
echo "
|
110 |
-
echo "π
|
111 |
-
echo
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
echo
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
echo
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
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"]
|