Spaces:
Running
Running
Download Dockerfile from Sdm0/opencodereview: direct link, hf CLI and curl.
- Browser
- Download file 4.26 kB
-
https://huggingface.co/spaces/Sdm0/opencodereview/resolve/main/Dockerfile
- Command line
-
hf download hf://spaces/Sdm0/opencodereview/Dockerfile
-
curl -L -o Dockerfile https://huggingface.co/spaces/Sdm0/opencodereview/resolve/main/Dockerfile
4.26 kB
| # ============================================================================= | |
| # 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. | |