da03 commited on
Commit
ba65ca0
Β·
1 Parent(s): 1828ec1
Files changed (1) hide show
  1. Dockerfile +14 -11
Dockerfile CHANGED
@@ -47,6 +47,9 @@ RUN echo 'server {' > /etc/nginx/sites-available/default && \
47
  echo ' }' >> /etc/nginx/sites-available/default && \
48
  echo '}' >> /etc/nginx/sites-available/default
49
 
 
 
 
50
  # Give user sudo permissions for nginx
51
  RUN echo "user ALL=(ALL) NOPASSWD: /usr/sbin/nginx, /usr/sbin/nginx -t, /usr/sbin/nginx -s quit" >> /etc/sudoers
52
 
@@ -81,13 +84,14 @@ RUN echo '#!/bin/bash' > /start_hf_spaces.sh && \
81
  echo '' >> /start_hf_spaces.sh && \
82
  echo '# Start nginx as root' >> /start_hf_spaces.sh && \
83
  echo 'echo "🌐 Starting nginx proxy..."' >> /start_hf_spaces.sh && \
 
84
  echo 'nginx -t && nginx' >> /start_hf_spaces.sh && \
85
  echo '' >> /start_hf_spaces.sh && \
86
- echo '# Start dispatcher as user' >> /start_hf_spaces.sh && \
87
  echo 'echo "🎯 Starting dispatcher..."' >> /start_hf_spaces.sh && \
88
- echo 'su - user -c "cd /home/user/app && python dispatcher.py --port 8080 > dispatcher.log 2>&1 &"' >> /start_hf_spaces.sh && \
89
- echo 'sleep 2' >> /start_hf_spaces.sh && \
90
- echo 'DISPATCHER_PID=$(pgrep -f "dispatcher.py")' >> /start_hf_spaces.sh && \
91
  echo 'echo "πŸ“Š Dispatcher PID: $DISPATCHER_PID"' >> /start_hf_spaces.sh && \
92
  echo '' >> /start_hf_spaces.sh && \
93
  echo '# Wait for dispatcher to start' >> /start_hf_spaces.sh && \
@@ -103,11 +107,10 @@ RUN echo '#!/bin/bash' > /start_hf_spaces.sh && \
103
  echo ' echo "⚠️ Nginx proxy test failed"' >> /start_hf_spaces.sh && \
104
  echo 'fi' >> /start_hf_spaces.sh && \
105
  echo '' >> /start_hf_spaces.sh && \
106
- echo '# Start worker as user' >> /start_hf_spaces.sh && \
107
  echo 'echo "πŸ”§ Starting worker..."' >> /start_hf_spaces.sh && \
108
- 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 && \
109
- echo 'sleep 2' >> /start_hf_spaces.sh && \
110
- echo 'WORKER_PID=$(pgrep -f "worker.py")' >> /start_hf_spaces.sh && \
111
  echo 'echo "πŸ“Š Worker PID: $WORKER_PID"' >> /start_hf_spaces.sh && \
112
  echo '' >> /start_hf_spaces.sh && \
113
  echo '# Wait for worker to initialize' >> /start_hf_spaces.sh && \
@@ -118,9 +121,9 @@ RUN echo '#!/bin/bash' > /start_hf_spaces.sh && \
118
  echo 'if ! kill -0 $WORKER_PID 2>/dev/null; then' >> /start_hf_spaces.sh && \
119
  echo ' echo "❌ Worker failed to start"' >> /start_hf_spaces.sh && \
120
  echo ' echo "πŸ“‹ Worker log:"' >> /start_hf_spaces.sh && \
121
- echo ' tail -n 50 /home/user/app/worker.log' >> /start_hf_spaces.sh && \
122
  echo ' echo "πŸ“‹ Dispatcher log:"' >> /start_hf_spaces.sh && \
123
- echo ' tail -n 50 /home/user/app/dispatcher.log' >> /start_hf_spaces.sh && \
124
  echo ' exit 1' >> /start_hf_spaces.sh && \
125
  echo 'fi' >> /start_hf_spaces.sh && \
126
  echo '' >> /start_hf_spaces.sh && \
@@ -142,7 +145,7 @@ RUN echo '#!/bin/bash' > /start_hf_spaces.sh && \
142
  echo '' >> /start_hf_spaces.sh && \
143
  echo '# Keep the script running' >> /start_hf_spaces.sh && \
144
  echo 'echo "πŸ“‹ Following logs (Ctrl+C to stop):"' >> /start_hf_spaces.sh && \
