yugbirla commited on
Commit
f4e3263
·
1 Parent(s): d4a141c

Fix Hugging Face runtime directory permissions

Browse files
Dockerfile CHANGED
@@ -1,4 +1,4 @@
1
- FROM python:3.11-slim
2
 
3
  RUN useradd -m -u 1000 user
4
 
@@ -18,18 +18,23 @@ RUN pip install --no-cache-dir -r requirements.txt
18
 
19
  COPY --chown=user . $HOME/app
20
 
 
 
 
 
21
  USER user
22
 
23
  ENV PORT=7860
 
24
  ENV LLM_PROVIDER=huggingface
25
  ENV ENABLE_LOCAL_LLM=false
26
  ENV HF_INFERENCE_MODEL=google/flan-t5-base
27
  ENV HF_TIMEOUT_SECONDS=60
28
 
29
- ENV UPLOAD_DIR=data/uploads
30
- ENV PROCESSED_DIR=data/processed
31
- ENV QDRANT_LOCAL_PATH=data/qdrant
32
- ENV EVALUATION_DIR=data/evaluation
33
 
34
  EXPOSE 7860
35
 
 
1
+ FROM python:3.11-slim
2
 
3
  RUN useradd -m -u 1000 user
4
 
 
18
 
19
  COPY --chown=user . $HOME/app
20
 
21
+ RUN mkdir -p /tmp/graphrag/uploads /tmp/graphrag/processed /tmp/graphrag/qdrant /tmp/graphrag/evaluation
22
+ RUN chown -R user:user /tmp/graphrag
23
+ RUN chown -R user:user $HOME/app
24
+
25
  USER user
26
 
27
  ENV PORT=7860
28
+
29
  ENV LLM_PROVIDER=huggingface
30
  ENV ENABLE_LOCAL_LLM=false
31
  ENV HF_INFERENCE_MODEL=google/flan-t5-base
32
  ENV HF_TIMEOUT_SECONDS=60
33
 
34
+ ENV UPLOAD_DIR=/tmp/graphrag/uploads
35
+ ENV PROCESSED_DIR=/tmp/graphrag/processed
36
+ ENV QDRANT_LOCAL_PATH=/tmp/graphrag/qdrant
37
+ ENV EVALUATION_DIR=/tmp/graphrag/evaluation
38
 
39
  EXPOSE 7860
40
 
app/core/config.py CHANGED
@@ -128,7 +128,28 @@ class Settings:
128
  ENABLE_STATIC_ASSETS: bool = get_bool_env("ENABLE_STATIC_ASSETS", True)
129
 
130
  def ensure_directories(self) -> None:
131
- self.UPLOAD_DIR.mkdir(parents=True, exist_ok=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
132
  self.PROCESSED_DIR.mkdir(parents=True, exist_ok=True)
133
  self.QDRANT_LOCAL_PATH.mkdir(parents=True, exist_ok=True)
134
  self.EVALUATION_DIR.mkdir(parents=True, exist_ok=True)
 
128
  ENABLE_STATIC_ASSETS: bool = get_bool_env("ENABLE_STATIC_ASSETS", True)
129
 
130
  def ensure_directories(self) -> None:
131
+ directories = [
132
+ self.UPLOAD_DIR,
133
+ self.PROCESSED_DIR,
134
+ self.QDRANT_LOCAL_PATH,
135
+ self.EVALUATION_DIR
136
+ ]
137
+
138
+ try:
139
+ for directory in directories:
140
+ directory.mkdir(parents=True, exist_ok=True)
141
+
142
+ except PermissionError:
143
+ fallback_base = Path("/tmp/graphrag")
144
+ fallback_dirs = [
145
+ fallback_base / "uploads",
146
+ fallback_base / "processed",
147
+ fallback_base / "qdrant",
148
+ fallback_base / "evaluation"
149
+ ]
150
+
151
+ for directory in fallback_dirs:
152
+ directory.mkdir(parents=True, exist_ok=True)
153
  self.PROCESSED_DIR.mkdir(parents=True, exist_ok=True)
154
  self.QDRANT_LOCAL_PATH.mkdir(parents=True, exist_ok=True)
155
  self.EVALUATION_DIR.mkdir(parents=True, exist_ok=True)
scripts/patch_config_permission.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from pathlib import Path
2
+ import re
3
+
4
+ path = Path("app/core/config.py")
5
+ text = path.read_text(encoding="utf-8")
6
+
7
+ pattern = r''' def ensure_directories\(self\) -> None:
8
+ (?: .+\n)+?'''
9
+
10
+ new_block = ''' def ensure_directories(self) -> None:
11
+ directories = [
12
+ self.UPLOAD_DIR,
13
+ self.PROCESSED_DIR,
14
+ self.QDRANT_LOCAL_PATH,
15
+ self.EVALUATION_DIR
16
+ ]
17
+
18
+ try:
19
+ for directory in directories:
20
+ directory.mkdir(parents=True, exist_ok=True)
21
+
22
+ except PermissionError:
23
+ fallback_base = Path("/tmp/graphrag")
24
+ fallback_dirs = [
25
+ fallback_base / "uploads",
26
+ fallback_base / "processed",
27
+ fallback_base / "qdrant",
28
+ fallback_base / "evaluation"
29
+ ]
30
+
31
+ for directory in fallback_dirs:
32
+ directory.mkdir(parents=True, exist_ok=True)
33
+ '''
34
+
35
+ match = re.search(pattern, text)
36
+
37
+ if not match:
38
+ print("Could not auto-patch ensure_directories. Please send config.py if this happens.")
39
+ else:
40
+ text = text[:match.start()] + new_block + text[match.end():]
41
+ path.write_text(text, encoding="utf-8")
42
+ print("config.py permission fallback patched successfully.")