# syntax=docker/dockerfile:1.4
# ============================================================
# Velocity-OS — media-engine (Dream Weaver Gateway)
# Async ComfyUI job gateway. Models mounted from NVMe PV.
# ============================================================

FROM python:3.11-slim AS runtime

LABEL org.opencontainers.image.title="velocity-os-media-engine" \
      org.opencontainers.image.description="Velocity-OS Dream Weaver / ComfyUI Gateway" \
      org.opencontainers.image.vendor="Desineuron" \
      org.opencontainers.image.version="2.0.0"

RUN apt-get update && apt-get install -y --no-install-recommends \
    curl \
    && rm -rf /var/lib/apt/lists/*

RUN groupadd -r velocity && useradd -r -g velocity velocity

WORKDIR /app

COPY requirements.txt .
RUN --mount=type=cache,target=/root/.cache/pip \
    pip install --no-cache-dir -r requirements.txt

COPY --chown=velocity:velocity . .

ENV PYTHONUNBUFFERED=1 \
    PYTHONPATH=/app \
    # Overridden by K3s ConfigMap/env
    COMFYUI_URLS="http://localhost:8188" \
    DW_ASSET_DIR="/opt/assets/generated" \
    MODEL_BASE="/opt/models/comfy"

USER velocity

EXPOSE 8290

HEALTHCHECK --interval=60s --timeout=10s --start-period=30s \
    CMD curl -f http://localhost:8290/health || exit 1

CMD ["python", "gateway.py", "--host", "0.0.0.0", "--port", "8290"]
