# Both bases are resolved and validated by the CLI before this build starts.
ARG BUILDER=scratch
ARG RUNTIME=scratch
FROM ${BUILDER} AS build
ARG RUNTIME=scratch
ARG ACTION_PLATFORM
ARG RUNTIME_IDENTITY
ENV ACTION_BASE=${RUNTIME_IDENTITY} ACTION_PLATFORM=${ACTION_PLATFORM}
COPY metadata/ /metadata/
# BEGIN dependencies
RUN --mount=type=cache,target=/root/.cache/pip \
    python -m pyplines.actions.build_dependencies /metadata/pyproject.toml > /metadata/requirements.txt && \
    if [ -f /metadata/uv.lock ]; then \
      python -m venv /opt/uv && /opt/uv/bin/pip install uv==0.12.18 && \
      cd /metadata && UV_PYTHON_DOWNLOADS=never /opt/uv/bin/uv export --locked --no-dev --no-emit-project --no-editable --format requirements-txt --output-file /metadata/locked.txt && \
      pip install --constraint /opt/pyplines/constraints.txt -r /metadata/locked.txt && \
      UV_PYTHON_DOWNLOADS=never /opt/uv/bin/uv export --locked --no-dev --no-emit-project --no-editable --no-hashes --format requirements-txt --output-file /metadata/constraints.txt && \
      pip install --constraint /opt/pyplines/constraints.txt --constraint /metadata/constraints.txt -r /metadata/requirements.txt && \
      rm -rf /opt/uv; \
    else pip install --constraint /opt/pyplines/constraints.txt -r /metadata/requirements.txt; fi
# END dependencies
COPY source/ /source/
ARG DEVELOPMENT=false
ARG DIAGNOSTICS=detailed
RUN --mount=type=cache,target=/root/.cache/pip pip install --constraint /opt/pyplines/constraints.txt $(if [ -f /metadata/locked.txt ]; then printf "%s" "--constraint /metadata/constraints.txt"; fi) --no-build-isolation /source && if [ "$DEVELOPMENT" = "true" ]; then python -m pyplines.actions.development --build /source --diagnostics "$DIAGNOSTICS"; else python -m pyplines.actions build /source; fi && pip check
RUN pip uninstall -y pip setuptools wheel
FROM ${RUNTIME}
COPY --from=build /opt/venv /opt/venv
COPY --from=build /opt/pyplines/action /opt/pyplines/action
USER 65532:65532
WORKDIR /tmp
ENTRYPOINT ["python", "-m", "pyplines.actions"]
