# Benchmark session/grade container. Build: docker build -t docwiki-bench-<repo> --build-arg TOOLCHAIN=node:22 benchmark/harness/docker/
ARG TOOLCHAIN=node:22
FROM ${TOOLCHAIN}
ARG CLAUDE_CODE_VERSION=2.1.170
# EXTRA_APT: optional space-separated list of additional apt packages to install at build time (e.g. "libpq-dev").
ARG EXTRA_APT=""
ENV DISABLE_AUTOUPDATER=1 \
    CLAUDE_CONFIG_DIR=/claude-cfg
RUN apt-get update && apt-get install -y --no-install-recommends git iptables dnsutils ca-certificates bash sudo curl ${EXTRA_APT} \
    && rm -rf /var/lib/apt/lists/* \
    && npm install -g @anthropic-ai/claude-code@${CLAUDE_CODE_VERSION} \
    # Enable corepack now (as root): the pnpm/yarn shims live in the root-owned global
    # prefix, so the non-root session user cannot run `corepack enable` itself. Per-run
    # installs just call `pnpm`; corepack auto-provisions the packageManager-pinned version
    # into COREPACK_HOME (node-writable) on first use, before the egress firewall comes up.
    && corepack enable \
    && mkdir -p /claude-cfg /out /work \
    # Claude Code refuses --dangerously-skip-permissions as root; run as the image's
    # non-root user (Anthropic devcontainer pattern). The firewall still needs root —
    # grant a single NOPASSWD sudo rule scoped to that one script.
    && chown -R node:node /claude-cfg /out /work \
    && echo "node ALL=(root) NOPASSWD: /usr/local/bin/init-firewall.sh" > /etc/sudoers.d/bench-firewall \
    && chmod 440 /etc/sudoers.d/bench-firewall
# Install uv system-wide so Python repos can provision their own Python at session time (no root needed).
# UV_INSTALL_DIR places the binary directly into /usr/local/bin (on PATH for the node user).
RUN curl -LsSf https://astral.sh/uv/install.sh | env UV_INSTALL_DIR=/usr/local/bin sh
COPY entrypoint.sh grade.sh init-firewall.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/entrypoint.sh /usr/local/bin/grade.sh /usr/local/bin/init-firewall.sh
USER node
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
