Spaces:
Runtime error
Runtime error
File size: 2,408 Bytes
e37f31f 63ed3a7 e37f31f 3380376 e3c6edf 3380376 e37f31f 3a54942 91ac14d e37f31f 91ac14d e37f31f ec69a8d 9c4d985 e37f31f 91ac14d e37f31f 2f4ec9d e37f31f ec69a8d 2fe35d2 e37f31f 2fe35d2 e37f31f 3a54942 87e57a0 63ed3a7 e37f31f 9c4d985 63ed3a7 e37f31f 3a54942 9c4d985 24816ee 9c4d985 ec69a8d 87e57a0 e37f31f ec69a8d e37f31f 3a54942 3380376 3a54942 63ed3a7 3a54942 63ed3a7 3a54942 e37f31f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | # Use official UV base image with Python 3.12
FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim
# Parameterize port with default value
ARG PORT=8001
ARG TRANSPORT_SERVER_URL=https://blanchon-robothub-transportserver.hf.space/api
# Set environment variables for Python and UV
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
UV_SYSTEM_PYTHON=1 \
UV_COMPILE_BYTECODE=1 \
UV_CACHE_DIR=/tmp/uv-cache \
PORT=${PORT} \
TRANSPORT_SERVER_URL=${TRANSPORT_SERVER_URL} \
HF_HOME=/home/appuser/.cache
# Install system dependencies
RUN apt-get update && apt-get install -y \
# Build tools for compiling Python packages
build-essential \
gcc \
g++ \
# Essential system libraries
libgl1-mesa-glx \
libglib2.0-0 \
libsm6 \
libxext6 \
libxrender-dev \
libgomp1 \
# FFmpeg for video processing
ffmpeg \
# Git for potential model downloads
git \
# Clean up
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Create a non-root user
RUN groupadd -r appuser && useradd -r -g appuser -m -s /bin/bash appuser
# Set working directory
WORKDIR /home/appuser
# Copy dependency files for better layer caching
COPY --chown=appuser:appuser pyproject.toml uv.lock* ./
# Copy external dependencies (submodules) needed for dependency resolution
COPY --chown=appuser:appuser external/ ./external/
# Install dependencies first (better caching)
RUN --mount=type=cache,target=/tmp/uv-cache \
uv sync --locked --no-install-project --no-dev
# Copy the rest of the application
COPY --chown=appuser:appuser . .
# Install the project in non-editable mode for production
RUN --mount=type=cache,target=/tmp/uv-cache \
uv sync --locked --no-editable --no-dev
# Switch to non-root user
USER appuser
# Create cache directories for Hugging Face with proper ownership
RUN mkdir -p /home/appuser/.cache/hub && \
chown -R appuser:appuser /home/appuser/.cache
# Add virtual environment to PATH
ENV PATH="/home/appuser/.venv/bin:$PATH"
# Expose port (parameterized)
EXPOSE ${PORT}
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \
CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:${PORT}/api/health')" || exit 1
# Run the application
CMD ["sh", "-c", "python launch_simple.py --host 0.0.0.0 --port ${PORT} --transport-server-url ${TRANSPORT_SERVER_URL}"] |