ARG HEADPOSE_BASE_IMAGE=python:3.11-slim FROM ${HEADPOSE_BASE_IMAGE} ARG HEADPOSE_MODEL_URL=https://cloud.ovgu.de/s/Q67RnLDy6JKLRWm/download/6DRepNet_300W_LP_AFLW2000.pth ARG HEADPOSE_MODEL_SHA256=9bdcd0e072df0d21e92288b40ea1d1b3cf7173c44728ab9c45c4d673f361e018 ARG HEADPOSE_MODEL_LOCAL_PATH= ARG HEADPOSE_REUSE_BASE_RUNTIME=false ENV HEADPOSE_MODEL_PATH=/opt/models/6DRepNet_300W_LP_AFLW2000.pth \ HEADPOSE_MODEL_SHA256=sha256:9bdcd0e072df0d21e92288b40ea1d1b3cf7173c44728ab9c45c4d673f361e018 \ HEADPOSE_LICENSE_ID=MIT \ HEADPOSE_OUTPUT_ROOT=/workspace/system/headpose-service \ PYTHONUNBUFFERED=1 USER root RUN apt-get update && apt-get install -y --no-install-recommends ffmpeg \ && rm -rf /var/lib/apt/lists/* COPY services/headpose/requirements.txt /app/services/headpose/requirements.txt RUN if [ "$HEADPOSE_REUSE_BASE_RUNTIME" = "true" ]; then \ HEADPOSE_MODEL_PATH="$HEADPOSE_MODEL_PATH" HEADPOSE_MODEL_SHA256="$HEADPOSE_MODEL_SHA256" python -c 'import hashlib, os, pathlib; path=pathlib.Path(os.environ["HEADPOSE_MODEL_PATH"]); assert path.is_file(), f"base runtime model missing: {path}"; actual=hashlib.sha256(path.read_bytes()).hexdigest(); expected=os.environ["HEADPOSE_MODEL_SHA256"].removeprefix("sha256:"); assert actual == expected, f"base runtime weight digest mismatch: {actual}"; import cv2, torch, sixdrepnet'; \ else \ python -m pip install --no-cache-dir --index-url https://download.pytorch.org/whl/cu121 torch==2.3.1 torchvision==0.18.1 \ && python -m pip install --no-cache-dir -r /app/services/headpose/requirements.txt \ && python -m pip install --no-cache-dir --no-deps sixdrepnet==0.1.6 \ && mkdir -p /opt/models \ && HEADPOSE_MODEL_URL="$HEADPOSE_MODEL_URL" HEADPOSE_MODEL_LOCAL_PATH="$HEADPOSE_MODEL_LOCAL_PATH" HEADPOSE_MODEL_PATH="$HEADPOSE_MODEL_PATH" HEADPOSE_MODEL_SHA256="$HEADPOSE_MODEL_SHA256" python -c 'import hashlib, os, pathlib, shutil, urllib.request; path=pathlib.Path(os.environ["HEADPOSE_MODEL_PATH"]); local=pathlib.Path(os.environ["HEADPOSE_MODEL_LOCAL_PATH"]) if os.environ.get("HEADPOSE_MODEL_LOCAL_PATH") else None; shutil.copy2(local, path) if local and local.is_file() else urllib.request.urlretrieve(os.environ["HEADPOSE_MODEL_URL"], path); actual=hashlib.sha256(path.read_bytes()).hexdigest(); expected=os.environ["HEADPOSE_MODEL_SHA256"].removeprefix("sha256:"); assert actual == expected, f"weight digest mismatch: {actual}"'; \ fi COPY services/headpose /app/services/headpose WORKDIR /app EXPOSE 8080 USER 10001:10001 ENTRYPOINT ["python", "-m", "uvicorn", "services.headpose.app:app", "--host", "0.0.0.0", "--port", "8080", "--workers", "1"]