crosse712 commited on
Commit ·
a7b73d3
1
Parent(s): fadb62b
Fix Dockerfile for HF Spaces deployment - improved nginx and supervisor config
Browse files- Dockerfile +71 -47
- 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 |
-
#
|
| 38 |
-
RUN
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
\
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
proxy_set_header
|
| 53 |
-
proxy_set_header
|
| 54 |
-
proxy_set_header
|
| 55 |
-
proxy_set_header X-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
|
|
|
|
|
|
|
|
|
| 59 |
|
| 60 |
-
# Create supervisor
|
| 61 |
-
RUN
|
| 62 |
-
|
| 63 |
-
\
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
\
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
stderr_logfile=/
|
| 77 |
-
|
| 78 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
|
| 80 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
EXPOSE 7860
|
| 82 |
|
| 83 |
-
#
|
| 84 |
-
|
| 85 |
-
|
|
|
|
| 86 |
|
| 87 |
-
# Start
|
| 88 |
-
CMD ["/
|
|
|
|
| 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)
|