JumaRubea commited on
Commit
37d2f2c
·
verified ·
1 Parent(s): c41b9fd

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +27 -36
Dockerfile CHANGED
@@ -1,45 +1,36 @@
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 /temp && \
17
- chown -R 1000:1000 /temp && \
18
- chmod -R 755 /temp
19
 
20
- # Copy requirements and source code
21
- COPY requirements.txt ./
22
- COPY src/ ./src/
23
 
 
 
 
24
 
25
- # Upgrade pip and install dependencies
26
- RUN pip install --upgrade pip
27
  RUN pip install --no-cache-dir -r requirements.txt
28
 
29
- # Set Hugging Face and Streamlit cache dirs to /tmp (writable in Spaces)
30
- ENV HF_HOME=/tmp/hf_home
31
- ENV TRANSFORMERS_CACHE=/tmp/transformers_cache
32
- ENV XDG_CACHE_HOME=/tmp/xdg_cache
33
- ENV STREAMLIT_HOME=/tmp/streamlit
34
-
35
- # Make sure cache directories exist
36
- RUN mkdir -p /tmp/hf_home /tmp/transformers_cache /tmp/xdg_cache /tmp/streamlit
37
 
38
- # Expose Streamlit port
39
- EXPOSE 8501
 
 
40
 
41
- # Healthcheck for Streamlit
42
- HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health || exit 1
43
 
44
- # Run the Streamlit app
45
- ENTRYPOINT ["streamlit", "run", "src/app.py", "--server.port=8501", "--server.address=0.0.0.0"]
 
1
+ # Use a lightweight Python image
2
+ FROM python:3.9-slim
3
 
4
+ # Set environment variables for cache directories
5
+ ENV HF_HOME=/tmp/huggingface_cache
6
+ ENV TRANSFORMERS_CACHE=/tmp/transformers_cache
7
+ ENV HF_HUB_CACHE=/tmp/hf_hub_cache
8
+ ENV SENTENCE_TRANSFORMERS_HOME=/tmp/sentence_transformers_cache
9
+ ENV STREAMLIT_CONFIG_DIR=/tmp/.streamlit
 
 
 
 
 
 
 
 
 
10
 
11
+ # Set the working directory in the container
12
+ WORKDIR /app
 
13
 
14
+ # Create cache directories and set permissions
15
+ RUN mkdir -p /tmp/huggingface_cache /tmp/transformers_cache /tmp/hf_hub_cache /tmp/sentence_transformers_cache /tmp/.streamlit && \
16
+ chmod -R 777 /tmp
17
 
18
+ # Copy the requirements file and install dependencies
19
+ COPY requirements.txt .
20
  RUN pip install --no-cache-dir -r requirements.txt
21
 
22
+ # Copy the application files and the document
23
+ COPY rag_components.py .
24
+ COPY app.py .
25
+ COPY me.txt .
 
 
 
 
26
 
27
+ # Create a non-root user for better security in HF Spaces
28
+ RUN useradd -m -u 1000 user
29
+ RUN chown -R user:user /app /tmp
30
+ USER user
31
 
32
+ # Expose the port Streamlit runs on
33
+ EXPOSE 7860
34
 
35
+ # Command to run the Streamlit application
36
+ CMD ["streamlit", "run", "app.py", "--server.port=7860", "--server.address=0.0.0.0"]