crosse712 commited on
Commit
a7b73d3
·
1 Parent(s): fadb62b

Fix Dockerfile for HF Spaces deployment - improved nginx and supervisor config

Browse files
Files changed (2) hide show
  1. Dockerfile +71 -47
  2. app.py +53 -0
Dockerfile CHANGED
@@ -34,55 +34,79 @@ COPY backend/ ./backend/
34
  # Copy frontend build from builder stage
35
  COPY --from=frontend-builder /app/frontend/dist /usr/share/nginx/html
36
 
37
- # Configure nginx to serve frontend and proxy to backend
38
- RUN echo 'server { \n\
39
- listen 7860; \n\
40
- root /usr/share/nginx/html; \n\
41
- index index.html; \n\
42
- \n\
43
- location / { \n\
44
- try_files $uri $uri/ /index.html; \n\
45
- } \n\
46
- \n\
47
- location /api/ { \n\
48
- proxy_pass http://127.0.0.1:8000/; \n\
49
- proxy_http_version 1.1; \n\
50
- proxy_set_header Upgrade $http_upgrade; \n\
51
- proxy_set_header Connection "upgrade"; \n\
52
- proxy_set_header Host $host; \n\
53
- proxy_set_header X-Real-IP $remote_addr; \n\
54
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; \n\
55
- proxy_set_header X-Forwarded-Proto $scheme; \n\
56
- proxy_buffering off; \n\
57
- } \n\
58
- }' > /etc/nginx/sites-available/default
 
 
 
59
 
60
- # Create supervisor config
61
- RUN echo '[supervisord] \n\
62
- nodaemon=true \n\
63
- \n\
64
- [program:nginx] \n\
65
- command=nginx -g "daemon off;" \n\
66
- autostart=true \n\
67
- autorestart=true \n\
68
- stderr_logfile=/var/log/nginx.err.log \n\
69
- stdout_logfile=/var/log/nginx.out.log \n\
70
- \n\
71
- [program:backend] \n\
72
- command=python -m uvicorn backend.app.main:app --host 127.0.0.1 --port 8000 \n\
73
- directory=/app \n\
74
- autostart=true \n\
75
- autorestart=true \n\
76
- stderr_logfile=/var/log/backend.err.log \n\
77
- stdout_logfile=/var/log/backend.out.log \n\
78
- environment=USE_EXTREME_OPTIMIZATION="true",MAX_MEMORY_GB="3"' > /etc/supervisor/conf.d/supervisord.conf
 
 
 
 
 
 
 
 
 
 
 
 
 
79
 
80
- # Expose Hugging Face Spaces default port
 
 
 
 
 
 
 
81
  EXPOSE 7860
82
 
83
- # Health check
84
- HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
85
- CMD curl -f http://localhost:7860/ || exit 1
 
86
 
87
- # Start supervisor
88
- CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]
 
34
  # Copy frontend build from builder stage
35
  COPY --from=frontend-builder /app/frontend/dist /usr/share/nginx/html
36
 
37
+ # Create nginx configuration
38
+ RUN rm -f /etc/nginx/sites-enabled/default && \
39
+ echo 'server { \
40
+ listen 7860; \
41
+ server_name localhost; \
42
+ root /usr/share/nginx/html; \
43
+ index index.html; \
44
+ \
45
+ location / { \
46
+ try_files $uri $uri/ /index.html; \
47
+ } \
48
+ \
49
+ location /api/ { \
50
+ proxy_pass http://127.0.0.1:8000/; \
51
+ proxy_http_version 1.1; \
52
+ proxy_set_header Upgrade $http_upgrade; \
53
+ proxy_set_header Connection "upgrade"; \
54
+ proxy_set_header Host $host; \
55
+ proxy_set_header X-Real-IP $remote_addr; \
56
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; \
57
+ proxy_set_header X-Forwarded-Proto $scheme; \
58
+ proxy_buffering off; \
59
+ proxy_read_timeout 86400; \
60
+ } \
61
+ }' > /etc/nginx/sites-enabled/default
62
 
