AreejMehboob commited on
Commit
0e36f33
·
verified ·
1 Parent(s): 142becd

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +58 -12
Dockerfile CHANGED
@@ -1,10 +1,16 @@
1
  FROM python:3.13.4-slim
2
 
3
- # Set environment variables
4
  ENV HF_HOME=/app/.cache/huggingface \
 
 
 
5
  PYTHONUNBUFFERED=1 \
6
  HOME=/app \
7
- TMPDIR=/tmp
 
 
 
8
 
9
  # Set working directory
10
  WORKDIR /app
@@ -16,22 +22,62 @@ RUN apt-get update && apt-get install -y \
16
  git \
17
  && rm -rf /var/lib/apt/lists/*
18
 
19
- # Create necessary directories
20
- RUN mkdir -p /app/.cache/huggingface/transformers \
 
 
 
 
 
 
 
21
  && mkdir -p /app/.streamlit \
22
- && chmod -R 755 /app
 
 
 
 
 
 
 
 
 
 
 
 
23
 
24
- # Copy files
25
- COPY requirements.txt ./
26
- COPY src/ ./src/
27
 
28
  # Fix permissions for the qdrant database folder
29
  RUN if [ -d "/app/src/qdrant_data_tesla" ]; then \
30
- chmod -R 777 /app/src/qdrant_data_tesla; \
 
31
  fi
32
 
 
 
 
33
  # Install Python dependencies
34
- RUN pip install --no-cache-dir -r requirements.txt
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
 
36
  # Expose Streamlit's default port
37
  EXPOSE 8501
@@ -39,5 +85,5 @@ EXPOSE 8501
39
  # Healthcheck for container status
40
  HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health || exit 1
41
 
42
- # Start the Streamlit app
43
- ENTRYPOINT ["streamlit", "run", "src/streamlit_app.py","--server.enableXsrfProtection=false","--server.port=8501", "--server.address=0.0.0.0"]
 
1
  FROM python:3.13.4-slim
2
 
3
+ # Set environment variables for Hugging Face and app
4
  ENV HF_HOME=/app/.cache/huggingface \
5
+ TRANSFORMERS_CACHE=/app/.cache/transformers \
6
+ HF_DATASETS_CACHE=/app/.cache/datasets \
7
+ HUGGINGFACE_HUB_CACHE=/app/.cache/huggingface \
8
  PYTHONUNBUFFERED=1 \
9
  HOME=/app \
10
+ TMPDIR=/tmp \
11
+ USER=appuser \
12
+ UID=1000 \
13
+ GID=1000
14
 
15
  # Set working directory
16
  WORKDIR /app
 
22
  git \
23
  && rm -rf /var/lib/apt/lists/*
24
 
25
+ # Create a non-root user with proper permissions
26
+ RUN groupadd -g $GID $USER && \
27
+ useradd -u $UID -g $GID -d /app -s /bin/bash $USER
28
+
29
+ # Create all necessary directories with proper permissions
30
+ RUN mkdir -p /app/.cache/huggingface/hub \
31
+ && mkdir -p /app/.cache/huggingface/transformers \
32
+ && mkdir -p /app/.cache/transformers \
33
+ && mkdir -p /app/.cache/datasets \
34
  && mkdir -p /app/.streamlit \
35
+ && mkdir -p /tmp/huggingface \
36
+ && mkdir -p /tmp/transformers \
37
+ && mkdir -p /tmp/datasets \
38
+ && mkdir -p /app/models
39
+
40
+ # Set comprehensive permissions
41
+ RUN chmod -R 777 /app/.cache \
42
+ && chmod -R 777 /tmp \
43
+ && chmod -R 755 /app \
44
+ && chown -R $USER:$USER /app \
45
+ && chown -R $USER:$USER /tmp/huggingface \
46
+ && chown -R $USER:$USER /tmp/transformers \
47
+ && chown -R $USER:$USER /tmp/datasets
48
 
49
+ # Copy files and set ownership
50
+ COPY --chown=$USER:$USER requirements.txt ./
51
+ COPY --chown=$USER:$USER src/ ./src/
52
 
53
  # Fix permissions for the qdrant database folder
54
  RUN if [ -d "/app/src/qdrant_data_tesla" ]; then \
55
+ chmod -R 777 /app/src/qdrant_data_tesla && \
56
+ chown -R $USER:$USER /app/src/qdrant_data_tesla; \
57
  fi
58
 
59
+ # Switch to non-root user for package installation
60
+ USER $USER
61
+
62
  # Install Python dependencies
63
+ RUN pip install --no-cache-dir --user -r requirements.txt
64
+
65
+ # Ensure pip user installation directory is in PATH
66
+ ENV PATH="/app/.local/bin:$PATH"
67
+
68
+ # Create a script to handle model downloads with proper error handling
69
+ RUN echo '#!/bin/bash\n\
70
+ # Clean up any existing lock files\n\
71
+ find /app/.cache/huggingface -name "*.lock" -type f -delete 2>/dev/null || true\n\
72
+ find /tmp/huggingface -name "*.lock" -type f -delete 2>/dev/null || true\n\
73
+ \n\
74
+ # Set additional permissions at runtime\n\
75
+ chmod -R 777 /app/.cache 2>/dev/null || true\n\
76
+ chmod -R 777 /tmp 2>/dev/null || true\n\
77
+ \n\
78
+ # Start the application\n\
79
+ exec streamlit run src/streamlit_app.py --server.enableXsrfProtection=false --server.port=8501 --server.address=0.0.0.0\n\
80
+ ' > /app/start.sh && chmod +x /app/start.sh
81
 
82
  # Expose Streamlit's default port
83
  EXPOSE 8501
 
85
  # Healthcheck for container status
86
  HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health || exit 1
87
 
88
+ # Use the startup script instead of direct entrypoint
89
+ ENTRYPOINT ["/app/start.sh"]