# Mist backend image — used by both `api` and `worker` containers.
# The api container runs uvicorn (the default ENTRYPOINT); the worker container
# overrides the command to `celery -A mist.worker worker --loglevel=INFO`.

FROM python:3.12-slim AS base

# System deps for py7zr, librsync, hdiff, build tools.
# hdiffz/hpatchz/rdiff binaries are expected to be installed here at /usr/local/bin.
# In dev they can be bind-mounted; in prod they're baked in. Placeholder COPY below.
RUN apt-get update && apt-get install -y --no-install-recommends \
        build-essential \
        librsync-dev \
        rdiff \
        curl \
        ca-certificates \
    && rm -rf /var/lib/apt/lists/*

# TODO: copy hdiffz/hpatchz binaries from a known release tarball (build-time stage)
#       For now, the operator is expected to provide them; or build from source.

WORKDIR /app

COPY pyproject.toml ./pyproject.toml
COPY src ./src
COPY alembic.ini ./alembic.ini

RUN pip install --no-cache-dir -e .

ENV PYTHONPATH=/app/src
ENV PYTHONUNBUFFERED=1

EXPOSE 8000

# Default entrypoint = api. The worker container overrides this in docker-compose.yml.
CMD ["uvicorn", "mist.api.app:app", "--host", "0.0.0.0", "--port", "8000"]
