# Sophios REST API image.
#
# NOTE: noble (24.04) ships Python 3.12. jammy (22.04) ships 3.10, which is
# below the >=3.11 that pyproject.toml requires, so the install cannot succeed
# there.
FROM ubuntu:noble

# python3-pip comes from the distro, so no separate bootstrap host is needed.
# graphviz supplies the `dot` binary that the graphviz Python bindings shell
# out to; the bindings alone are not enough.
RUN apt-get update && \
    apt-get install --no-install-recommends -y \
        python3 \
        python3-pip \
        graphviz && \
    rm -rf /var/lib/apt/lists/*

COPY . /sophios
WORKDIR /sophios

# The image has no git, so setuptools-scm cannot read the release tag here. The
# publish workflow passes the version it read from the tag; a local build
# without it reports the post-release dev version from pyproject.toml.
ARG SOPHIOS_VERSION=""

# PEP 668 marks the distro interpreter externally managed. Inside a container
# there is no other consumer of site-packages, so installing into it directly
# is what we want.
RUN if [ -n "$SOPHIOS_VERSION" ]; then \
        export SETUPTOOLS_SCM_PRETEND_VERSION_FOR_SOPHIOS="$SOPHIOS_VERSION"; \
    fi && \
    pip3 install --no-cache-dir --break-system-packages /sophios

# Then run the sophios REST API through port 3000
EXPOSE 3000

CMD ["uvicorn", "sophios.contrib.rest.api:app", "--host", "0.0.0.0", "--port", "3000"]
