Skip to content

fix(Dockerfile): add rust ov#570

Merged
qin-ctx merged 1 commit intomainfrom
fix_Dockerfile
Mar 13, 2026
Merged

fix(Dockerfile): add rust ov#570
qin-ctx merged 1 commit intomainfrom
fix_Dockerfile

Conversation

@zhoujh01
Copy link
Copy Markdown
Collaborator

Description

Related Issue

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional changes)
  • Performance improvement
  • Test update

Changes Made

Testing

  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have tested this on the following platforms:
    • Linux
    • macOS
    • Windows

Checklist

  • My code follows the project's coding style
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

Screenshots (if applicable)

Additional Notes

@github-actions
Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ No major issues detected

@github-actions
Copy link
Copy Markdown

PR Code Suggestions ✨

No code suggestions found for the PR.

@@ -24,7 +32,9 @@ ENV UV_NO_DEV=1
WORKDIR /app

# Copy source required for setup.py artifact builds and native extension build.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Bug] COPY Cargo.toml Cargo.lock ./ 放在 COPY pyproject.toml ... 之前,Cargo.lock 是一个 3232 行的文件,任何变更都会使后续所有层的 Docker 缓存失效,包括 uv sync 这个最耗时的步骤。建议将 Cargo 文件的 COPY 与 Python 依赖安装分离,或调整层顺序以优化缓存命中率。

ENV PATH="/usr/local/go/bin:${PATH}"
# Reuse Rust toolchain from stage 2 so setup.py can compile ov CLI in-place.
COPY --from=rust-toolchain /usr/local/cargo /usr/local/cargo
COPY --from=rust-toolchain /usr/local/rustup /usr/local/rustup
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Suggestion] 将完整的 cargo + rustup 工具链(通常 500MB~800MB)复制到 py-builder 阶段,但实际上 setup.py 只需要最终编译出的 ov 二进制文件(几 MB)。

建议改为在 rust-toolchain 阶段直接编译,只复制产物:

# Stage 2: build Rust CLI
FROM rust:1.88-trixie AS rust-builder
WORKDIR /build
COPY Cargo.toml Cargo.lock ./
COPY crates/ crates/
RUN --mount=type=cache,target=/usr/local/cargo/registry \
    --mount=type=cache,target=/build/target \
    cargo build --release --package ov_cli

# Stage 3: py-builder
FROM ghcr.io/astral-sh/uv:python3.13-trixie-slim AS py-builder
COPY --from=rust-builder /build/target/release/ov /app/openviking/bin/ov

setup.py 已支持 OV_SKIP_OV_BUILD=1OV_PREBUILT_BIN_DIR 环境变量来跳过 Rust 构建,所以这个方案可行。

# Copy source required for setup.py artifact builds and native extension build.
COPY Cargo.toml Cargo.lock ./
COPY pyproject.toml uv.lock setup.py README.md ./
COPY crates/ crates/
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Suggestion] 当前 uv sync 已使用 --mount=type=cache,但 Cargo 的依赖下载和编译缓存未被挂载。每次构建都会重新下载和编译所有 Rust 依赖。

建议添加 Cargo cache mount,例如:

RUN --mount=type=cache,target=/root/.cache/uv \
    --mount=type=cache,target=/usr/local/cargo/registry \
    --mount=type=cache,target=/app/target \
    uv sync --no-editable

@qin-ctx qin-ctx merged commit 8f1fef9 into main Mar 13, 2026
7 checks passed
@qin-ctx qin-ctx deleted the fix_Dockerfile branch March 13, 2026 08:03
@github-project-automation github-project-automation bot moved this from Backlog to Done in OpenViking project Mar 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants