blanchon commited on
Commit
2fe35d2
·
1 Parent(s): 91ac14d
Files changed (1) hide show
  1. Dockerfile +27 -34
Dockerfile CHANGED
@@ -1,7 +1,6 @@
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
 
@@ -12,60 +11,54 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
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}"]
 
 
1
  FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim
2
 
3
+ # ---------- build args ----------
4
  ARG PORT=8001
5
  ARG TRANSPORT_SERVER_URL=https://blanchon-robothub-transportserver.hf.space/api
6
 
 
11
  ffmpeg git \
12
  && apt-get clean && rm -rf /var/lib/apt/lists/*
13
 
14
+ # ---------- app user ----------
15
  RUN groupadd -r appuser && useradd -m -r -g appuser -s /bin/bash appuser
16
+ USER appuser # ←─── switch early!
17
 
18
+ # ---------- directories & env ----------
19
+ ENV HOME=/home/appuser
 
 
 
 
 
 
 
 
 
20
  ENV \
21
+ # Hugging-Face / transformers caches
22
+ HF_HOME=$HOME/.cache \
23
+ HF_HUB_CACHE=$HOME/.cache/hub \
24
+ HUGGINGFACE_HUB_CACHE=$HOME/.cache/hub \
25
+ TRANSFORMERS_CACHE=$HOME/.cache/huggingface/hub \
26
+ # uv’s compilation / wheel cache
27
+ UV_CACHE_DIR=$HOME/.cache/uv \
28
+ # python / app settings
 
29
  PYTHONUNBUFFERED=1 \
30
  PYTHONDONTWRITEBYTECODE=1 \
31
  UV_SYSTEM_PYTHON=1 \
32
  UV_COMPILE_BYTECODE=1 \
 
33
  PORT=${PORT} \
34
  TRANSPORT_SERVER_URL=${TRANSPORT_SERVER_URL}
35
 
36
+ RUN mkdir -p "$HF_HUB_CACHE" "$TRANSFORMERS_CACHE" "$UV_CACHE_DIR"
 
37
 
38
+ # ---------- workdir ----------
39
+ WORKDIR /app
40
+
41
+ # ---------- copy manifests first ----------
42
+ COPY --chown=appuser:appuser pyproject.toml uv.lock* ./
43
+ COPY --chown=appuser:appuser external/ ./external/
44
+
45
+ # ---------- install deps ----------
46
+ RUN --mount=type=cache,target=$UV_CACHE_DIR,uid=1000,gid=1000 \
47
  uv sync --locked --no-install-project --no-dev
48
 
49
+ # ---------- copy source ----------
50
  COPY --chown=appuser:appuser . .
51
 
52
+ # ---------- install the project itself ----------
53
+ RUN --mount=type=cache,target=$UV_CACHE_DIR,uid=1000,gid=1000 \
54
  uv sync --locked --no-editable --no-dev
55
 
56
  # ---------- virtual-env path ----------
57
  ENV PATH="/app/.venv/bin:$PATH"
58
 
59
+ # ---------- runtime ----------
60
  EXPOSE ${PORT}
 
61
  HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \
62
  CMD python -c "import urllib.request, os; urllib.request.urlopen(f'http://localhost:{os.getenv(\"PORT\")}/api/health')" || exit 1
63
 
 
64
  CMD ["sh", "-c", "python launch_simple.py --host 0.0.0.0 --port ${PORT} --transport-server-url ${TRANSPORT_SERVER_URL}"]