Skip to content

Sandbox script _copy_tree should respect .dockerignore patterns #3150

@jiridanek

Description

@jiridanek

Context

The sandbox script's _copy_tree (scripts/sandbox.py:106) copies prerequisite directories into a temp build context using os.walk(followlinks=True). It doesn't skip files/dirs excluded by .dockerignore, so untracked directories like .pnpm-store (which has a recursive content-addressed structure) cause:

OSError: [Errno 63] File name too long: '.../jupyter/utils/addons/.pnpm-store/v10/projects/.../.pnpm-store/v10/projects/.../.pnpm-store/...'

Why not just skip all hidden directories?

Blanket-skipping directories starting with . won't work — codeserver images need .git (COPY .git /root/.git in codeserver/ubi9-python-3.12/Dockerfile.cpu). The root .dockerignore explicitly documents this:

# .git/ is intentionally NOT ignored: the Dockerfile needs it to resolve the
# code-server git submodule (COPY .git ...). Ensure CI uses a shallow clone.

Proposed approach

Read .dockerignore from the repo root and extract simple directory name patterns to filter during os.walk. No new dependencies needed — use stdlib only.

  1. Add _load_dockerignore(root) — parse .dockerignore, skip comments and blanks
  2. Add _ignored_dir_names(root) — extract directory names from patterns like **/node_modules/, **/.pnpm-store/, node_modules/ by stripping **/ prefix and / suffix. Path-based patterns (like ci/) are ignored since they don't apply inside prerequisite subdirectories.
  3. Modify _copy_tree — accept dir_ignore_names: set[str] parameter, filter dirnames in-place:
    if dir_ignore_names:
        dirnames[:] = [d for d in dirnames if d not in dir_ignore_names]
  4. Update setup_sandbox — compute ignore set once, pass to all _copy_tree calls

Current .dockerignore patterns this would handle

**/node_modules/    → skip "node_modules" dirs
**/.pnpm-store/     → skip ".pnpm-store" dirs  (added in separate fix)

Workaround

Until this is fixed, remove the problematic directory:

rm -rf jupyter/utils/addons/.pnpm-store

Or add .pnpm-store/ to .gitignore and .dockerignore (already done in PR #3142).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    📋 Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions