Spaces:
Runtime error
Runtime error
Update
Browse files- Dockerfile +45 -54
Dockerfile
CHANGED
|
@@ -1,80 +1,71 @@
|
|
| 1 |
-
#
|
| 2 |
FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim
|
| 3 |
|
| 4 |
-
#
|
| 5 |
ARG PORT=8001
|
| 6 |
ARG TRANSPORT_SERVER_URL=https://blanchon-robothub-transportserver.hf.space/api
|
| 7 |
|
| 8 |
-
#
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
PORT=${PORT} \
|
| 15 |
-
TRANSPORT_SERVER_URL=${TRANSPORT_SERVER_URL} \
|
| 16 |
-
HF_HOME=/home/appuser/.cache \
|
| 17 |
-
HF_HUB_CACHE=/home/appuser/.cache/hub
|
| 18 |
|
| 19 |
-
#
|
| 20 |
-
RUN
|
| 21 |
-
# Build tools for compiling Python packages
|
| 22 |
-
build-essential \
|
| 23 |
-
gcc \
|
| 24 |
-
g++ \
|
| 25 |
-
# Essential system libraries
|
| 26 |
-
libgl1-mesa-glx \
|
| 27 |
-
libglib2.0-0 \
|
| 28 |
-
libsm6 \
|
| 29 |
-
libxext6 \
|
| 30 |
-
libxrender-dev \
|
| 31 |
-
libgomp1 \
|
| 32 |
-
# FFmpeg for video processing
|
| 33 |
-
ffmpeg \
|
| 34 |
-
# Git for potential model downloads
|
| 35 |
-
git \
|
| 36 |
-
# Clean up
|
| 37 |
-
&& apt-get clean \
|
| 38 |
-
&& rm -rf /var/lib/apt/lists/*
|
| 39 |
|
| 40 |
-
#
|
| 41 |
-
RUN groupadd -r appuser && useradd -r -g appuser -m -s /bin/bash appuser
|
| 42 |
-
|
| 43 |
-
# Set working directory
|
| 44 |
WORKDIR /app
|
| 45 |
|
| 46 |
-
#
|
| 47 |
COPY --chown=appuser:appuser pyproject.toml uv.lock* ./
|
| 48 |
-
|
| 49 |
-
# Copy external dependencies (submodules) needed for dependency resolution
|
| 50 |
COPY --chown=appuser:appuser external/ ./external/
|
| 51 |
|
| 52 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
RUN --mount=type=cache,target=/tmp/uv-cache \
|
| 54 |
uv sync --locked --no-install-project --no-dev
|
| 55 |
|
| 56 |
-
#
|
| 57 |
COPY --chown=appuser:appuser . .
|
| 58 |
|
| 59 |
-
#
|
| 60 |
RUN --mount=type=cache,target=/tmp/uv-cache \
|
| 61 |
uv sync --locked --no-editable --no-dev
|
| 62 |
|
| 63 |
-
#
|
| 64 |
-
USER appuser
|
| 65 |
-
|
| 66 |
-
# Create cache directories for Hugging Face in user home directory
|
| 67 |
-
RUN mkdir -p /home/appuser/.cache/hub /home/appuser/.cache/transformers /home/appuser/.cache/datasets
|
| 68 |
-
|
| 69 |
-
# Add virtual environment to PATH
|
| 70 |
ENV PATH="/app/.venv/bin:$PATH"
|
| 71 |
|
| 72 |
-
#
|
| 73 |
EXPOSE ${PORT}
|
| 74 |
|
| 75 |
-
# Health check
|
| 76 |
HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \
|
| 77 |
-
CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost
|
| 78 |
|
| 79 |
-
#
|
| 80 |
-
CMD ["sh", "-c", "python launch_simple.py --host 0.0.0.0 --port ${PORT} --transport-server-url ${TRANSPORT_SERVER_URL}"]
|
|
|
|
| 1 |
+
# Base image with uv + Python 3.12
|
| 2 |
FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim
|
| 3 |
|
| 4 |
+
# ---------- build-time args ----------
|
| 5 |
ARG PORT=8001
|
| 6 |
ARG TRANSPORT_SERVER_URL=https://blanchon-robothub-transportserver.hf.space/api
|
| 7 |
|
| 8 |
+
# ---------- system packages ----------
|
| 9 |
+
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 10 |
+
build-essential gcc g++ \
|
| 11 |
+
libgl1-mesa-glx libglib2.0-0 libsm6 libxext6 libxrender-dev libgomp1 \
|
| 12 |
+
ffmpeg git \
|
| 13 |
+
&& apt-get clean && rm -rf /var/lib/apt/lists/*
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
+
# ---------- non-root user ----------
|
| 16 |
+
RUN groupadd -r appuser && useradd -m -r -g appuser -s /bin/bash appuser
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
+
# ---------- working dir ----------
|
|
|
|
|
|
|
|
|
|
| 19 |
WORKDIR /app
|
| 20 |
|
| 21 |
+
# ---------- copy manifests (as root, but owned by appuser) ----------
|
| 22 |
COPY --chown=appuser:appuser pyproject.toml uv.lock* ./
|
|
|
|
|
|
|
| 23 |
COPY --chown=appuser:appuser external/ ./external/
|
| 24 |
|
| 25 |
+
# ---------- switch to non-root BEFORE anything that downloads ----------
|
| 26 |
+
USER appuser
|
| 27 |
+
|
| 28 |
+
# ---------- cache locations (all writable) ----------
|
| 29 |
+
ENV \
|
| 30 |
+
# generic caches
|
| 31 |
+
XDG_CACHE_HOME=/home/appuser/.cache \
|
| 32 |
+
# huggingface-hub + datasets
|
| 33 |
+
HF_HOME=/home/appuser/.cache \
|
| 34 |
+
HF_HUB_CACHE=/home/appuser/.cache/hub \
|
| 35 |
+
HUGGINGFACE_HUB_CACHE=/home/appuser/.cache/hub \
|
| 36 |
+
# transformers
|
| 37 |
+
TRANSFORMERS_CACHE=/home/appuser/.cache/huggingface/hub \
|
| 38 |
+
# uv & app settings
|
| 39 |
+
PYTHONUNBUFFERED=1 \
|
| 40 |
+
PYTHONDONTWRITEBYTECODE=1 \
|
| 41 |
+
UV_SYSTEM_PYTHON=1 \
|
| 42 |
+
UV_COMPILE_BYTECODE=1 \
|
| 43 |
+
UV_CACHE_DIR=/tmp/uv-cache \
|
| 44 |
+
PORT=${PORT} \
|
| 45 |
+
TRANSPORT_SERVER_URL=${TRANSPORT_SERVER_URL}
|
| 46 |
+
|
| 47 |
+
# make sure cache dirs exist
|
| 48 |
+
RUN mkdir -p $HF_HUB_CACHE $TRANSFORMERS_CACHE
|
| 49 |
+
|
| 50 |
+
# ---------- install dependencies ----------
|
| 51 |
RUN --mount=type=cache,target=/tmp/uv-cache \
|
| 52 |
uv sync --locked --no-install-project --no-dev
|
| 53 |
|
| 54 |
+
# ---------- copy application code ----------
|
| 55 |
COPY --chown=appuser:appuser . .
|
| 56 |
|
| 57 |
+
# ---------- install project itself ----------
|
| 58 |
RUN --mount=type=cache,target=/tmp/uv-cache \
|
| 59 |
uv sync --locked --no-editable --no-dev
|
| 60 |
|
| 61 |
+
# ---------- virtual-env path ----------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
ENV PATH="/app/.venv/bin:$PATH"
|
| 63 |
|
| 64 |
+
# ---------- network / health ----------
|
| 65 |
EXPOSE ${PORT}
|
| 66 |
|
|
|
|
| 67 |
HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \
|
| 68 |
+
CMD python -c "import urllib.request, os; urllib.request.urlopen(f'http://localhost:{os.getenv(\"PORT\")}/api/health')" || exit 1
|
| 69 |
|
| 70 |
+
# ---------- run ----------
|
| 71 |
+
CMD ["sh", "-c", "python launch_simple.py --host 0.0.0.0 --port ${PORT} --transport-server-url ${TRANSPORT_SERVER_URL}"]
|