nakas commited on
Commit
3e150ad
·
verified ·
1 Parent(s): 28052e5

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +16 -5
Dockerfile CHANGED
@@ -2,27 +2,38 @@ FROM python:3.9-slim
2
 
3
  WORKDIR /app
4
 
 
 
 
5
  # Install system dependencies
6
  RUN apt-get update && apt-get install -y \
7
  build-essential \
8
  git \
9
  && rm -rf /var/lib/apt/lists/*
10
 
11
- # Copy requirements file
12
- COPY requirements.txt .
 
13
 
14
- # Install Python dependencies
 
15
  RUN pip install --no-cache-dir -r requirements.txt
16
 
17
  # Copy application files
18
  COPY app.py .
19
  COPY utils.py .
20
 
21
- # Environment variables will be set in the Hugging Face Space UI
22
- # OPENAI_API_KEY should be added as a secret
 
 
 
23
 
24
  # Expose port for the application
25
  EXPOSE 7860
26
 
 
 
 
27
  # Command to run the application
28
  CMD ["python", "app.py"]
 
2
 
3
  WORKDIR /app
4
 
5
+ # Create a non-root user
6
+ RUN useradd -m appuser
7
+
8
  # Install system dependencies
9
  RUN apt-get update && apt-get install -y \
10
  build-essential \
11
  git \
12
  && rm -rf /var/lib/apt/lists/*
13
 
14
+ # Create directories for matplotlib and set appropriate permissions
15
+ RUN mkdir -p /home/appuser/.config/matplotlib && \
16
+ chown -R appuser:appuser /home/appuser/.config
17
 
18
+ # Copy requirements first for better caching
19
+ COPY requirements.txt .
20
  RUN pip install --no-cache-dir -r requirements.txt
21
 
22
  # Copy application files
23
  COPY app.py .
24
  COPY utils.py .
25
 
26
+ # Set ownership of application files
27
+ RUN chown -R appuser:appuser /app
28
+
29
+ # Set environment variable for matplotlib
30
+ ENV MPLCONFIGDIR=/home/appuser/.config/matplotlib
31
 
32
  # Expose port for the application
33
  EXPOSE 7860
34
 
35
+ # Switch to the non-root user
36
+ USER appuser
37
+
38
  # Command to run the application
39
  CMD ["python", "app.py"]