FROM python:3.12-slim

ARG INSTALL_NER=false
ARG INSTALL_DOCS=false

ENV PYTHONDONTWRITEBYTECODE=1 \
    PYTHONUNBUFFERED=1 \
    REDACTOR_SOCKET=/run/vault/daemon.sock

WORKDIR /app

# Create unprivileged non-root user
RUN groupadd --gid 10001 redactor && \
    useradd --uid 10001 --gid 10001 --create-home --shell /bin/false redactor

COPY pyproject.toml README.md ./
COPY rules ./rules
COPY src ./src

RUN pip install --no-cache-dir --upgrade pip && \
    if [ "$INSTALL_NER" = "true" ] && [ "$INSTALL_DOCS" = "true" ]; then \
        pip install --no-cache-dir ".[ner,docs]" && \
        python -m spacy download en_core_web_sm; \
    elif [ "$INSTALL_NER" = "true" ]; then \
        pip install --no-cache-dir ".[ner]" && \
        python -m spacy download en_core_web_sm; \
    elif [ "$INSTALL_DOCS" = "true" ]; then \
        pip install --no-cache-dir ".[docs]"; \
    else \
        pip install --no-cache-dir .; \
    fi

RUN mkdir -p /run/vault /data/sensitive /data/clean /data/output && \
    chown -R redactor:redactor /run/vault /data /app

USER redactor

ENTRYPOINT ["redactor-mcp"]
CMD ["daemon"]
