JumaRubea commited on
Commit
ecdbe25
·
verified ·
1 Parent(s): 37eee57

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +29 -17
Dockerfile CHANGED
@@ -1,35 +1,47 @@
1
- FROM python:3.13.5-slim
 
2
 
 
3
  WORKDIR /app
4
 
5
- RUN apt-get update && apt-get install -y \
 
6
  build-essential \
7
  curl \
8
  git \
 
9
  && rm -rf /var/lib/apt/lists/*
10
 
11
- # Create a non-root user
12
- RUN useradd -ms /bin/bash appuser
13
- USER appuser
 
14
 
15
- # Set Hugging Face & Streamlit cache dirs to user-writable locations
16
- ENV TRANSFORMERS_CACHE=/app/.cache/huggingface/transformers
17
- ENV HF_HOME=/app/.cache/huggingface
18
- ENV XDG_CACHE_HOME=/app/.cache
19
- ENV STREAMLIT_HOME=/app/.streamlit
20
 
21
- # Make directories
22
- RUN mkdir -p $TRANSFORMERS_CACHE $HF_HOME $XDG_CACHE_HOME $STREAMLIT_HOME
23
 
24
- # Copy code
25
- COPY --chown=appuser:appuser requirements.txt ./
26
- COPY --chown=appuser:appuser src/ ./src/
27
-
28
- # Install dependencies
29
  RUN pip install --no-cache-dir -r requirements.txt
30
 
 
 
 
 
 
 
 
 
 
 
31
  EXPOSE 8501
32
 
 
33
  HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health || exit 1
34
 
 
35
  ENTRYPOINT ["streamlit", "run", "src/app.py", "--server.port=8501", "--server.address=0.0.0.0"]
 
1
+ # Use official Python slim image
2
+ FROM python:3.10-slim
3
 
4
+ # Set working directory
5
  WORKDIR /app
6
 
7
+ # Install system dependencies
8
+ RUN apt update && apt install -y \
9
  build-essential \
10
  curl \
11
  git \
12
+ sqlite3 \
13
  && rm -rf /var/lib/apt/lists/*
14
 
15
+ # Create /data directory (for database, logs) and set permissions
16
+ RUN mkdir -p /data && \
17
+ chown -R 1000:1000 /data && \
18
+ chmod -R 755 /data
19
 
20
+ # Copy requirements and source code
21
+ COPY requirements.txt ./
22
+ COPY src/ ./src/
 
 
23
 
24
+ # Optional: pre-copy chats.db
25
+ RUN [ -f src/chats.db ] && cp src/chats.db /data/chats.db || true
26
 
27
+ # Upgrade pip and install dependencies
28
+ RUN pip install --upgrade pip
 
 
 
29
  RUN pip install --no-cache-dir -r requirements.txt
30
 
31
+ # Set Hugging Face and Streamlit cache dirs to /tmp (writable in Spaces)
32
+ ENV HF_HOME=/tmp/hf_home
33
+ ENV TRANSFORMERS_CACHE=/tmp/transformers_cache
34
+ ENV XDG_CACHE_HOME=/tmp/xdg_cache
35
+ ENV STREAMLIT_HOME=/tmp/streamlit
36
+
37
+ # Make sure cache directories exist
38
+ RUN mkdir -p /tmp/hf_home /tmp/transformers_cache /tmp/xdg_cache /tmp/streamlit
39
+
40
+ # Expose Streamlit port
41
  EXPOSE 8501
42
 
43
+ # Healthcheck for Streamlit
44
  HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health || exit 1
45
 
46
+ # Run the Streamlit app
47
  ENTRYPOINT ["streamlit", "run", "src/app.py", "--server.port=8501", "--server.address=0.0.0.0"]