Joash2024 commited on
Commit
55cdbde
·
1 Parent(s): 21ba4fb

Fix Docker permissions and cache directory

Browse files
Files changed (1) hide show
  1. Dockerfile +19 -16
Dockerfile CHANGED
@@ -10,33 +10,36 @@ RUN apt-get update && apt-get install -y \
10
  curl \
11
  && rm -rf /var/lib/apt/lists/*
12
 
13
- # Create necessary directories
14
- RUN mkdir -p logs src/static
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
 
16
  # Upgrade pip and install numpy first
17
  RUN pip install --upgrade pip
18
  RUN pip install --no-cache-dir "numpy<2.0.0"
19
 
20
  # Copy requirements first to leverage Docker cache
21
- COPY requirements.txt .
22
 
23
  # Install Python dependencies
24
  RUN pip install --no-cache-dir -r requirements.txt
25
 
26
  # Copy application code
27
- COPY . .
28
-
29
- # Ensure proper permissions for logs directory
30
- RUN chmod 777 logs
31
-
32
- # Set environment variables
33
- ENV PYTHONPATH=/app
34
- ENV PYTHONUNBUFFERED=1
35
- ENV PYTHONDONTWRITEBYTECODE=1
36
- ENV PORT=7860
37
-
38
- # Expose port for Hugging Face Spaces
39
- EXPOSE 7860
40
 
41
  # Run the application
42
  CMD ["python", "-m", "uvicorn", "src.api:app", "--host", "0.0.0.0", "--port", "7860"]
 
10
  curl \
11
  && rm -rf /var/lib/apt/lists/*
12
 
13
+ # Create necessary directories with proper permissions
14
+ RUN mkdir -p /app/logs /app/src/static /home/user/.cache/huggingface && \
15
+ chmod -R 777 /app/logs /home/user/.cache/huggingface
16
+
17
+ # Create non-root user
18
+ RUN useradd -m -u 1000 user && \
19
+ chown -R user:user /app /home/user/.cache
20
+
21
+ # Set environment variables
22
+ ENV PYTHONPATH=/app
23
+ ENV PYTHONUNBUFFERED=1
24
+ ENV PYTHONDONTWRITEBYTECODE=1
25
+ ENV PORT=7860
26
+ ENV TRANSFORMERS_CACHE=/home/user/.cache/huggingface
27
+
28
+ # Switch to non-root user
29
+ USER user
30
 
31
  # Upgrade pip and install numpy first
32
  RUN pip install --upgrade pip
33
  RUN pip install --no-cache-dir "numpy<2.0.0"
34
 
35
  # Copy requirements first to leverage Docker cache
36
+ COPY --chown=user:user requirements.txt .
37
 
38
  # Install Python dependencies
39
  RUN pip install --no-cache-dir -r requirements.txt
40
 
41
  # Copy application code
42
+ COPY --chown=user:user . .
 
 
 
 
 
 
 
 
 
 
 
 
43
 
44
  # Run the application
45
  CMD ["python", "-m", "uvicorn", "src.api:app", "--host", "0.0.0.0", "--port", "7860"]