Aasher commited on
Commit
15ae77a
·
1 Parent(s): cdb3d07

feat: Containerize the project using Docker for production

Browse files
Files changed (3) hide show
  1. .dockerignore +22 -0
  2. .gitattributes +35 -0
  3. Dockerfile +69 -0
.dockerignore ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Ignore Python cache files
2
+ __pycache__/
3
+ *.pyc
4
+ *.pyo
5
+
6
+ # Ignore virtual environments
7
+ venv/
8
+ env/
9
+
10
+ .venv
11
+ .env
12
+
13
+ # Ignore logs
14
+ *.log
15
+
16
+ # Ignore local configuration files
17
+ *.env
18
+
19
+ # Ignore any other unnecessary files
20
+ *.DS_Store
21
+ *.db
22
+ *.sqlite3
.gitattributes ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tar filter=lfs diff=lfs merge=lfs -text
29
+ *.tflite filter=lfs diff=lfs merge=lfs -text
30
+ *.tgz filter=lfs diff=lfs merge=lfs -text
31
+ *.wasm filter=lfs diff=lfs merge=lfs -text
32
+ *.xz filter=lfs diff=lfs merge=lfs -text
33
+ *.zip filter=lfs diff=lfs merge=lfs -text
34
+ *.zst filter=lfs diff=lfs merge=lfs -text
35
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
Dockerfile ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Use the official Python 3.11 slim image as the base
2
+ FROM python:3.1-slim
3
+
4
+ # --- Install System Dependencies, uv, and Node.js/npm/npx ---
5
+ # Install curl (for uv script), nodejs & npm (for npx), git (optional, but sometimes needed by deps)
6
+ # Install uv using its official script
7
+ # Install npx globally using npm (often included with recent npm, but explicit install is safer)
8
+ # Clean up apt cache to reduce image size
9
+ RUN apt-get update && \
10
+ apt-get install -y --no-install-recommends curl nodejs npm git && \
11
+ curl -LsSf https://astral.sh/uv/install.sh | sh && \
12
+ mv /root/.local/bin/uv /usr/local/bin/uv && \
13
+ # mv /root/.local/bin/uvx /usr/local/bin/uvx # uvx might not be needed unless you use uv run directly
14
+ npm install -g npx && \
15
+ apt-get clean && \
16
+ rm -rf /var/lib/apt/lists/*
17
+
18
+ # --- Python Dependency Installation (as root for system-wide access) ---
19
+ # Create cache directory for uv
20
+ RUN mkdir -p /.cache/uv
21
+
22
+ # Copy only the pyproject.toml file first to leverage Docker layer caching
23
+ COPY pyproject.toml .
24
+
25
+ # Install Python dependencies using uv sync based on pyproject.toml
26
+ # This reads dependencies and installs them efficiently
27
+ # Remove the uv cache after installation if not needed later to save space
28
+ RUN uv sync --system && \
29
+ rm -rf /.cache/uv/*
30
+
31
+ # --- Non-Root User Setup ---
32
+ # Create a non-root user 'user' with ID 1000 and create their home directory
33
+ # Note: Cache was already cleaned, so no need to chown it here.
34
+ RUN useradd -m -u 1000 user
35
+ # Switch to the non-root user
36
+ USER user
37
+
38
+ # --- Environment Setup ---
39
+ # Set the home directory for the user
40
+ ENV HOME=/home/user
41
+ # Add user's local bin to PATH (though we installed system-wide with uv sync --system)
42
+ # Ensure Python output is sent straight to terminal without being buffered
43
+ # Set the default port expected by Hugging Face Spaces for web apps
44
+ ENV PATH="/home/user/.local/bin:$PATH" \
45
+ PYTHONUNBUFFERED=1 \
46
+ PORT=7860
47
+
48
+ # Set the working directory for the application inside the user's home
49
+ WORKDIR $HOME/app
50
+
51
+ # --- Application Code ---
52
+ # Copy the rest of the application files needed at runtime
53
+ # Ensure the non-root user owns these files
54
+ # Specific copies are better for caching than 'COPY . .' after dependency install
55
+ COPY --chown=user:user ./chainlit_ui.py ./chainlit_ui.py
56
+ COPY --chown=user:user ./mcp.json ./mcp.json
57
+ COPY --chown=user:user ./src ./src
58
+ COPY --chown=user:user ./public ./public
59
+ # If you have a .env file for local dev, ensure it's NOT copied (use .dockerignore)
60
+ # Secrets should come from Hugging Face Secrets management
61
+
62
+ # --- Runtime ---
63
+ # Expose the port Chainlit will run on (standard HF Spaces port)
64
+ EXPOSE 7860
65
+
66
+ # Define the command to run the Chainlit application
67
+ # Listen on all interfaces (0.0.0.0) on the designated port
68
+ # Do NOT use the --watch (-w) flag in production
69
+ CMD ["chainlit", "run", "chainlit_ui.py", "--host", "0.0.0.0", "--port", "7860"]