jens-l commited on
Commit
1462647
·
1 Parent(s): 7c71035

feat: improve Docker deployment with analytics disable and nginx optimization

Browse files
Files changed (5) hide show
  1. Dockerfile +10 -3
  2. app.py +6 -1
  3. manifest.json +16 -0
  4. nginx.conf +39 -64
  5. start.sh +1 -8
Dockerfile CHANGED
@@ -12,10 +12,10 @@ WORKDIR /app
12
  COPY ./requirements.txt requirements.txt
13
  RUN pip install --no-cache-dir --upgrade -r requirements.txt
14
 
15
- # Copy nginx configuration as main config
16
- COPY nginx.conf /etc/nginx/nginx.conf
17
 
18
- # Create all nginx directories and set permissions for user
19
  RUN mkdir -p /var/run/nginx /var/log/nginx /var/lib/nginx/body /var/lib/nginx/fastcgi \
20
  /var/lib/nginx/proxy /var/lib/nginx/scgi /var/lib/nginx/uwsgi && \
21
  chown -R user:user /var/run/nginx /var/log/nginx /var/lib/nginx
@@ -27,5 +27,12 @@ RUN chmod +x /app/start.sh
27
  # Switch to user for execution
28
  USER user
29
  ENV PATH="/home/user/.local/bin:$PATH"
 
 
 
 
 
 
 
30
 
31
  CMD ["/app/start.sh"]
 
12
  COPY ./requirements.txt requirements.txt
13
  RUN pip install --no-cache-dir --upgrade -r requirements.txt
14
 
15
+ # Copy nginx configuration
16
+ COPY nginx.conf /app/nginx.conf
17
 
18
+ # Create nginx directories and set permissions for user
19
  RUN mkdir -p /var/run/nginx /var/log/nginx /var/lib/nginx/body /var/lib/nginx/fastcgi \
20
  /var/lib/nginx/proxy /var/lib/nginx/scgi /var/lib/nginx/uwsgi && \
21
  chown -R user:user /var/run/nginx /var/log/nginx /var/lib/nginx
 
27
  # Switch to user for execution
28
  USER user
29
  ENV PATH="/home/user/.local/bin:$PATH"
30
+ ENV GRADIO_ANALYTICS_ENABLED=False
31
+ ENV GRADIO_ANALYTICS_ENABLED=false
32
+ ENV HF_HUB_DISABLE_TELEMETRY=1
33
+ ENV GRADIO_TELEMETRY_ENABLED=False
34
+ ENV MPLCONFIGDIR=/tmp/matplotlib
35
+
36
+ EXPOSE 7860
37
 
38
  CMD ["/app/start.sh"]
app.py CHANGED
@@ -563,7 +563,11 @@ class GradioUI:
563
  )
564
 
565
  def launch(self, share: bool = True, **kwargs):
566
- self.create_app().launch(debug=True, share=share, **kwargs)
 
 
 
 
567
 
568
  def create_app(self):
569
  import gradio as gr
@@ -573,6 +577,7 @@ class GradioUI:
573
  theme=gr.themes.Soft(),
574
  fill_height=True,
575
  fill_width=True,
 
576
  ) as demo:
577
  gr.Markdown("# 💗Likable")
578
 
 
563
  )
564
 
565
  def launch(self, share: bool = True, **kwargs):
566
+ self.create_app().launch(
567
+ debug=True,
568
+ share=share,
569
+ **kwargs,
570
+ )
571
 
572
  def create_app(self):
573
  import gradio as gr
 
577
  theme=gr.themes.Soft(),
578
  fill_height=True,
579
  fill_width=True,
580
+ analytics_enabled=False,
581
  ) as demo:
582
  gr.Markdown("# 💗Likable")
583
 
manifest.json ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "💗Likable",
3
+ "short_name": "Likable",
4
+ "description": "It's almost lovable...",
5
+ "start_url": "/",
6
+ "display": "standalone",
7
+ "theme_color": "#000000",
8
+ "background_color": "#ffffff",
9
+ "icons": [
10
+ {
11
+ "src": "/favicon.ico",
12
+ "sizes": "any",
13
+ "type": "image/x-icon"
14
+ }
15
+ ]
16
+ }
nginx.conf CHANGED
@@ -1,93 +1,68 @@
1
- # Basic nginx configuration for running as non-root user
2
- worker_processes auto;
3
- pid /var/run/nginx/nginx.pid;
4
- error_log /var/log/nginx/error.log;
5
 
6
  events {
7
- worker_connections 768;
8
  }
9
 
