Spaces:
Sleeping
Sleeping
Update Dockerfile
Browse files- Dockerfile +49 -28
Dockerfile
CHANGED
|
@@ -1,41 +1,59 @@
|
|
| 1 |
-
FROM python:3.13.5-slim
|
| 2 |
-
|
| 3 |
-
# Avoid interactive prompts during build
|
| 4 |
-
ENV DEBIAN_FRONTEND=noninteractive
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
ARG APP_HOME=/home/${APP_USER}
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
| 15 |
&& rm -rf /var/lib/apt/lists/*
|
| 16 |
|
| 17 |
-
|
| 18 |
-
RUN useradd --create-home --home-dir ${APP_HOME} --shell /usr/sbin/nologin ${APP_USER}
|
| 19 |
|
| 20 |
-
|
|
|
|
|
|
|
| 21 |
|
| 22 |
-
#
|
| 23 |
-
|
| 24 |
-
COPY src/ ./src/
|
| 25 |
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
| 29 |
HF_HOME=/app/.cache/huggingface \
|
| 30 |
-
|
| 31 |
-
|
|
|
|
| 32 |
|
| 33 |
-
#
|
| 34 |
-
RUN
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
-
# Install Python
|
| 38 |
-
RUN pip3 install --no-cache-dir -r requirements.txt
|
|
|
|
| 39 |
|
| 40 |
EXPOSE 8501
|
| 41 |
|
|
@@ -45,4 +63,7 @@ HEALTHCHECK --interval=30s --timeout=5s --start-period=5s --retries=3 \
|
|
| 45 |
# Run as non-root user
|
| 46 |
USER ${APP_USER}
|
| 47 |
|
|
|
|
|
|
|
|
|
|
| 48 |
ENTRYPOINT ["streamlit", "run", "src/streamlit_app.py", "--server.port=8501", "--server.address=0.0.0.0"]
|
|
|
|
| 1 |
+
FROM python:3.13.5-slim AS builder
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
+
ENV DEBIAN_FRONTEND=noninteractive \
|
| 4 |
+
PYTHONUNBUFFERED=1
|
|
|
|
| 5 |
|
| 6 |
+
# Install build dependencies in one RUN to keep image layers small
|
| 7 |
+
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 8 |
+
build-essential \
|
| 9 |
+
python3-dev \
|
| 10 |
+
gcc \
|
| 11 |
+
curl \
|
| 12 |
+
git \
|
| 13 |
+
ca-certificates \
|
| 14 |
&& rm -rf /var/lib/apt/lists/*
|
| 15 |
|
| 16 |
+
WORKDIR /wheels
|
|
|
|
| 17 |
|
| 18 |
+
# Copy requirements and build wheels to /wheels
|
| 19 |
+
COPY requirements.txt .
|
| 20 |
+
RUN pip3 wheel --no-cache-dir -r requirements.txt -w /wheels
|
| 21 |
|
| 22 |
+
# ---------------- final image ----------------
|
| 23 |
+
FROM python:3.13.5-slim
|
|
|
|
| 24 |
|
| 25 |
+
ENV DEBIAN_FRONTEND=noninteractive \
|
| 26 |
+
PYTHONUNBUFFERED=1 \
|
| 27 |
+
APP_USER=appuser \
|
| 28 |
+
APP_HOME=/home/appuser \
|
| 29 |
+
APP_DIR=/app \
|
| 30 |
+
# Hugging Face cache dirs inside container (avoid /root/.cache permissions issues)
|
| 31 |
HF_HOME=/app/.cache/huggingface \
|
| 32 |
+
HUGGINGFACE_HUB_CACHE=/app/.cache/huggingface/hub \
|
| 33 |
+
TRANSFORMERS_CACHE=/app/.cache/huggingface/transformers \
|
| 34 |
+
XDG_CACHE_HOME=/app/.cache
|
| 35 |
|
| 36 |
+
# Install minimal runtime deps and cleanup in one RUN
|
| 37 |
+
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 38 |
+
curl \
|
| 39 |
+
ca-certificates \
|
| 40 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 41 |
+
|
| 42 |
+
# Create non-root user and app dirs
|
| 43 |
+
RUN useradd --create-home --home-dir ${APP_HOME} --shell /usr/sbin/nologin ${APP_USER} \
|
| 44 |
+
&& mkdir -p ${APP_DIR} ${APP_HOME} /app/.cache/huggingface/transformers /app/.cache/huggingface/hub /app/src/logs \
|
| 45 |
+
&& chown -R ${APP_USER}:${APP_USER} ${APP_DIR} ${APP_HOME} /app/.cache /app/src/logs
|
| 46 |
+
|
| 47 |
+
WORKDIR ${APP_DIR}
|
| 48 |
+
|
| 49 |
+
# Copy project source and wheels from builder
|
| 50 |
+
COPY --chown=${APP_USER}:${APP_USER} src/ ./src/
|
| 51 |
+
COPY requirements.txt ./
|
| 52 |
+
COPY --from=builder /wheels /wheels
|
| 53 |
|
| 54 |
+
# Install Python dependencies from built wheels (faster, reproducible)
|
| 55 |
+
RUN pip3 install --no-cache-dir --no-index --find-links=/wheels -r requirements.txt \
|
| 56 |
+
&& rm -rf /wheels
|
| 57 |
|
| 58 |
EXPOSE 8501
|
| 59 |
|
|
|
|
| 63 |
# Run as non-root user
|
| 64 |
USER ${APP_USER}
|
| 65 |
|
| 66 |
+
# NOTE:
|
| 67 |
+
# - The entrypoint expects your Streamlit app at src/streamlit_app.py.
|
| 68 |
+
# - If your file is named src/streamlitapp.py (no underscore), update the ENTRYPOINT accordingly.
|
| 69 |
ENTRYPOINT ["streamlit", "run", "src/streamlit_app.py", "--server.port=8501", "--server.address=0.0.0.0"]
|