Spaces:
Running
Running
File size: 4,256 Bytes
47d2384 b582abc 47d2384 c392bff b582abc 0e64a0d b582abc 47d2384 0e64a0d 3c52a25 47d2384 bd551c6 47d2384 9bd6fdd 47d2384 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | # =============================================================================
# OpenCodeReview β Dockerfile
# =============================================================================
# Multi-stage build:
# 1. builder β installs all Python dependencies
# 2. runtime β minimal image with just the app + deps
#
# Usage
# -----
# docker build -t opencodereview .
# docker run --rm opencodereview review --smoke
# docker run --rm -e GROQ_API_KEY=gsk_... -e GITHUB_TOKEN=ghp_... \
# opencodereview review --repo org/repo --pr 42
#
# To include sentence-transformers (needed for vector-store retrieval):
# docker build --target runtime-full -t opencodereview:full .
#
# Environment variables
# ---------------------
# GROQ_API_KEY Required for AI reviewers (correctness, security, etc.)
# GITHUB_TOKEN Required for fetching PRs and posting comments
# =============================================================================
# -- Stage 1: Builder (core + optional deps, except heavy ML) -----------------
FROM python:3.12-slim AS builder
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1
WORKDIR /build
# Install system build deps needed by chromadb
RUN apt-get update && apt-get install -y --no-install-recommends \
gcc \
g++ \
build-essential \
&& rm -rf /var/lib/apt/lists/*
# Core dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# Optional dependencies (chromadb for vector store, langchain-groq for LLM)
# ragas and litellm are installed here (not just via requirements.txt)
# so pip resolves all transitive deps (numpy, etc.) together with
# chromadb, avoiding version conflicts at runtime.
RUN pip install --no-cache-dir \
chromadb \
langchain-groq \
langfuse \
langchain-google-genai \
"ragas>=0.4,<0.5" \
"langchain-community>=0.4.1,<0.4.2" \
litellm
# -- Stage 2: Runtime (default) -----------------------------------------------
FROM python:3.12-slim AS runtime
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1
WORKDIR /app
# chromadb/onnx needs libgomp at runtime
RUN apt-get update && apt-get install -y --no-install-recommends \
libgomp1 \
&& rm -rf /var/lib/apt/lists/*
# Copy Python packages from builder
COPY --from=builder /usr/local/lib/python3.12/site-packages /usr/local/lib/python3.12/site-packages
COPY --from=builder /usr/local/bin /usr/local/bin
# Copy application code
COPY . .
COPY docker-entrypoint.sh /docker-entrypoint.sh
# Install ragas+litellm as fallback in case multi-stage COPY missed them.
# ragas 0.4.x keeps the single_turn_score API used by the code; langchain-community
# must stay <0.4.2 (0.4.2 removed chat_models.vertexai, which ragas imports at
# startup β previously masked as "ragas not installed").
RUN pip install --no-cache-dir "ragas>=0.4,<0.5" "langchain-community>=0.4.1,<0.4.2" litellm
# Non-root user
RUN useradd -m -u 1000 appuser && chown -R appuser:appuser /app \
&& chmod +x /docker-entrypoint.sh \
&& mkdir -p /tmp/opencodereview_vectors \
&& chown -R appuser:appuser /tmp/opencodereview_vectors
# The entrypoint runs as root to fix volume permissions, then drops to appuser.
# Default: run the Gradio web UI on port 7860 (HF Spaces expects this).
# Override CMD for CLI usage:
# docker run --rm opencodereview python -m main review --smoke
ENTRYPOINT ["/docker-entrypoint.sh"]
CMD ["uvicorn", "combined_server:app", "--host", "0.0.0.0", "--port", "7860"]
# -- Stage 3: Full runtime (includes sentence-transformers for embeddings) -----
# Build with: docker build --target runtime-full -t opencodereview:full .
FROM runtime AS runtime-full
USER root
RUN pip install --no-cache-dir sentence-transformers
# Note: No USER appuser here β ENTRYPOINT (inherited from runtime) handles privilege dropping
# Keep the lightweight runtime as Docker's default final stage. The full image
# remains available explicitly with `--target runtime-full` for local retrieval
# rebuilds that need sentence-transformers.
FROM runtime AS final
# Note: sentence-transformers pulls in PyTorch (~800 MB), making the image
# significantly larger. Only use this target when you need the retrieval node
# to build vector indexes from scratch.
|