liaoch commited on
Commit
1ce97d9
·
1 Parent(s): 8cffb5a

Update for Hugging Face Spaces deployment: Change port to 80 and update documentation

Browse files
Files changed (3) hide show
  1. Dockerfile +5 -6
  2. README.md +7 -6
  3. app.py +2 -2
Dockerfile CHANGED
@@ -72,16 +72,15 @@ RUN . /app/venv/bin/activate && pip install --no-cache-dir -r requirements.txt
72
  # Copy the rest of the application code into the container
73
  COPY . .
74
 
75
- # Make port 5001 available to the world outside this container
76
- # This should match the port Flask runs on in app.py (or Gunicorn config)
77
- EXPOSE 5001
78
 
79
  # Define environment variables
80
  # IMPORTANT: Set a strong FLASK_SECRET_KEY when running the container!
81
  # Using a placeholder here for demonstration.
82
  ENV FLASK_APP=app.py
83
  ENV FLASK_RUN_HOST=0.0.0.0
84
- ENV FLASK_RUN_PORT=5001
85
  ENV FLASK_SECRET_KEY="replace_this_in_docker_run_with_a_real_secret"
86
  # Add venv's bin to the PATH for subsequent commands (like CMD)
87
  ENV PATH="/app/venv/bin:$PATH"
@@ -92,7 +91,7 @@ ENTRYPOINT []
92
  # Run the application using Gunicorn when the container launches
93
  # Use the full path to gunicorn within the virtual environment
94
  # Bind to 0.0.0.0 to accept connections from outside the container
95
- # Use the port defined by FLASK_RUN_PORT
96
  # The number of workers (e.g., --workers 3) can be adjusted based on server resources
97
  # Use JSON form with the absolute path to gunicorn in the venv to avoid PATH issues
98
- CMD ["/app/venv/bin/gunicorn", "--workers", "3", "--bind", "0.0.0.0:5001", "--timeout", "60", "app:app"]
 
72
  # Copy the rest of the application code into the container
73
  COPY . .
74
 
75
+ # Make port 80 available to the world outside this container (required for Hugging Face Spaces)
76
+ EXPOSE 80
 
77
 
78
  # Define environment variables
79
  # IMPORTANT: Set a strong FLASK_SECRET_KEY when running the container!
80
  # Using a placeholder here for demonstration.
81
  ENV FLASK_APP=app.py
82
  ENV FLASK_RUN_HOST=0.0.0.0
83
+ ENV FLASK_RUN_PORT=80
84
  ENV FLASK_SECRET_KEY="replace_this_in_docker_run_with_a_real_secret"
85
  # Add venv's bin to the PATH for subsequent commands (like CMD)
86
  ENV PATH="/app/venv/bin:$PATH"
 
91
  # Run the application using Gunicorn when the container launches
92
  # Use the full path to gunicorn within the virtual environment
93
  # Bind to 0.0.0.0 to accept connections from outside the container
94
+ # Use port 80 (required for Hugging Face Spaces)
95
  # The number of workers (e.g., --workers 3) can be adjusted based on server resources
96
  # Use JSON form with the absolute path to gunicorn in the venv to avoid PATH issues
97
+ CMD ["/app/venv/bin/gunicorn", "--workers", "3", "--bind", "0.0.0.0:80", "--timeout", "60", "app:app"]
README.md CHANGED
@@ -1,11 +1,12 @@
1
  ---
2
  title: Mermaid Rendering Docker
3
- emoji: 🚀
4
- colorFrom: indigo
5
- colorTo: yellow
6
  sdk: docker
7
  pinned: false
8
  license: mit
 
9
  ---
10
 
11
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
@@ -68,15 +69,15 @@ This is the recommended way to run the application, as it bundles all dependenci
68
  ```bash
69
  # Replace 'YOUR_GENERATED_SECRET_KEY' with the key from step 2.
70
  # -d: Run in detached mode (background)
71
- # -p 80:5001: Map port 80 on the host to port 5001 in the container
72
  # --name mermaid-app: Assign a name to the container for easier management
73
  # -e FLASK_SECRET_KEY=...: Set the environment variable inside the container
74
  # mermaid-renderer-app: The name of the image to run
75
- docker run -d -p 80:5001 --name mermaid-app \
76
  -e FLASK_SECRET_KEY='YOUR_GENERATED_SECRET_KEY' \
77
  mermaid-renderer-app
78
  ```
79
- *Note:* If port 80 is already in use on your host, choose a different host port (e.g., `-p 8080:5001`).
80
 
81
  5. **Access the Application:** Open your web browser and navigate to `http://localhost` (or `http://your_server_ip` if deploying remotely). If you used a different host port, include it (e.g., `http://localhost:8080`).
82
 
 
1
  ---
2
  title: Mermaid Rendering Docker
3
+ emoji: 🔥
4
+ colorFrom: purple
5
+ colorTo: red
6
  sdk: docker
7
  pinned: false
8
  license: mit
9
+ short_description: mermaid-rendering docker version
10
  ---
11
 
12
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
69
  ```bash
70
  # Replace 'YOUR_GENERATED_SECRET_KEY' with the key from step 2.
71
  # -d: Run in detached mode (background)
72
+ # -p 80:80: Map port 80 on the host to port 80 in the container
73
  # --name mermaid-app: Assign a name to the container for easier management
74
  # -e FLASK_SECRET_KEY=...: Set the environment variable inside the container
75
  # mermaid-renderer-app: The name of the image to run
76
+ docker run -d -p 80:80 --name mermaid-app \
77
  -e FLASK_SECRET_KEY='YOUR_GENERATED_SECRET_KEY' \
78
  mermaid-renderer-app
79
  ```
80
+ *Note:* If port 80 is already in use on your host, choose a different host port (e.g., `-p 8080:80`).
81
 
82
  5. **Access the Application:** Open your web browser and navigate to `http://localhost` (or `http://your_server_ip` if deploying remotely). If you used a different host port, include it (e.g., `http://localhost:8080`).
83
 
app.py CHANGED
@@ -184,5 +184,5 @@ if __name__ == '__main__':
184
  # Use 0.0.0.0 to be accessible on the network
185
  # Set debug=False for production-like testing, or True for development features
186
  is_debug = os.environ.get('FLASK_DEBUG', 'false').lower() == 'true'
187
- # Changed default port from 5000 to 5001 to avoid conflicts
188
- app.run(debug=is_debug, host='0.0.0.0', port=int(os.environ.get('PORT', 5001)))
 
184
  # Use 0.0.0.0 to be accessible on the network
185
  # Set debug=False for production-like testing, or True for development features
186
  is_debug = os.environ.get('FLASK_DEBUG', 'false').lower() == 'true'
187
+ # Use port 80 for Hugging Face Spaces compatibility
188
+ app.run(debug=is_debug, host='0.0.0.0', port=int(os.environ.get('PORT', 80)))