AntDX316 commited on
Commit
3ecdadc
·
1 Parent(s): 227e0d8
Files changed (3) hide show
  1. Dockerfile +24 -3
  2. README.md +17 -1
  3. docker-compose.yml +7 -2
Dockerfile CHANGED
@@ -1,12 +1,33 @@
1
  FROM nginx:alpine
2
 
 
 
 
3
  # Copy the application files to the nginx html directory
4
  COPY index.html /usr/share/nginx/html/
5
  COPY styles.css /usr/share/nginx/html/
6
  COPY script.js /usr/share/nginx/html/
7
 
8
- # Expose port 80
9
- EXPOSE 80
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
 
11
- # Start Nginx server
12
  CMD ["nginx", "-g", "daemon off;"]
 
1
  FROM nginx:alpine
2
 
3
+ # Create a directory for the app
4
+ WORKDIR /app
5
+
6
  # Copy the application files to the nginx html directory
7
  COPY index.html /usr/share/nginx/html/
8
  COPY styles.css /usr/share/nginx/html/
9
  COPY script.js /usr/share/nginx/html/
10
 
11
+ # Fix permission issues - create necessary directories and set permissions
12
+ RUN mkdir -p /var/cache/nginx /var/run /var/log/nginx && \
13
+ chown -R nginx:nginx /var/cache/nginx /var/run /var/log/nginx /usr/share/nginx/html && \
14
+ chmod -R 755 /var/cache/nginx /var/run /var/log/nginx /usr/share/nginx/html
15
+
16
+ # Create custom Nginx configuration to run as non-root
17
+ RUN echo $'server {\n\
18
+ listen 8080;\n\
19
+ server_name localhost;\n\
20
+ location / {\n\
21
+ root /usr/share/nginx/html;\n\
22
+ index index.html;\n\
23
+ }\n\
24
+ }' > /etc/nginx/conf.d/default.conf
25
+
26
+ # Use non-root user
27
+ USER nginx
28
+
29
+ # Change the port to 8080 since non-root can't bind to 80
30
+ EXPOSE 8080
31
 
32
+ # Start Nginx server with custom config
33
  CMD ["nginx", "-g", "daemon off;"]
README.md CHANGED
@@ -54,7 +54,7 @@ This application can also be run using Docker, which ensures consistent behavior
54
 
55
  2. Run the container:
56
  ```
57
- docker run -p 8080:80 battle-simulator
58
  ```
59
 
60
  3. Open your browser and navigate to:
@@ -79,6 +79,22 @@ This application can also be run using Docker, which ensures consistent behavior
79
  docker-compose down
80
  ```
81
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82
  ## How to Use
83
 
84
  - **View Unit Info**: Click on any unit to see its details in the info panel
 
54
 
55
  2. Run the container:
56
  ```
57
+ docker run -p 8080:8080 battle-simulator
58
  ```
59
 
60
  3. Open your browser and navigate to:
 
79
  docker-compose down
80
  ```
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
+
93
+ 1. Push your code to a GitHub repository
94
+ 2. Create a new Space on Hugging Face with Docker SDK
95
+ 3. Connect your GitHub repository to the Space
96
+ 4. The Space will automatically build and deploy your application
97
+
98
  ## How to Use
99
 
100
  - **View Unit Info**: Click on any unit to see its details in the info panel
docker-compose.yml CHANGED
@@ -4,8 +4,13 @@ services:
4
  battle-simulator:
5
  build: .
6
  ports:
7
- - "8080:80"
8
  volumes:
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
 
 
 
 
 
 
4
  battle-simulator:
5
  build: .
6
  ports:
7
+ - "8080:8080"
8
  volumes:
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