10
  http {
11
  include /etc/nginx/mime.types;
12
  default_type application/octet-stream;
 
 
 
 
13
 
14
- # Temp directories that user can write to
15
- client_body_temp_path /var/lib/nginx/body;
16
- proxy_temp_path /var/lib/nginx/proxy;
17
- fastcgi_temp_path /var/lib/nginx/fastcgi;
18
- uwsgi_temp_path /var/lib/nginx/uwsgi;
19
- scgi_temp_path /var/lib/nginx/scgi;
20
-
21
- access_log /var/log/nginx/access.log;
22
-
23
- # Upstream configuration for better load balancing and failover
24
- upstream preview_backend {
25
- server localhost:7861 max_fails=1 fail_timeout=5s;
26
- keepalive 32;
27
  }
28
 
29
- upstream main_backend {
30
- server localhost:7862 max_fails=1 fail_timeout=5s;
31
- keepalive 32;
32
  }
33
 
34
  server {
35
  listen 7860 default_server;
36
- listen [::]:7860 default_server;
37
-
38
  server_name _;
39
 
40
- # Main Gradio app - serve on root path, proxy to internal port 7862
41
- location / {
42
- proxy_pass http://main_backend;
43
- proxy_http_version 1.1;
44
- proxy_set_header Upgrade $http_upgrade;
45
- proxy_set_header Connection 'upgrade';
46
- proxy_set_header Host $host;
47
- proxy_set_header X-Real-IP $remote_addr;
48
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
49
- proxy_set_header X-Forwarded-Host $host;
50
- proxy_set_header X-Forwarded-Proto $scheme;
51
- proxy_cache_bypass $http_upgrade;
52
- proxy_read_timeout 86400;
53
- proxy_connect_timeout 10s;
54
- proxy_send_timeout 10s;
55
- proxy_redirect off;
56
 
57
- # Buffer settings to handle temporary unavailability
58
- proxy_buffering on;
59
- proxy_buffer_size 4k;
60
- proxy_buffers 8 4k;
61
- proxy_busy_buffers_size 8k;
62
  }
63
 
64
- # Preview apps - route to internal port 7861
65
  location /preview/ {
66
- # Remove /preview prefix and pass to the sandbox app
67
  rewrite /preview/(.*) /$1 break;
68
  proxy_pass http://preview_backend;
 
 
69
  proxy_http_version 1.1;
70
  proxy_set_header Upgrade $http_upgrade;
71
- proxy_set_header Connection 'upgrade';
72
- proxy_set_header Host $host;
73
- proxy_set_header X-Real-IP $remote_addr;
74
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
75
- proxy_set_header X-Forwarded-Host $host;
76
  proxy_set_header X-Forwarded-Proto $scheme;
77
- proxy_cache_bypass $http_upgrade;
78
- proxy_read_timeout 86400;
79
- proxy_connect_timeout 10s;
80
- proxy_send_timeout 10s;
81
- proxy_redirect off;
82
 
83
- # Buffer settings and retry logic for preview apps
84
- proxy_buffering on;
85
- proxy_buffer_size 4k;
86
- proxy_buffers 8 4k;
87
- proxy_busy_buffers_size 8k;
88
- proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
89
- proxy_next_upstream_tries 3;
90
- proxy_next_upstream_timeout 10s;
 
 
91
  }
92
  }
93
  }
 
1
+ worker_processes 1;
2
+ daemon off;
3
+ pid /tmp/nginx.pid;
4
+ error_log /tmp/error.log;
5
 
6
  events {
7
+ worker_connections 1024;
8
  }
9
 
10
  http {
11
  include /etc/nginx/mime.types;
12
  default_type application/octet-stream;
13
+ access_log /tmp/access.log;
14
+ sendfile on;
15
+ keepalive_timeout 65;
16
+ client_max_body_size 100M;
17
 
18
+ upstream main_backend {
19
+ server 127.0.0.1:7862;
 
 
 
 
 
 
 
 
 
 
 
20
  }
21
 
22
+ upstream preview_backend {
23
+ server 127.0.0.1:7861;
 
24
  }
25
 
26
  server {
27
  listen 7860 default_server;
 
 
28
  server_name _;
29
 
30
+ # Serve manifest.json directly
31
+ location = /manifest.json {
32
+ root /app;
33
+ add_header Content-Type "application/manifest+json";
34
+ try_files $uri =404;
35
+ }
 
 
 
 
 
 
 
 
 
 
36
 
37
+ # Handle missing fallback font files gracefully
38
+ location ~ ^/static/fonts/(ui-sans-serif|system-ui)/ {
39
+ access_log off;
40
+ return 204;
 
41
  }
42
 
 
43
  location /preview/ {
 
44
  rewrite /preview/(.*) /$1 break;
45
  proxy_pass http://preview_backend;
46
+ proxy_buffering off;
47
+ proxy_redirect off;
48
  proxy_http_version 1.1;
49
  proxy_set_header Upgrade $http_upgrade;
50
+ proxy_set_header Connection "upgrade";
51
+ proxy_set_header Host $http_host;
52
+ proxy_set_header X-Forwarded-Host $http_host;
 
 
53
  proxy_set_header X-Forwarded-Proto $scheme;
54
+ }
 
 
 
 
55
 
56
+ location / {
57
+ proxy_pass http://main_backend;
58
+ proxy_buffering off;
59
+ proxy_redirect off;
60
+ proxy_http_version 1.1;
61
+ proxy_set_header Upgrade $http_upgrade;
62
+ proxy_set_header Connection "upgrade";
63
+ proxy_set_header Host $http_host;
64
+ proxy_set_header X-Forwarded-Host $http_host;
65
+ proxy_set_header X-Forwarded-Proto $scheme;
66
  }
67
  }
68
  }
start.sh CHANGED
@@ -1,15 +1,8 @@
1
  #!/bin/bash
2
 
3
- # Create necessary directories
4
- mkdir -p /var/run/nginx /var/lib/nginx/body /var/lib/nginx/proxy /var/lib/nginx/fastcgi /var/lib/nginx/uwsgi /var/lib/nginx/scgi /var/log/nginx
5
-
6
- # Set proper permissions
7
- chmod 755 /var/run/nginx /var/lib/nginx/* /var/log/nginx
8
-
9
  # Start nginx with our configuration
10
  echo "Starting nginx..."
11
- nginx -c /app/nginx.conf -g "daemon off;" &
12
- sleep 2
13
 
14
  # Start the main Gradio app
15
  echo "Starting Gradio app on port 7862..."
 
1
  #!/bin/bash
2
 
 
 
 
 
 
 
3
  # Start nginx with our configuration
4
  echo "Starting nginx..."
5
+ nginx -c /app/nginx.conf &
 
6
 
7
  # Start the main Gradio app
8
  echo "Starting Gradio app on port 7862..."