perf(docker): single-stage with cache-friendly layer ordering#139
Merged
perf(docker): single-stage with cache-friendly layer ordering#139
Conversation
Reshape the Dockerfile so heavy deps live in a stable early layer (digest reproducible across releases, users cache it) and per-release cocoindex + cocoindex-code installs land in their own small layer at the end. Cuts the per-release `docker pull` from ~5 GB to ~470 MB. Specifically: - Drop the multi-stage builder/model_cache layout; do everything in one runtime image so each install RUN produces its own distinct layer. BuildKit COPY in a multi-stage emits the full copied tree as a layer (not a diff) — that's what made the previous two-COPY split bloat the image to ~10 GB without saving any pull cost. - Order layers so per-release content (the source-tree-dependent install) is last; everything before reuses across releases. - Use `RUN --mount=type=bind,source=.,target=/ccc-src,rw=true` instead of `COPY . /ccc-src` so hatch-vcs can write `_version.py` during the PEP 517 build without persisting the source tree as a layer in the final image. Image sizes: slim 534 MB (was 598 MB), full 5.77 GB (was 5.83 GB). Per-release layer: 468 MB (uv install on top of pre-installed ST). Verified: docker E2E suite passes (6 passed, 2 Linux-only skipped on macOS).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replaces the multi-stage / two-COPY layout introduced in #138 with a single-stage Dockerfile that actually achieves the user-pull-cost optimization. The previous attempt bloated the image to 10 GB without reducing per-release downloads — BuildKit's
COPY --fromemits the full copied tree as a layer rather than a diff vs. the destination.Summary
cocoindex+cocoindex-codeinstall is the last layer. EachRUN uv pip installproduces its own distinct layer with a content-addressable digest.docker pulling an upgrade keep that ~5 GB layer locally.litellminto the stable layer to shrink further.RUN --mount=type=bind,source=.,target=/ccc-src,rw=trueinstead ofCOPY . /ccc-src— gives hatch-vcs a writable overlay for_version.pyduring the PEP 517 build without persisting the source tree as a layer in the final image.Numbers
Test plan
uv run pytest -m docker_e2e— 6 passed, 2 Linux-only PUID tests skipped on macOS.workflow_dispatchwithtest_docker=truewill populate the GHA cache; the release after should show short build times.🤖 Generated with Claude Code