File size: 2,315 Bytes
63ed3a7
 
2fe35d2
3380376
e3c6edf
3380376
91ac14d
 
 
 
 
 
63ed3a7
2fe35d2
91ac14d
63ed3a7
2f4ec9d
2fe35d2
91ac14d
2fe35d2
 
 
 
 
91ac14d
 
 
 
 
 
 
2f4ec9d
 
 
 
 
 
91ac14d
2fe35d2
 
 
 
 
 
 
 
 
87e57a0
63ed3a7
2fe35d2
63ed3a7
 
2fe35d2
 
87e57a0
 
91ac14d
63ed3a7
 
2fe35d2
3380376
63ed3a7
91ac14d
63ed3a7
91ac14d
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
FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim

# ---------- build args ----------
ARG PORT=8001
ARG TRANSPORT_SERVER_URL=https://blanchon-robothub-transportserver.hf.space/api

# ---------- system packages ----------
RUN apt-get update && apt-get install -y --no-install-recommends \
        build-essential gcc g++ \
        libgl1-mesa-glx libglib2.0-0 libsm6 libxext6 libxrender-dev libgomp1 \
        ffmpeg git \
    && apt-get clean && rm -rf /var/lib/apt/lists/*

# ---------- app user ----------
RUN groupadd -r appuser && useradd -m -r -g appuser -s /bin/bash appuser

# ---------- cache directories & environment ----------
ENV HOME=/home/appuser
ENV \
    HF_HOME=$HOME/.cache \
    HF_HUB_CACHE=$HOME/.cache/hub \
    HUGGINGFACE_HUB_CACHE=$HOME/.cache/hub \
    TRANSFORMERS_CACHE=$HOME/.cache/huggingface/hub \
    UV_CACHE_DIR=$HOME/.cache/uv \
    PYTHONUNBUFFERED=1 \
    PYTHONDONTWRITEBYTECODE=1 \
    UV_SYSTEM_PYTHON=1 \
    UV_COMPILE_BYTECODE=1 \
    PORT=${PORT} \
    TRANSPORT_SERVER_URL=${TRANSPORT_SERVER_URL}

# create the caches while still root, then chown to appuser
RUN mkdir -p "$HF_HUB_CACHE" "$TRANSFORMERS_CACHE" "$UV_CACHE_DIR" \
    && chown -R appuser:appuser "$HOME/.cache"

# switch to non-root user (no inline comment!)
USER appuser

# ---------- workdir ----------
WORKDIR /app

# ---------- copy manifests first ----------
COPY --chown=appuser:appuser pyproject.toml uv.lock* ./
COPY --chown=appuser:appuser external/ ./external/

# ---------- install deps ----------
RUN --mount=type=cache,target=$UV_CACHE_DIR,uid=1000,gid=1000 \
    uv sync --locked --no-install-project --no-dev

# ---------- copy source ----------
COPY --chown=appuser:appuser . .

# ---------- install the project itself ----------
RUN --mount=type=cache,target=$UV_CACHE_DIR,uid=1000,gid=1000 \
    uv sync --locked --no-editable --no-dev

# ---------- virtual-env path ----------
ENV PATH="/app/.venv/bin:$PATH"

# ---------- runtime ----------
EXPOSE ${PORT}
HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \
    CMD python -c "import urllib.request, os; urllib.request.urlopen(f'http://localhost:{os.getenv(\"PORT\")}/api/health')" || exit 1

CMD ["sh", "-c", "python launch_simple.py --host 0.0.0.0 --port ${PORT} --transport-server-url ${TRANSPORT_SERVER_URL}"]