yadavkapil23 commited on
Commit
a507b1e
·
1 Parent(s): b63ad23
Files changed (2) hide show
  1. Dockerfile +17 -0
  2. vector_rag.py +5 -0
Dockerfile CHANGED
@@ -4,6 +4,17 @@ FROM python:3.10-slim
4
  # Set the working directory in the container
5
  WORKDIR /app
6
 
 
 
 
 
 
 
 
 
 
 
 
7
  # Copy the requirements file into the container
8
  COPY requirements.txt .
9
 
@@ -13,6 +24,12 @@ RUN pip install --no-cache-dir -r requirements.txt
13
  # Copy the rest of the application code into the container
14
  COPY . .
15
 
 
 
 
 
 
 
16
  # Expose the port your app runs on
17
  EXPOSE 8000
18
 
 
4
  # Set the working directory in the container
5
  WORKDIR /app
6
 
7
+ # Create a non-root user and set cache directory permissions
8
+ RUN useradd --create-home --shell /bin/bash app && \
9
+ mkdir -p /home/app/.cache && \
10
+ chown -R app:app /home/app/.cache && \
11
+ chown -R app:app /app
12
+
13
+ # Set environment variables for Hugging Face cache
14
+ ENV HF_HOME=/home/app/.cache/huggingface
15
+ ENV TRANSFORMERS_CACHE=/home/app/.cache/huggingface/transformers
16
+ ENV HF_DATASETS_CACHE=/home/app/.cache/huggingface/datasets
17
+
18
  # Copy the requirements file into the container
19
  COPY requirements.txt .
20
 
 
24
  # Copy the rest of the application code into the container
25
  COPY . .
26
 
27
+ # Change ownership of all files to app user
28
+ RUN chown -R app:app /app
29
+
30
+ # Switch to non-root user
31
+ USER app
32
+
33
  # Expose the port your app runs on
34
  EXPOSE 8000
35
 
vector_rag.py CHANGED
@@ -11,6 +11,11 @@ from dotenv import load_dotenv
11
 
12
  load_dotenv()
13
 
 
 
 
 
 
14
  # --- MODEL INITIALIZATION (Minimal Footprint) ---
15
  print("Loading Qwen2-0.5B-Instruct...")
16
  model_name = "Qwen/Qwen2-0.5B-Instruct"
 
11
 
12
  load_dotenv()
13
 
14
+ # Set cache directories with fallback for permission issues
15
+ os.environ.setdefault('HF_HOME', '/tmp/huggingface_cache')
16
+ os.environ.setdefault('TRANSFORMERS_CACHE', '/tmp/huggingface_cache/transformers')
17
+ os.environ.setdefault('HF_DATASETS_CACHE', '/tmp/huggingface_cache/datasets')
18
+
19
  # --- MODEL INITIALIZATION (Minimal Footprint) ---
20
  print("Loading Qwen2-0.5B-Instruct...")
21
  model_name = "Qwen/Qwen2-0.5B-Instruct"