AntDX316 commited on
Commit
51bd74e
·
1 Parent(s): 480ee70
Files changed (4) hide show
  1. Dockerfile +15 -17
  2. README.md +6 -5
  3. docker-compose.yml +3 -1
  4. nginx.conf +40 -0
Dockerfile CHANGED
@@ -1,27 +1,25 @@
1
  FROM nginx:alpine
2
 
3
- WORKDIR /app
 
4
 
 
 
 
 
 
 
 
 
 
 
 
5
  COPY index.html /usr/share/nginx/html/
6
  COPY styles.css /usr/share/nginx/html/
7
  COPY script.js /usr/share/nginx/html/
8
 
9
- # Create necessary writable temp directories in /tmp
10
- RUN mkdir -p /tmp/nginx/client_temp && \
11
- chown -R nginx:nginx /tmp/nginx
12
-
13
- # Custom Nginx config using /tmp for temp files
14
- RUN echo $'server {\n\
15
- listen 8080;\n\
16
- server_name localhost;\n\
17
- client_body_temp_path /tmp/nginx/client_temp;\n\
18
- location / {\n\
19
- root /usr/share/nginx/html;\n\
20
- index index.html;\n\
21
- }\n\
22
- }' > /etc/nginx/conf.d/default.conf
23
-
24
- USER nginx
25
  EXPOSE 8080
26
 
 
27
  CMD ["nginx", "-g", "daemon off;"]
 
1
  FROM nginx:alpine
2
 
3
+ # Remove the default configs that reference /var/cache/nginx
4
+ RUN rm -f /etc/nginx/nginx.conf && rm -f /etc/nginx/conf.d/default.conf
5
 
6
+ # Copy in your custom nginx.conf
7
+ COPY nginx.conf /etc/nginx/nginx.conf
8
+
9
+ # Create writable temp directories in /tmp
10
+ RUN mkdir -p /tmp/client_temp \
11
+ /tmp/proxy_temp \
12
+ /tmp/fastcgi_temp \
13
+ /tmp/scgi_temp \
14
+ /tmp/uwsgi_temp
15
+
16
+ # Copy the application files to the nginx html directory
17
  COPY index.html /usr/share/nginx/html/
18
  COPY styles.css /usr/share/nginx/html/
19
  COPY script.js /usr/share/nginx/html/
20
 
21
+ # Hugging Face Spaces typically expects the app on port 8080
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  EXPOSE 8080
23
 
24
+ # Start Nginx in the foreground
25
  CMD ["nginx", "-g", "daemon off;"]
README.md CHANGED
@@ -81,12 +81,13 @@ This application can also be run using Docker, which ensures consistent behavior
81
 
82
  ### Deploying to Hugging Face Spaces
83
 
84
- This application is compatible with Hugging Face Spaces Docker deployments. The Docker configuration has been specifically adjusted to work in the Hugging Face Spaces environment:
85
 
86
- 1. The Nginx container runs as a non-root user to comply with security requirements
87
- 2. The web server listens on port 8080 instead of the default 80
88
- 3. Required directories are pre-created with appropriate permissions
89
- 4. The configuration handles read-only filesystem restrictions
 
90
 
91
  To deploy to Hugging Face Spaces:
92
 
 
81
 
82
  ### Deploying to Hugging Face Spaces
83
 
84
+ This application is compatible with Hugging Face Spaces Docker deployments. The Docker configuration has been specifically adjusted to work in the Hugging Face Spaces environment, which has stricter security and filesystem restrictions:
85
 
86
+ 1. **Custom nginx.conf**: We use a custom nginx configuration that redirects all temp directories to /tmp, which is writable in Hugging Face Spaces
87
+ 2. **Default Config Removal**: We remove the default nginx configuration files that reference /var/cache/nginx (which is read-only in Spaces)
88
+ 3. **Writable Temp Directories**: We create temp directories in /tmp with appropriate permissions
89
+ 4. **Port 8080**: The web server listens on port 8080 (the default port expected by Hugging Face Spaces)
90
+ 5. **Read-only Filesystem Handling**: The configuration properly handles read-only filesystem restrictions that are common in containerized environments
91
 
92
  To deploy to Hugging Face Spaces:
93
 
docker-compose.yml CHANGED
@@ -9,8 +9,10 @@ services:
9
  - ./index.html:/usr/share/nginx/html/index.html
10
  - ./styles.css:/usr/share/nginx/html/styles.css
11
  - ./script.js:/usr/share/nginx/html/script.js
 
12
  # Add read-only flag to prevent write attempts to read-only filesystem in HF Spaces
13
  read_only: false
14
  # Specific settings for Hugging Face Spaces or similar restricted environments
15
  environment:
16
- - NGINX_ENTRYPOINT_QUIET_LOGS=1
 
 
9
  - ./index.html:/usr/share/nginx/html/index.html
10
  - ./styles.css:/usr/share/nginx/html/styles.css
11
  - ./script.js:/usr/share/nginx/html/script.js
12
+ - ./nginx.conf:/etc/nginx/nginx.conf
13
  # Add read-only flag to prevent write attempts to read-only filesystem in HF Spaces
14
  read_only: false
15
  # Specific settings for Hugging Face Spaces or similar restricted environments
16
  environment:
17
+ - NGINX_ENTRYPOINT_QUIET_LOGS=1
18
+ - NGINX_WORKER_PROCESSES=1
nginx.conf ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ worker_processes auto;
2
+
3
+ error_log /dev/stderr warn;
4
+ pid /tmp/nginx.pid;
5
+
6
+ events {
7
+ worker_connections 1024;
8
+ }
9
+
10
+ http {
11
+ include /etc/nginx/mime.types;
12
+ default_type application/octet-stream;
13
+
14
+ # Use /tmp for all temp files (it's writable in Spaces)
15
+ client_body_temp_path /tmp/client_temp;
16
+ proxy_temp_path /tmp/proxy_temp;
17
+ fastcgi_temp_path /tmp/fastcgi_temp;
18
+ scgi_temp_path /tmp/scgi_temp;
19
+ uwsgi_temp_path /tmp/uwsgi_temp;
20
+
21
+ log_format main '$remote_addr - $remote_user [$time_local] "$request" '
22
+ '$status $body_bytes_sent "$http_referer" '
23
+ '"$http_user_agent" "$http_x_forwarded_for"';
24
+
25
+ access_log /dev/stdout main;
26
+
27
+ sendfile on;
28
+ keepalive_timeout 65;
29
+
30
+ # Basic server block on port 8080
31
+ server {
32
+ listen 8080;
33
+ server_name localhost;
34
+
35
+ location / {
36
+ root /usr/share/nginx/html;
37
+ index index.html;
38
+ }
39
+ }
40
+ }