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