Executor-Tyrant-Framework commited on
Commit
daa1f06
·
verified ·
1 Parent(s): f8420ad

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +23 -117
Dockerfile CHANGED
@@ -1,136 +1,42 @@
1
- # Dockerfile for Clawdbot Dev Assistant on HuggingFace Spaces
2
- #
3
- # CHANGELOG [2025-01-30 - Josh]
4
- # REBUILD: Updated to Gradio 5.0+ for type="messages" support
5
- # Added translation layer for Kimi K2.5 tool calling
6
- # Added multimodal file upload support
7
- #
8
- # CHANGELOG [2025-01-31 - Claude]
9
- # FIXED: Permissions for HF Spaces runtime user (UID 1000).
10
- # PROBLEM: HF Spaces run containers as user 1000, not root. Directories
11
- # created during build (as root) weren't writable at runtime, causing
12
- # ChromaDB to silently fail when trying to create SQLite files.
13
- # FIX: chown all writable directories to 1000:1000, then switch to USER 1000.
14
- #
15
- # ALSO: Added /data directory for HF persistent storage.
16
- # /data is the ONLY path that survives container restarts on HF Spaces.
17
- # Must enable "Persistent Storage" in Space Settings for /data to exist.
18
- # Falls back to /workspace (ephemeral) if /data isn't available.
19
- #
20
- # FEATURES:
21
- # - Python 3.11 for Gradio
22
- # - Gradio 5.0+ for modern chat interface
23
- # - ChromaDB for vector search
24
- # - Git for repo cloning
25
- # - Optimized layer caching
26
- # - Correct permissions for HF Spaces (UID 1000)
27
-
28
  FROM python:3.11-slim
29
 
30
- # CACHE BUSTER: Force rebuild when dependencies change
31
- # Update this date to invalidate Docker cache for everything below
32
- ENV REBUILD_DATE=2025-01-31-v1
33
-
34
- # Set working directory
35
  WORKDIR /app
36
 
37
  # Install system dependencies
