Repository navigation
perf: reduce sandbox image build time and size during onboarding - #855
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
✅ Files skipped from review due to trivial changes (3)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughThis PR refactors Docker sandbox build-context staging by extracting inline logic into a dedicated module supporting both legacy and optimized strategies. The optimized approach reduces build-context size by selectively copying essential files (package metadata, source code, minimal scripts) instead of entire directories. Integration into the primary onboarding workflow is simplified, and new benchmarking and test utilities validate performance improvements and prevent regressions. Changes
Sequence DiagramsequenceDiagram
actor User
participant CLI as benchmark-sandbox-image-build.js
participant Git as Git
participant Staging as Staging Logic
participant Docker as Docker
participant FS as File System
User->>CLI: Run benchmark script
activate CLI
CLI->>Git: Create detached worktree at main-ref
Git-->>CLI: Worktree ready
rect rgba(255, 200, 100, 0.5)
Note over CLI,Docker: Legacy Build Cycle
CLI->>Staging: stageLegacySandboxBuildContext()
Staging->>FS: Copy nemoclaw, nemoclaw-blueprint, scripts
Staging->>FS: Remove node_modules
Staging-->>CLI: buildCtx path, stats
CLI->>Docker: docker build (legacy)
Docker-->>CLI: Build time, image size
end
rect rgba(100, 200, 255, 0.5)
Note over CLI,Docker: Optimized Build Cycle
CLI->>Staging: stageOptimizedSandboxBuildContext()
Staging->>FS: Copy selective files (metadata, src, nemoclaw-start.sh)
Staging-->>CLI: buildCtx path, stats
CLI->>Docker: docker build (optimized)
Docker-->>CLI: Build time, image size
end
CLI->>CLI: Calculate deltas
CLI->>User: Print summary & comparison
CLI->>FS: Clean up temporary directories
CLI->>Docker: Remove temporary image tags
CLI->>Git: Remove temporary worktree
deactivate CLI
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
|
✨ Thanks for submitting this PR with a detailed summary, it proposes a fix to improve the performance of NemoClaw. |
Merge main into fix/optimize-sandbox-image-builds, resolving four conflicts: - Dockerfile: take main's base-image approach (monolithic layers now in Dockerfile.base), keep PR's builder improvements (npm ci, ENV) - bin/lib/onboard.js: combine main's pRetry/envInt/redact with PR's stageOptimizedSandboxBuildContext - test/onboard.test.js: keep both main's new helper tests and PR's build context test - scripts/setup.sh: accept main's deletion (superseded by nemoclaw onboard) Signed-off-by: Aaron Erickson <aerickson@nvidia.com>
ericksoa
left a comment
There was a problem hiding this comment.
Merge conflicts resolved, all 1012 unit tests pass, pre-commit hooks clean, nightly e2e validated.
…DIA#855) ## Summary Reduce NemoClaw sandbox image build cost during onboarding without changing functionality or weakening the current security model. This PR keeps the existing monolithic image approach, but trims unnecessary build/runtime overhead and adds a repeatable benchmark for comparing image build performance against `origin/main`. ## What Changed - stage a minimal sandbox build context instead of copying whole source trees - exclude `nemoclaw-blueprint/.venv` from the staged context - stage only the blueprint files the Docker build actually consumes - switch plugin installs from `npm install` to lockfile-backed `npm ci` - remove unused runtime packages from the sandbox image: - `python3-pip` - `python3-venv` - `iproute2` - build-time `PyYAML` - prune clearly non-runtime OpenClaw package content after install: - docs - READMEs - changelogs - source maps - add benchmark tooling for `origin/main` vs current branch sandbox image builds ## Security / Behavior This PR is intentionally scoped to image build optimization and does not change the core security model. Preserved: - immutable `openclaw.json` / config-hash protection - gateway vs sandbox user separation - no credential values in CLI argv - no sandbox secret env injection during sandbox create - Dockerfile arg-to-env injection guard for the Python config generation step Security validation still passes, including the gateway isolation end-to-end test. ## Validation Repo checks: - `npx vitest run test/sandbox-build-context.test.js test/onboard.test.js test/security-c2-dockerfile-injection.test.js test/credential-exposure.test.js test/runner.test.js` - `git diff --check` - `bash -n test/e2e-test.sh test/e2e-gateway-isolation.sh` Container/security checks: - `bash test/e2e-gateway-isolation.sh` - result: `10 passed`, `0 failed` Benchmark: - `node scripts/benchmark-sandbox-image-build.js` Latest result: - `main (93a475a)`: `74.2s`, `1493.0 MiB` - `candidate`: `40.8s`, `1165.7 MiB` Delta: - build time: `33.4s` faster - image size: `327.3 MiB` smaller ## Follow-up The next larger step is tracked separately in NVIDIA#854: - reusable `nemoclaw-base` image - thin per-onboard top image - optional uninstall purge for cached/base images - possible GHCR publishing flow <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added build performance benchmarking capability to compare sandbox image build strategies. * **Refactor** * Optimized Docker build process with deterministic dependency installation and reduced build context size for faster, more efficient builds. * **Tests** * Added test coverage for build-context staging and validation. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Signed-off-by: Aaron Erickson <aerickson@nvidia.com> Co-authored-by: Aaron Erickson <aerickson@nvidia.com>
…DIA#855) ## Summary Reduce NemoClaw sandbox image build cost during onboarding without changing functionality or weakening the current security model. This PR keeps the existing monolithic image approach, but trims unnecessary build/runtime overhead and adds a repeatable benchmark for comparing image build performance against `origin/main`. ## What Changed - stage a minimal sandbox build context instead of copying whole source trees - exclude `nemoclaw-blueprint/.venv` from the staged context - stage only the blueprint files the Docker build actually consumes - switch plugin installs from `npm install` to lockfile-backed `npm ci` - remove unused runtime packages from the sandbox image: - `python3-pip` - `python3-venv` - `iproute2` - build-time `PyYAML` - prune clearly non-runtime OpenClaw package content after install: - docs - READMEs - changelogs - source maps - add benchmark tooling for `origin/main` vs current branch sandbox image builds ## Security / Behavior This PR is intentionally scoped to image build optimization and does not change the core security model. Preserved: - immutable `openclaw.json` / config-hash protection - gateway vs sandbox user separation - no credential values in CLI argv - no sandbox secret env injection during sandbox create - Dockerfile arg-to-env injection guard for the Python config generation step Security validation still passes, including the gateway isolation end-to-end test. ## Validation Repo checks: - `npx vitest run test/sandbox-build-context.test.js test/onboard.test.js test/security-c2-dockerfile-injection.test.js test/credential-exposure.test.js test/runner.test.js` - `git diff --check` - `bash -n test/e2e-test.sh test/e2e-gateway-isolation.sh` Container/security checks: - `bash test/e2e-gateway-isolation.sh` - result: `10 passed`, `0 failed` Benchmark: - `node scripts/benchmark-sandbox-image-build.js` Latest result: - `main (93a475a)`: `74.2s`, `1493.0 MiB` - `candidate`: `40.8s`, `1165.7 MiB` Delta: - build time: `33.4s` faster - image size: `327.3 MiB` smaller ## Follow-up The next larger step is tracked separately in NVIDIA#854: - reusable `nemoclaw-base` image - thin per-onboard top image - optional uninstall purge for cached/base images - possible GHCR publishing flow <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added build performance benchmarking capability to compare sandbox image build strategies. * **Refactor** * Optimized Docker build process with deterministic dependency installation and reduced build context size for faster, more efficient builds. * **Tests** * Added test coverage for build-context staging and validation. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Signed-off-by: Aaron Erickson <aerickson@nvidia.com> Co-authored-by: Aaron Erickson <aerickson@nvidia.com>
Summary
Reduce NemoClaw sandbox image build cost during onboarding without changing functionality or weakening the current security model.
This PR keeps the existing monolithic image approach, but trims unnecessary build/runtime overhead and adds a repeatable benchmark for comparing image build performance against
origin/main.What Changed
nemoclaw-blueprint/.venvfrom the staged contextnpm installto lockfile-backednpm cipython3-pippython3-venviproute2PyYAMLorigin/mainvs current branch sandbox image buildsSecurity / Behavior
This PR is intentionally scoped to image build optimization and does not change the core security model.
Preserved:
openclaw.json/ config-hash protectionSecurity validation still passes, including the gateway isolation end-to-end test.
Validation
Repo checks:
npx vitest run test/sandbox-build-context.test.js test/onboard.test.js test/security-c2-dockerfile-injection.test.js test/credential-exposure.test.js test/runner.test.jsgit diff --checkbash -n test/e2e-test.sh test/e2e-gateway-isolation.shContainer/security checks:
bash test/e2e-gateway-isolation.sh10 passed,0 failedBenchmark:
node scripts/benchmark-sandbox-image-build.jsLatest result:
main (93a475a):74.2s,1493.0 MiBcandidate:40.8s,1165.7 MiBDelta:
33.4sfaster327.3 MiBsmallerFollow-up
The next larger step is tracked separately in #854:
nemoclaw-baseimageSummary by CodeRabbit
New Features
Refactor
Tests