145
- echo 'tail -f /home/user/app/dispatcher.log /home/user/app/worker.log &' >> /start_hf_spaces.sh && \
146
  echo 'TAIL_PID=$!' >> /start_hf_spaces.sh && \
147
  echo 'wait $DISPATCHER_PID' >> /start_hf_spaces.sh && \
148
  echo 'kill $TAIL_PID 2>/dev/null || true' >> /start_hf_spaces.sh && \
 
47
  echo ' }' >> /etc/nginx/sites-available/default && \
48
  echo '}' >> /etc/nginx/sites-available/default
49
 
50
+ # Create directories for nginx
51
+ RUN mkdir -p /run/nginx && chmod 755 /run/nginx
52
+
53
  # Give user sudo permissions for nginx
54
  RUN echo "user ALL=(ALL) NOPASSWD: /usr/sbin/nginx, /usr/sbin/nginx -t, /usr/sbin/nginx -s quit" >> /etc/sudoers
55
 
 
84
  echo '' >> /start_hf_spaces.sh && \
85
  echo '# Start nginx as root' >> /start_hf_spaces.sh && \
86
  echo 'echo "🌐 Starting nginx proxy..."' >> /start_hf_spaces.sh && \
87
+ echo 'mkdir -p /run/nginx' >> /start_hf_spaces.sh && \
88
  echo 'nginx -t && nginx' >> /start_hf_spaces.sh && \
89
  echo '' >> /start_hf_spaces.sh && \
90
+ echo '# Start dispatcher as user using runuser' >> /start_hf_spaces.sh && \
91
  echo 'echo "🎯 Starting dispatcher..."' >> /start_hf_spaces.sh && \
92
+ echo 'cd /home/user/app' >> /start_hf_spaces.sh && \
93
+ echo 'runuser -l user -c "cd /home/user/app && python dispatcher.py --port 8080" > dispatcher.log 2>&1 &' >> /start_hf_spaces.sh && \
94
+ echo 'DISPATCHER_PID=$!' >> /start_hf_spaces.sh && \
95
  echo 'echo "πŸ“Š Dispatcher PID: $DISPATCHER_PID"' >> /start_hf_spaces.sh && \
96
  echo '' >> /start_hf_spaces.sh && \
97
  echo '# Wait for dispatcher to start' >> /start_hf_spaces.sh && \
 
107
  echo ' echo "⚠️ Nginx proxy test failed"' >> /start_hf_spaces.sh && \
108
  echo 'fi' >> /start_hf_spaces.sh && \
109
  echo '' >> /start_hf_spaces.sh && \
110
+ echo '# Start worker as user using runuser' >> /start_hf_spaces.sh && \
111
  echo 'echo "πŸ”§ Starting worker..."' >> /start_hf_spaces.sh && \
112
+ echo 'runuser -l 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 && \
113
+ echo 'WORKER_PID=$!' >> /start_hf_spaces.sh && \
 
114
  echo 'echo "πŸ“Š Worker PID: $WORKER_PID"' >> /start_hf_spaces.sh && \
115
  echo '' >> /start_hf_spaces.sh && \
116
  echo '# Wait for worker to initialize' >> /start_hf_spaces.sh && \
 
121
  echo 'if ! kill -0 $WORKER_PID 2>/dev/null; then' >> /start_hf_spaces.sh && \
122
  echo ' echo "❌ Worker failed to start"' >> /start_hf_spaces.sh && \
123
  echo ' echo "πŸ“‹ Worker log:"' >> /start_hf_spaces.sh && \
124
+ echo ' tail -n 50 worker.log' >> /start_hf_spaces.sh && \
125
  echo ' echo "πŸ“‹ Dispatcher log:"' >> /start_hf_spaces.sh && \
126
+ echo ' tail -n 50 dispatcher.log' >> /start_hf_spaces.sh && \
127
  echo ' exit 1' >> /start_hf_spaces.sh && \
128
  echo 'fi' >> /start_hf_spaces.sh && \
129
  echo '' >> /start_hf_spaces.sh && \
 
145
  echo '' >> /start_hf_spaces.sh && \
146
  echo '# Keep the script running' >> /start_hf_spaces.sh && \
147
  echo 'echo "πŸ“‹ Following logs (Ctrl+C to stop):"' >> /start_hf_spaces.sh && \
148
+ echo 'tail -f dispatcher.log worker.log &' >> /start_hf_spaces.sh && \
149
  echo 'TAIL_PID=$!' >> /start_hf_spaces.sh && \
150
  echo 'wait $DISPATCHER_PID' >> /start_hf_spaces.sh && \
151
  echo 'kill $TAIL_PID 2>/dev/null || true' >> /start_hf_spaces.sh && \