mazen2100 commited on
Commit
37fdb37
·
verified ·
1 Parent(s): 75ebc48

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +27 -12
Dockerfile CHANGED
@@ -1,39 +1,54 @@
1
- # Dockerfile for Streamlit app in `src/` folder with Transformers cache fix
2
 
3
  # 1. Base image
4
  FROM python:3.9-slim
5
 
6
- # 2. Set working directory
 
 
 
7
  WORKDIR /app
8
 
9
- # 3. Set HOME to /app to avoid writing to root
10
  ENV HOME=/app
11
 
12
- # 4. Environment variables for writable cache/config dirs
13
  ENV STREAMLIT_CONFIG_DIR=/app/.streamlit \
14
  TRANSFORMERS_CACHE=/app/.cache/huggingface/hub \
15
  HF_HOME=/app/.cache/huggingface \
16
  XDG_CACHE_HOME=/app/.cache \
17
  STREAMLIT_HOME=/app/.cache/streamlit
18
 
19
- # 5. Create directories with correct permissions and inject Streamlit config
20
  RUN mkdir -p /app/.streamlit \
21
  && mkdir -p /app/.cache/huggingface/hub \
22
  && mkdir -p /app/.cache/streamlit \
23
- && chmod -R 777 /app/.cache /app/.streamlit \
24
- && printf '[browser]\ngatherUsageStats = false\n\n[server]\nheadless = true\nenableCORS = false\nport = 8501\n' > /app/.streamlit/config.toml
 
 
 
25
 
26
- # 6. Copy in dependency file and install
27
  COPY requirements.txt .
28
  RUN pip install --no-cache-dir -r requirements.txt
29
 
30
- # 7. Copy your source app code
31
  COPY src/ ./src
32
 
33
- # 8. Expose Streamlit default port
 
 
 
 
 
34
  EXPOSE 8501
35
 
36
- # 9. Launch Streamlit pointing to src/app.py
 
 
 
 
37
  CMD ["streamlit", "run", "src/app.py", \
38
  "--server.port=8501", \
39
- "--server.address=0.0.0.0"]
 
1
+ # Dockerfile for Streamlit app in src/ folder with Transformers cache fix
2
 
3
  # 1. Base image
4
  FROM python:3.9-slim
5
 
6
+ # 2. Create non-root user for security
7
+ RUN useradd -m -u 1000 appuser
8
+
9
+ # 3. Set working directory
10
  WORKDIR /app
11
 
12
+ # 4. Set HOME to /app to avoid writing to root
13
  ENV HOME=/app
14
 
15
+ # 5. Environment variables for writable cache/config dirs
16
  ENV STREAMLIT_CONFIG_DIR=/app/.streamlit \
17
  TRANSFORMERS_CACHE=/app/.cache/huggingface/hub \
18
  HF_HOME=/app/.cache/huggingface \
19
  XDG_CACHE_HOME=/app/.cache \
20
  STREAMLIT_HOME=/app/.cache/streamlit
21
 
22
+ # 6. Create cache directories with correct permissions
23
  RUN mkdir -p /app/.streamlit \
24
  && mkdir -p /app/.cache/huggingface/hub \
25
  && mkdir -p /app/.cache/streamlit \
26
+ && chmod -R 755 /app/.cache /app/.streamlit \
27
+ && chown -R appuser:appuser /app
28
+
29
+ # 7. Switch to non-root user
30
+ USER appuser
31
 
32
+ # 8. Copy in dependency file and install
33
  COPY requirements.txt .
34
  RUN pip install --no-cache-dir -r requirements.txt
35
 
36
+ # 9. Copy your source app code and Streamlit config
37
  COPY src/ ./src
38
 
39
+ # 10. Move .streamlit/config.toml to the correct location
40
+ RUN if [ -f /app/src/.streamlit/config.toml ]; then \
41
+ mv /app/src/.streamlit/config.toml /app/.streamlit/config.toml; \
42
+ fi
43
+
44
+ # 11. Expose Streamlit default port
45
  EXPOSE 8501
46
 
47
+ # 12. Healthcheck to verify app is running
48
+ HEALTHCHECK --interval=30s --timeout=3s \
49
+ CMD curl -f http://localhost:8501/healthz || exit 1
50
+
51
+ # 13. Launch Streamlit pointing to src/app.py
52
  CMD ["streamlit", "run", "src/app.py", \
53
  "--server.port=8501", \
54
+ "--server.address=0.0.0.0"]