SuhasGholkar commited on
Commit
191d429
·
verified ·
1 Parent(s): 2622f62

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +46 -13
Dockerfile CHANGED
@@ -1,21 +1,54 @@
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
+ # ---- Base image ----
2
+ FROM python:3.10-slim
3
 
4
+ # ---- Workdir ----
5
  WORKDIR /app
6
 
7
+ # ---- Env ----
8
+ ENV PYTHONDONTWRITEBYTECODE=1 \
9
+ PYTHONUNBUFFERED=1 \
10
+ PIP_NO_CACHE_DIR=1 \
11
+ STREAMLIT_SERVER_HEADLESS=true \
12
+ HF_HUB_DISABLE_SYMLINKS_WARNING=1 \
13
+ XDG_CACHE_HOME=/app/.cache
14
 
15
+ # ---- Python deps ----
16
+ COPY requirements.txt /app/requirements.txt
17
+ RUN python -m pip install --no-cache-dir --upgrade pip \
18
+ && python -m pip install --no-cache-dir -r /app/requirements.txt
19
 
20
+ # System deps for video/text rendering
21
+ RUN apt-get update && apt-get install -y --no-install-recommends \
22
+ ffmpeg \
23
+ fonts-dejavu-core \
24
+ && rm -rf /var/lib/apt/lists/*
25
 
 
26
 
27
+ # ---- App code ----
28
+ COPY . /app
29
 
30
+ # ---- Create non-root user and fix permissions ----
31
+ # uid 1000 is conventional; adjust if you need
32
+ RUN useradd -m -u 1000 -s /bin/sh app \
33
+ && mkdir -p /app/.streamlit /app/.cache \
34
+ && chown -R app:app /app
35
+
36
+ # Drop privileges for runtime
37
+ USER app
38
+
39
+ # ---- Streamlit config ----
40
+ RUN printf "[server]\nheadless = true\nport = 7860\naddress = \"0.0.0.0\"\nenableCORS = false\nenableXsrfProtection = false\n" \
41
+ > /app/.streamlit/config.toml
42
+
43
+ # ---- Port & health ----
44
+ EXPOSE 7860
45
+ ENV PORT=7860
46
+
47
+ # Healthcheck hits Streamlit's built-in health endpoint
48
+ COPY --chown=app:app healthcheck.py /app/healthcheck.py
49
+ HEALTHCHECK --interval=30s --timeout=5s --start-period=15s --retries=5 \
50
+ CMD python /app/healthcheck.py || exit 1
51
+
52
+ # ---- Start the app ----
53
+ # Use sh -c so ${PORT} expands at runtime on Spaces
54
+ CMD ["sh","-c","python -m streamlit run app.py --server.port=${PORT:-7860} --server.address=0.0.0.0 --server.enableCORS=false --server.enableXsrfProtection=false"]