# syntax=docker/dockerfile:1
# devloop-temporal-worker: the reference Temporal Orchestration Worker.
#
# Installs omneval-devloop from PyPI and starts devloop.worker, which registers
# the Dev Loop and Summarization workflows on the orchestration task queue and
# serves /healthz. Consumers who need custom workflows build their own image that
# installs omneval-devloop alongside their workflow code.
#
# SDK_VERSION pins omneval-devloop to the exact release; the release pipeline
# (release.yml) passes the tag version and builds this image only after the PyPI
# publish lands, so the worker and the agent-base image always carry the same
# published SDK. Left empty on continuous (main) builds, where latest is fine.
# (Previously this installed from local source; PyPI is now the single source so
# hatch-vcs versioning — which needs git — never has to run inside a build context.)

FROM python:3.12-slim

COPY --from=ghcr.io/astral-sh/uv:0.11.18 /uv /uvx /bin/

WORKDIR /app

# Runtime dependencies (just omneval-devloop) are declared in pyproject.toml.
# SDK_VERSION pins omneval-devloop to the exact release when set (release builds);
# empty on continuous builds, which take the latest release.
#
# wait_for_pypi.py (release.yml) confirms the pinned SDK is queryable before this
# build starts, but PyPI fronts its index with a CDN whose edges propagate a fresh
# publish independently — uv's resolver can still hit a stale edge for a short
# window right after the version becomes "queryable" elsewhere. Retry the install
# itself (the thing that actually observes uv's view of the index) rather than
# trying to predict propagation from the outside.
ARG SDK_VERSION=
COPY pyproject.toml ./
RUN if [ -n "$SDK_VERSION" ]; then \
        echo "omneval-devloop==$SDK_VERSION" > /tmp/sdk-constraint.txt; \
    fi; \
    n=0; \
    until UV_HTTP_TIMEOUT=300 uv pip install --system --no-cache \
            ${SDK_VERSION:+--constraint /tmp/sdk-constraint.txt} .; do \
        n=$((n + 1)); \
        if [ "$n" -ge 6 ]; then \
            echo "uv pip install failed after $n attempts (PyPI index propagation?)" >&2; \
            rm -f /tmp/sdk-constraint.txt; \
            exit 1; \
        fi; \
        echo "uv pip install failed (attempt $n/6) — PyPI index may not have fully propagated yet; retrying in 30s" >&2; \
        sleep 30; \
    done; \
    rm -f /tmp/sdk-constraint.txt

# /healthz (Kubernetes probes) and the webhook receiver port.
EXPOSE 8080 8088

CMD ["python", "-m", "devloop.worker"]