63
+ # Create supervisor configuration
64
+ RUN mkdir -p /var/log/supervisor && \
65
+ echo '[supervisord] \
66
+ nodaemon=true \
67
+ logfile=/var/log/supervisor/supervisord.log \
68
+ pidfile=/var/run/supervisord.pid \
69
+ \
70
+ [program:nginx] \
71
+ command=/usr/sbin/nginx -g "daemon off;" \
72
+ autostart=true \
73
+ autorestart=true \
74
+ priority=10 \
75
+ stdout_events_enabled=true \
76
+ stderr_events_enabled=true \
77
+ stdout_logfile=/dev/stdout \
78
+ stdout_logfile_maxbytes=0 \
79
+ stderr_logfile=/dev/stderr \
80
+ stderr_logfile_maxbytes=0 \
81
+ \
82
+ [program:backend] \
83
+ command=python -m uvicorn backend.app.main:app --host 127.0.0.1 --port 8000 --workers 1 \
84
+ directory=/app \
85
+ autostart=true \
86
+ autorestart=true \
87
+ priority=5 \
88
+ stdout_events_enabled=true \
89
+ stderr_events_enabled=true \
90
+ stdout_logfile=/dev/stdout \
91
+ stdout_logfile_maxbytes=0 \
92
+ stderr_logfile=/dev/stderr \
93
+ stderr_logfile_maxbytes=0 \
94
+ environment=USE_EXTREME_OPTIMIZATION="true",MAX_MEMORY_GB="3",PYTHONUNBUFFERED="1"' > /etc/supervisor/conf.d/supervisord.conf
95
 
96
+ # Create startup script
97
+ RUN echo '#!/bin/bash \
98
+ echo "Starting FastVLM Screen Observer..." \
99
+ echo "Starting supervisor..." \
100
+ exec /usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf' > /app/start.sh && \
101
+ chmod +x /app/start.sh
102
+
103
+ # Expose port
104
  EXPOSE 7860
105
 
106
+ # Environment variables
107
+ ENV USE_EXTREME_OPTIMIZATION=true
108
+ ENV MAX_MEMORY_GB=3
109
+ ENV PYTHONUNBUFFERED=1
110
 
111
+ # Start the application
112
+ CMD ["/app/start.sh"]
app.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Simple test app for Hugging Face Spaces - will be replaced by full app
3
+ """
4
+ import gradio as gr
5
+ import subprocess
6
+ import os
7
+ import time
8
+
9
+ def get_status():
10
+ """Check if services are running"""
11
+ try:
12
+ # Check if nginx is running
13
+ nginx_status = "✅ Nginx is configured" if os.path.exists('/etc/nginx/sites-enabled/default') else "❌ Nginx not configured"
14
+
15
+ # Check if backend directory exists
16
+ backend_status = "✅ Backend code present" if os.path.exists('/app/backend/app/main.py') else "❌ Backend code missing"
17
+
18
+ # Check if frontend was built
19
+ frontend_status = "✅ Frontend built" if os.path.exists('/usr/share/nginx/html/index.html') else "❌ Frontend not built"
20
+
21
+ return f"""
22
+ # FastVLM Screen Observer Status
23
+
24
+ {nginx_status}
25
+ {backend_status}
26
+ {frontend_status}
27
+
28
+ The full application is being deployed. Please check back in a few moments.
29
+
30
+ Visit: http://localhost:7860 once services are running.
31
+ """
32
+ except Exception as e:
33
+ return f"Error checking status: {str(e)}"
34
+
35
+ # Create simple Gradio interface for testing
36
+ demo = gr.Interface(
37
+ fn=get_status,
38
+ inputs=None,
39
+ outputs="markdown",
40
+ title="FastVLM Screen Observer - Deployment Status",
41
+ description="Checking deployment status..."
42
+ )
43
+
44
+ if __name__ == "__main__":
45
+ # Try to start supervisor in background
46
+ try:
47
+ subprocess.Popen(["/app/start.sh"])
48
+ time.sleep(2)
49
+ except:
50
+ pass
51
+
52
+ # Launch Gradio on port 7860
53
+ demo.launch(server_name="0.0.0.0", server_port=7860)