38
- RUN apt-get update && apt-get install -y \
39
- git \
40
- build-essential \
41
- curl \
42
- && rm -rf /var/lib/apt/lists/*
43
 
44
- # Copy requirements first (for layer caching)
45
  COPY requirements.txt .
 
46
 
47
- # FORCE CLEAN INSTALL: Uninstall any cached Gradio, then install fresh
48
- RUN pip uninstall -y gradio gradio-client 2>/dev/null; \
49
- pip install --no-cache-dir -r requirements.txt
50
-
51
- # Create workspace directory for repository
52
- RUN mkdir -p /workspace
53
 
54
- # Clone E-T Systems repository (if URL provided via build arg)
55
- ARG REPO_URL=""
56
- RUN if [ -n "$REPO_URL" ]; then \
57
- git clone $REPO_URL /workspace/e-t-systems; \
58
- else \
59
- mkdir -p /workspace/e-t-systems && \
60
- echo "# E-T Systems" > /workspace/e-t-systems/README.md && \
61
- echo "Repository will be cloned on first run or mounted via Space secrets."; \
62
- fi
63
 
64
- # Copy application code and entrypoint
65
  COPY recursive_context.py .
66
  COPY app.py .
67
  COPY entrypoint.sh .
68
 
69
- # Make entrypoint executable
70
- RUN chmod +x entrypoint.sh
71
-
72
- # =============================================================================
73
- # PERMISSIONS FIX FOR HF SPACES
74
- # =============================================================================
75
- # CHANGELOG [2025-01-31 - Claude]
76
- # HF Spaces run as UID 1000, not root. All directories that the app needs
77
- # to write to must be owned by 1000:1000, otherwise ChromaDB, conversation
78
- # saves, and file downloads will silently fail.
79
- #
80
- # /workspace - ephemeral storage (wiped on restart, but works within session)
81
- # /workspace/chroma_db - ChromaDB fallback if /data isn't available
82
- # /data - HF persistent storage (survives restarts, created by HF at runtime)
83
- # NOTE: /data may not exist at build time. We create it here so the chown
84
- # works, but HF may mount over it at runtime. That's fine - HF sets correct
85
- # permissions on their mount. This is belt-and-suspenders.
86
- # /tmp - needed for temporary files during cloud backup
87
- # /app - the application directory itself (for any runtime-generated files)
88
- # =============================================================================
89
- RUN mkdir -p /workspace/chroma_db /data/chroma_db /data/.cache/huggingface /data/.cache/chroma /tmp && \
90
- chown -R 1000:1000 /workspace /data /tmp /app
91
 
92
- # Expose port for Gradio (HF Spaces uses 7860)
93
  EXPOSE 7860
94
 
95
- # Set environment variables
96
- ENV PYTHONUNBUFFERED=1
97
- ENV REPO_PATH=/workspace/e-t-systems
98
-
99
- # =============================================================================
100
- # CACHE DIRECTORY CONFIGURATION
101
- # =============================================================================
102
- # CHANGELOG [2025-01-31 - Claude]
103
- # ChromaDB downloads its ONNX MiniLM-L6-V2 embedding model on first use.
104
- # By default it writes to /.cache which is owned by root.
105
- # Since we run as USER 1000, this causes:
106
- # PermissionError: [Errno 13] Permission denied: '/.cache'
107
- #
108
- # FIX: Redirect ALL cache directories to /data/.cache (persistent!)
109
- # This has a bonus effect: the embedding model download persists across
110
- # restarts too, so subsequent startups are faster (no re-download).
111
- #
112
- # If /data isn't available (persistent storage not enabled), these dirs
113
- # will be created at runtime under /tmp/.cache as a fallback.
114
- # =============================================================================
115
- ENV HF_HOME=/data/.cache/huggingface
116
- ENV TRANSFORMERS_CACHE=/data/.cache/huggingface
117
- ENV XDG_CACHE_HOME=/data/.cache
118
- ENV CHROMA_CACHE_DIR=/data/.cache/chroma
119
-
120
- # Health check
121
- HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
122
- CMD curl -f http://localhost:7860/ || exit 1
123
-
124
- # =============================================================================
125
- # SWITCH TO NON-ROOT USER
126
- # =============================================================================
127
- # CHANGELOG [2025-01-31 - Claude]
128
- # HF Spaces expect the container to run as UID 1000. Setting this explicitly
129
- # ensures consistent behavior between local testing and deployed Spaces.
130
- # Without this, the process runs as root during build but HF forces UID 1000
131
- # at runtime, causing permission mismatches on files created during build.
132
- # =============================================================================
133
  USER 1000
134
 
135
- # Run via entrypoint script (handles repo cloning at runtime)
136
- CMD ["./entrypoint.sh"]
 
1
+ # Dockerfile for Clawdbot Dev Assistant
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  FROM python:3.11-slim
3
 
4
+ # Force rebuild
5
+ ENV REBUILD_DATE=2025-01-31-v2
 
 
 
6
  WORKDIR /app
7
 
8
  # Install system dependencies
9
+ RUN apt-get update && apt-get install -y git build-essential curl && rm -rf /var/lib/apt/lists/*
 
 
 
 
10
 
11
+ # Install python requirements
12
  COPY requirements.txt .
13
+ RUN pip install --no-cache-dir -r requirements.txt
14
 
15
+ # Create workspace and storage directories
16
+ RUN mkdir -p /workspace/e-t-systems /workspace/chroma_db /data/chroma_db /tmp/.cache/huggingface /tmp/.cache/chroma
 
 
 
 
17
 
18
+ # Set environment variables for writable cache locations
19
+ ENV HF_HOME=/tmp/.cache/huggingface
20
+ ENV XDG_CACHE_HOME=/tmp/.cache
21
+ ENV CHROMA_CACHE_DIR=/tmp/.cache/chroma
22
+ ENV HOME=/tmp
23
+ ENV PYTHONUNBUFFERED=1
24
+ ENV REPO_PATH=/workspace/e-t-systems
 
 
25
 
26
+ # Copy application files
27
  COPY recursive_context.py .
28
  COPY app.py .
29
  COPY entrypoint.sh .
30
 
31
+ # Ensure permissions for the non-root Space user (UID 1000)
32
+ RUN chmod +x entrypoint.sh && \
33
+ chown -R 1000:1000 /app /workspace /tmp/.cache
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
 
35
+ # Correctly expose port
36
  EXPOSE 7860
37
 
38
+ # Switch to the Hugging Face Space user
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
  USER 1000
40
 
41
+ # Launch
42
+ CMD ["./entrypoint.sh"]