Skip to content

Fix duplicate venv copy in server Dockerfile template - #1034

Open
ritvik412 wants to merge 1 commit into
huggingface:mainfrom
ritvik412:fix/1021-dockerfile-venv-double-copy
Open

Fix duplicate venv copy in server Dockerfile template #1034
ritvik412 wants to merge 1 commit into
huggingface:mainfrom
ritvik412:fix/1021-dockerfile-venv-double-copy

Conversation

@ritvik412

@ritvik412 ritvik412 commented Aug 2, 2026

Copy link
Copy Markdown

Fixes #1021

Problem

openenv init generates a Dockerfile whose final stage copies the built
virtualenv twice: once explicitly, and once again implicitly because uv sync
places .venv inside /app/env, and the next layer copies /app/env
wholesale — nesting a second full copy of the venv inside it. This roughly
doubles the image size (confirmed via dive in the issue: two ~523-524MB
layers for what should be one).

Fix

  • Move .venv out of /app/env in the builder stage, before the final
    stage's copies happen, so the wholesale COPY --from=builder /app/env /app/env no longer contains a nested venv.
  • Recreate a .venv symlink inside /app/env in the runtime stage (pointing
    at the single real copy at /app/.venv) so tooling that expects the venv
    alongside the project (e.g. uv run) still works, with no second physical
    copy on disk.
  • Applied identically to src/openenv/cli/templates/openenv_env/server/Dockerfile
    and .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) and
confirmed via docker history that 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 init by stopping the server Dockerfile from shipping the same virtualenv twice.

In the builder stage, .venv is moved from /app/env/.venv to /app/.venv before the runtime stage copies /app/env wholesale, so that layer no longer embeds a second full copy of the venv alongside the explicit COPY to /app/.venv. The runtime stage adds a symlink /app/env/.venv/app/.venv so 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/Dockerfile and .claude/skills/generate-openenv-env/assets/openenv_env_template/server/Dockerfile to keep them aligned.

Reviewed by Cursor Bugbot for commit c2910b7. Bugbot is set up for automated code reviews on this repo. Configure here.

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
@ritvik412 ritvik412 changed the title Fix duplicate venv copy in server Dockerfile template (#1021) Fix duplicate venv copy in server Dockerfile template Aug 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Default Dockerfile inefficient multi-stage build results in doubling size of python venv.

1 participant