# Single image with everything Adrift needs to review a PR:
#   Python 3.11 + Node 20 + GitNexus + Adrift itself.
#
# Use as a CLI in CI:
#     docker run --rm \
#       -e GITHUB_TOKEN -e ANTHROPIC_API_KEY \
#       -v "$(pwd):/workspace" \
#       ghcr.io/mohamad-zubi/adrift:latest \
#       review https://github.com/your-org/your-repo/pull/42 --dry-run
#
# Or replace your workflow's setup-python + setup-node + pip install +
# npm install steps with a single `container:` directive — see
# `examples/workflows/adrift-review-docker.yml`.

FROM python:3.11-slim AS runtime

# All system-level setup happens in one layer so apt-get/npm caches don't
# bloat the final image. GitNexus's tree-sitter bindings need a C++
# toolchain at install time; we add and then purge it in the same layer
# so it doesn't ship in the final image.
ENV NODE_VERSION=20 \
    GITNEXUS_SKIP_OPTIONAL_GRAMMARS=1
RUN apt-get update \
    && apt-get install -y --no-install-recommends \
        curl \
        ca-certificates \
        git \
        build-essential \
        python3-dev \
    && curl -fsSL https://deb.nodesource.com/setup_${NODE_VERSION}.x | bash - \
    && apt-get install -y --no-install-recommends nodejs \
    && npm install -g --omit=dev gitnexus \
    && npm cache clean --force \
    && apt-get purge -y --auto-remove build-essential python3-dev curl \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

# Install Adrift from the build context (the tag's checkout). This keeps
# the image tied to exactly the code at that tag, no race against PyPI
# publishing finishing first.
WORKDIR /opt/adrift
COPY pyproject.toml README.md LICENSE ./
COPY adrift ./adrift
RUN pip install --no-cache-dir . \
    && rm -rf /root/.cache/pip

# Default working directory for `docker run`. Bind-mount your repo here.
WORKDIR /workspace

# Adrift is the entrypoint — `docker run <image> review <pr-url>` works
# without specifying the binary name. Override with `--entrypoint sh`
# for an interactive shell.
ENTRYPOINT ["adrift"]
CMD ["--help"]

LABEL org.opencontainers.image.title="Adrift" \
      org.opencontainers.image.description="Open-source PR reviewer for design-intent regressions." \
      org.opencontainers.image.source="https://github.com/MOHAMAD-ZUBI/Adrift" \
      org.opencontainers.image.licenses="MIT"
