albertchristopher commited on
Commit
d51faa2
·
verified ·
1 Parent(s): 9242aa4

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +58 -8
Dockerfile CHANGED
@@ -1,34 +1,84 @@
1
  FROM python:3.11-slim
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
  ENV PYTHONDONTWRITEBYTECODE=1
4
  ENV PYTHONUNBUFFERED=1
5
  ENV HOME=/home/user
6
 
7
- # Add git so pip can install from GitHub
 
8
  RUN apt-get update \
9
- && apt-get install -y --no-install-recommends git \
10
- && rm -rf /var/lib/apt/lists/*
 
11
 
12
- # Create non-root user and writable dirs
13
  RUN useradd -m -u 1000 user \
14
- && mkdir -p /data ${HOME}/.streamlit \
15
- && chown -R user:user /data ${HOME}
 
16
 
17
  WORKDIR /app
18
 
19
- # Caches go to /data (writable & persistent on Spaces)
 
20
  ENV XDG_CACHE_HOME=/data/.cache
21
  ENV HF_HOME=/data/.cache/huggingface
22
  ENV HUGGINGFACE_HUB_CACHE=/data/.cache/huggingface
23
  ENV TRANSFORMERS_CACHE=/data/.cache/huggingface/transformers
24
  ENV STREAMLIT_BROWSER_GATHERUSAGESTATS=false
25
 
 
26
  COPY requirements.txt .
27
  RUN pip install --no-cache-dir -r requirements.txt
28
 
 
29
  COPY src/ ./src/
30
 
 
 
31
  USER user
 
 
 
32
  EXPOSE 8501
33
  HEALTHCHECK CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8501/_stcore/health')" || exit 1
34
- CMD ["streamlit", "run", "src/streamlit_app.py", "--server.port=8501", "--server.address=0.0.0.0"]
 
 
 
 
1
  FROM python:3.11-slim
2
+ WORKDIR /app
3
+
4
+
5
+ # Send caches to /data (persistent & writable on Spaces)
6
+ ENV XDG_CACHE_HOME=/data/.cache
7
+ ENV HF_HOME=/data/.cache/huggingface
8
+ ENV HUGGINGFACE_HUB_CACHE=/data/.cache/huggingface
9
+ ENV TRANSFORMERS_CACHE=/data/.cache/huggingface/transformers
10
+ ENV STREAMLIT_BROWSER_GATHERUSAGESTATS=false
11
+
12
+
13
+ # Optional: if you want to *disable* Torch Inductor JIT (no C++ compile at runtime)
14
+ # ENV TORCHINDUCTOR_DISABLE=1
15
+
16
+
17
+ COPY requirements.txt .
18
+ RUN pip install --no-cache-dir -r requirements.txt
19
+
20
+
21
+ COPY src/ ./src/
22
+
23
+
24
+ # Run as non-root
25
+ USER user
26
+
27
+
28
+ # Port & healthcheck expected by the Space
29
+ EXPOSE 8501
30
+ HEALTHCHECK CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8501/_stcore/health')" || exit 1
31
+
32
+
33
+ # Launch Streamlit
34
+ CMD ["streamlit", "run", "src/streamlit_app.py", "--server.port=8501", "--server.address=0.0.0.0"]
35
+ ```dockerfile
36
+ FROM python:3.11-slim
37
+
38
 
39
  ENV PYTHONDONTWRITEBYTECODE=1
40
  ENV PYTHONUNBUFFERED=1
41
  ENV HOME=/home/user
42
 
43
+
44
+ # Install git so pip can install from GitHub (transformers fork)
45
  RUN apt-get update \
46
+ && apt-get install -y --no-install-recommends git \
47
+ && rm -rf /var/lib/apt/lists/*
48
+
49
 
50
+ # Create non-root user and writable dirs (avoid /.streamlit, /.cache perms)
51
  RUN useradd -m -u 1000 user \
52
+ && mkdir -p /data ${HOME}/.streamlit \
53
+ && chown -R user:user /data ${HOME}
54
+
55
 
56
  WORKDIR /app
57
 
58
+
59
+ # Send caches to /data (persistent & writable on Spaces)
60
  ENV XDG_CACHE_HOME=/data/.cache
61
  ENV HF_HOME=/data/.cache/huggingface
62
  ENV HUGGINGFACE_HUB_CACHE=/data/.cache/huggingface
63
  ENV TRANSFORMERS_CACHE=/data/.cache/huggingface/transformers
64
  ENV STREAMLIT_BROWSER_GATHERUSAGESTATS=false
65
 
66
+
67
  COPY requirements.txt .
68
  RUN pip install --no-cache-dir -r requirements.txt
69
 
70
+
71
  COPY src/ ./src/
72
 
73
+
74
+ # Run as non-root
75
  USER user
76
+
77
+
78
+ # Port & healthcheck expected by the Space
79
  EXPOSE 8501
80
  HEALTHCHECK CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8501/_stcore/health')" || exit 1
81
+
82
+
83
+ # Launch Streamlit
84
+ CMD ["streamlit", "run", "src/streamlit_app.py", "--server.port=8501", "--server.address=0.0.0.0"]