# Matrx SEO — standalone vertical service image.
#
# PYPI mode installs ENTIRELY from PyPI (every matrx-* dep is published; a bare
# `uv pip install matrx-seo[standalone]` is proven by the independence gate).
# Build from anywhere:
#   docker build -t matrx-seo packages/matrx-seo
# Pin the version at build time for reproducible deploys:
#   docker build --build-arg MATRX_SEO_VERSION==0.1.0 -t matrx-seo:0.1.0 packages/matrx-seo
#
# No system binaries: this service talks HTTP to SEO providers and Postgres to
# the ONE database. Nothing to render, nothing to OCR — keep the image small.
FROM python:3.14-slim

RUN pip install --no-cache-dir uv

# TWO install modes, one Dockerfile:
#   SOURCE (how the Server Manager deploys, from the aidream release commit):
#     the build context holds requirements.txt + packages/<matrx-seo and every
#     matrx-* sibling it installs>, written by the Manager's source bundle
#     (infra/matrx-ship/server-manager/src/microservice_source.js).
#   PYPI (manual / independence proof): context is packages/matrx-seo; no
#     requirements.txt, so the published package is installed.
ARG MATRX_SEO_VERSION=""
COPY . /build/
RUN if [ -f /build/requirements.txt ]; then \
      uv pip install --system --no-sources -r /build/requirements.txt; \
    else \
      uv pip install --system "matrx-seo[standalone]${MATRX_SEO_VERSION}"; \
    fi && rm -rf /build

# What runs, readable from /health and the image labels (empty in PYPI mode).
ARG MATRX_BUILD_COMMIT=""
ARG MATRX_SOURCE_ID=""
ENV MATRX_BUILD_COMMIT=${MATRX_BUILD_COMMIT} MATRX_SOURCE_ID=${MATRX_SOURCE_ID}
LABEL org.opencontainers.image.revision=${MATRX_BUILD_COMMIT} matrx.source-id=${MATRX_SOURCE_ID}
RUN printf '%s\n%s\n' "${MATRX_BUILD_COMMIT}" "${MATRX_SOURCE_ID}" > /etc/matrx-build-identity

EXPOSE 8081
CMD ["uvicorn", "matrx_seo.standalone.app:create_app", "--factory", "--host", "0.0.0.0", "--port", "8081"]
