Fix duplicate venv copy in server Dockerfile template - #1034
Open
ritvik412 wants to merge 1 commit into
Open
Conversation
openenv init generated Dockerfiles copy the built virtualenv twice: once explicitly (COPY --from=builder /app/env/.venv /app/.venv) and once implicitly, since uv sync places .venv inside /app/env and the next layer copies /app/env wholesale (COPY --from=builder /app/env /app/env). This roughly doubles the final image size (~523MB -> two ~524MB layers per dive output in huggingface#1021). Fix: move .venv out of /app/env in the builder stage before the final stage copies happen, then symlink /app/env/.venv -> /app/.venv in the runtime stage so tooling that expects the venv alongside the project (e.g. uv run) keeps working, without shipping a second physical copy. Applied identically to both copies of the template (CLI init template and the Claude Code skill's mirrored asset) since they were already kept byte-for-byte identical apart from the license header. Fixes huggingface#1021
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.
Fixes #1021
Problem
openenv initgenerates a Dockerfile whose final stage copies the builtvirtualenv twice: once explicitly, and once again implicitly because
uv syncplaces
.venvinside/app/env, and the next layer copies/app/envwholesale — nesting a second full copy of the venv inside it. This roughly
doubles the image size (confirmed via
divein the issue: two ~523-524MBlayers for what should be one).
Fix
.venvout of/app/envin the builder stage, before the finalstage's copies happen, so the wholesale
COPY --from=builder /app/env /app/envno longer contains a nested venv..venvsymlink inside/app/envin the runtime stage (pointingat the single real copy at
/app/.venv) so tooling that expects the venvalongside the project (e.g.
uv run) still works, with no second physicalcopy on disk.
src/openenv/cli/templates/openenv_env/server/Dockerfileand
.claude/skills/generate-openenv-env/assets/openenv_env_template/server/Dockerfile,since these two files were already kept byte-for-byte identical (aside from
license header) and would otherwise drift.
Testing
Built a fresh env from the fixed template (
openenv init+docker build) andconfirmed via
docker historythat the venv is now copied once, not twice:Note
Low Risk
Build-only Dockerfile template change with no runtime application logic; behavior is intended to stay the same aside from smaller images.
Overview
Fixes roughly doubled Docker image size for environments built from
openenv initby stopping the server Dockerfile from shipping the same virtualenv twice.In the builder stage,
.venvis moved from/app/env/.venvto/app/.venvbefore the runtime stage copies/app/envwholesale, so that layer no longer embeds a second full copy of the venv alongside the explicitCOPYto/app/.venv. The runtime stage adds a symlink/app/env/.venv→/app/.venvso tools that expect a venv next to the project (e.g.uv run) still work without a second on-disk copy.The same change is applied in both
src/openenv/cli/templates/openenv_env/server/Dockerfileand.claude/skills/generate-openenv-env/assets/openenv_env_template/server/Dockerfileto keep them aligned.Reviewed by Cursor Bugbot for commit c2910b7. Bugbot is set up for automated code reviews on this repo. Configure here.