mazen2100 commited on
Commit
10be552
·
verified ·
1 Parent(s): 37fdb37

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +22 -17
Dockerfile CHANGED
@@ -3,52 +3,57 @@
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"]
 
3
  # 1. Base image
4
  FROM python:3.9-slim
5
 
6
+ # 2. Install curl for HEALTHCHECK
7
+ RUN apt-get update && apt-get install -y curl && rm -rf /var/lib/apt/lists/*
8
+
9
+ # 3. Create non-root user for security
10
  RUN useradd -m -u 1000 appuser
11
 
12
+ # 4. Set working directory
13
  WORKDIR /app
14
 
15
+ # 5. Set HOME to /app to avoid writing to root
16
  ENV HOME=/app
17
 
18
+ # 6. Environment variables for writable cache/config dirs and PATH
19
  ENV STREAMLIT_CONFIG_DIR=/app/.streamlit \
20
  TRANSFORMERS_CACHE=/app/.cache/huggingface/hub \
21
  HF_HOME=/app/.cache/huggingface \
22
  XDG_CACHE_HOME=/app/.cache \
23
+ STREAMLIT_HOME=/app/.cache/streamlit \
24
+ PATH=/app/.local/bin:$PATH
25
 
26
+ # 7. Create cache directories with correct permissions
27
  RUN mkdir -p /app/.streamlit \
28
  && mkdir -p /app/.cache/huggingface/hub \
29
  && mkdir -p /app/.cache/streamlit \
30
  && chmod -R 755 /app/.cache /app/.streamlit \
31
  && chown -R appuser:appuser /app
32
 
33
+ # 8. Copy requirements as root to ensure permissions
 
 
 
34
  COPY requirements.txt .
35
+
36
+ # 9. Install dependencies as appuser
37
+ USER appuser
38
  RUN pip install --no-cache-dir -r requirements.txt
39
 
40
+ # 10. Copy source code as appuser
41
+ COPY --chown=appuser:appuser src/ ./src
42
 
43
+ # 11. Move .streamlit/config.toml to the correct location with proper permissions
44
  RUN if [ -f /app/src/.streamlit/config.toml ]; then \
45
+ mv /app/src/.streamlit/config.toml /app/.streamlit/config.toml && \
46
+ chmod 644 /app/.streamlit/config.toml; \
47
  fi
48
 
49
+ # 12. Expose Streamlit default port
50
  EXPOSE 8501
51
 
52
+ # 13. Healthcheck to verify app is running
53
  HEALTHCHECK --interval=30s --timeout=3s \
54
  CMD curl -f http://localhost:8501/healthz || exit 1
55
 
56
+ # 14. Launch Streamlit pointing to src/app.py
57
  CMD ["streamlit", "run", "src/app.py", \
58
  "--server.port=8501", \
59
  "--server.address=0.0.0.0"]