AreejMehboob17 commited on
Commit
5c1c937
·
verified ·
1 Parent(s): 9539c99

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +71 -7
Dockerfile CHANGED
@@ -1,21 +1,85 @@
1
- FROM python:3.9-slim
2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  WORKDIR /app
4
 
 
5
  RUN apt-get update && apt-get install -y \
6
  build-essential \
7
  curl \
8
- software-properties-common \
9
  git \
10
  && rm -rf /var/lib/apt/lists/*
11
 
12
- COPY requirements.txt ./
13
- COPY src/ ./src/
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
 
15
- RUN pip3 install -r requirements.txt
 
 
 
 
 
 
 
 
 
 
 
 
16
 
 
17
  EXPOSE 8501
18
 
19
- HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
 
20
 
21
- ENTRYPOINT ["streamlit", "run", "src/streamlit_app.py", "--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
17
 
18
+ # Install basic OS packages
19
  RUN apt-get update && apt-get install -y \
20
  build-essential \
21
  curl \
 
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
+
54
+
55
+ # Switch to non-root user for package installation
56
+ USER $USER
57
+
58
+ # Install Python dependencies
59
+ RUN pip install --no-cache-dir --user -r requirements.txt
60
+
61
+ # Ensure pip user installation directory is in PATH
62
+ ENV PATH="/app/.local/bin:$PATH"
63
 
64
+ # Create a script to handle model downloads with proper error handling
65
+ RUN echo '#!/bin/bash\n\
66
+ # Clean up any existing lock files\n\
67
+ find /app/.cache/huggingface -name "*.lock" -type f -delete 2>/dev/null || true\n\
68
+ find /tmp/huggingface -name "*.lock" -type f -delete 2>/dev/null || true\n\
69
+ \n\
70
+ # Set additional permissions at runtime\n\
71
+ chmod -R 777 /app/.cache 2>/dev/null || true\n\
72
+ chmod -R 777 /tmp 2>/dev/null || true\n\
73
+ \n\
74
+ # Start the application\n\
75
+ exec streamlit run src/streamlit_app.py --server.enableXsrfProtection=false --server.port=8501 --server.address=0.0.0.0\n\
76
+ ' > /app/start.sh && chmod +x /app/start.sh
77
 
78
+ # Expose Streamlit's default port
79
  EXPOSE 8501
80
 
81
+ # Healthcheck for container status
82
+ HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health || exit 1
83
 
84
+ # Use the startup script instead of direct entrypoint
85
+ ENTRYPOINT ["/app/start.sh"]