Skip to content

Read Docker ignore rules when locating requirements inputs - #626

Merged
patrickballard merged 9 commits into
wheelgap:mainfrom
kunalkshah1:fix/dockerignore-inputs
Nov 21, 2026
Merged

patrickballard merged 9 commits into
wheelgap:mainfrom
kunalkshah1:fix/dockerignore-inputs

Conversation

@kunalkshah1

Copy link
Copy Markdown
Contributor

Closes #597

What this changes

Use the Dockerfile-specific ignore file when present, otherwise the context-root .dockerignore. Interpret Go filepath patterns, **, parent directories and last-match exceptions with BuildKit's pruning rules. When a requirements file would be excluded, identify the COPY and the matching rule.

References: Docker ignore files, Moby patternmatcher, and BuildKit's bundled fsutil.

Compared 11,150 pattern/path cases against the bundled Go matcher and pruning rules with no mismatches. Reversing the rule order in the matcher made four regression tests fail.

AI tools used: Codex

Ruff formatting and lint, mypy, and full pytest passed (5,196 passed, 3 skipped). The Unreleased entry will be added with the PR number.

@patrickballard

Copy link
Copy Markdown
Collaborator

Thanks @kunalkshah1, this looks good overall: the Dockerfile-specific ignore file wins over the context's .dockerignore, the matcher follows BuildKit's rules for **, parent directories and last-match exceptions, and an excluded requirements file is reported with the COPY line and the rule that excludes it. Checking the matcher against BuildKit's own is exactly the care this needs.

It touches the same parts of dockerfile.py and cli.py as your other --dockerfile-inputs PRs (#621, #622, #625, #626, #630), so Patrick will sort out the merge order and any conflicts between them.

CI is green on this commit.

#597 is a help wanted issue, so Patrick will review and merge this one himself. Nothing more needed from you for now.

(Review assisted by Claude.)

Kunal Shah and others added 4 commits November 21, 2026 16:20
…gainst Moby's table

Three cases where the reading could differ from Docker's now raise instead: a pattern that Moby's second clean-and-trim turns into an exception or trims (./!a, ./ a); a backslash, colon or leading // when wheelgap runs on Windows, where Docker's client reads backslash as a separator; and an empty Dockerfile-specific ignore file beside a .dockerignore with rules, where BuildKit's built-in and # syntax= frontends pick different files. Adds Moby's patternmatcher test table and fsutil's exception cases as tests, and says in the docs what is read.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@patrickballard

Copy link
Copy Markdown
Collaborator

Thanks @kunalkshah1! This is a faithful port of Moby's matcher. We read moby/patternmatcher, tonistiigi/fsutil and BuildKit's dockerui and compared rule by rule: exceptions and ordering, parent pruning, **, classes, cleaning, and which ignore file is used.

We've made these changes so it can go in. Each is a case Docker can read differently from the port, so wheelgap now refuses instead of guessing:

  • A pattern that becomes an exception after Moby's second clean (./!keep).
  • An empty Dockerfile-specific ignore file beside a .dockerignore with rules; which one wins depends on the frontend.
  • Backslash, drive and UNC patterns when wheelgap runs on Windows, where Docker reads \ as a separator.

We also added Moby's own matcher test table and fsutil's exception cases as tests (they pass on Linux, macOS and Windows), and the docs say what is read, marked "after 0.13.0".

It merges third of the four Dockerfile PRs, with main merged in, and gets its final review on that head.

(Review assisted by Claude.)

patrickballard and others added 2 commits November 21, 2026 11:31
main gained wheelgap#622 (pip flags, -c FILE on the RUN line, the --prefer-binary
gate), wheelgap#621 (verified -r/-c includes) and wheelgap#630 since this branch was written.

dockerfile.py: main moved the COPY lookup into _find_copied_file, called by
the copied_requirements closure and by _check_includes. The ignore rules are
now a required argument of _find_copied_file and _check_includes and reach
_copied_file from both, so a file that .dockerignore leaves out under a folder
COPY is refused with the rule named whether it is the installed file, a -c
file on the RUN line, or a -r/-c inside either. Without this an excluded
include would have been read from disk although the image doesn't have it.
The old "a .dockerignore is refused" loop stays deleted (main still had it),
and the merged docstring no longer lists a .dockerignore among the refusals.

tests: both sides' new tests are kept; the nested-includes test keeps wheelgap#621's
assertions and this branch's removal of its .dockerignore tail. New tests for
the interaction: an excluded include (one and two levels down), an excluded
-c file, an excluded -r inside the -c file, the same under --prefer-binary,
an include a later ! rule puts back (and a later rule takes out again), a
file COPY naming an excluded source, and the CLI looking nothing up.

docs/cli.md: the ignore-file paragraph says included and constraints files
are covered. CHANGELOG: every bullet once, this PR's first.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
…reads as rules

Two cases where a file the image doesn't have was read:

- A symlink is matched against the ignore rules by its own name, so a link
  whose target the rules leave out (a linked folder under `COPY . .`, or a
  linked file a COPY names) was read although it dangles in the image. When
  the ignore file has rules, a COPY source or a file under a folder COPY that
  is, or is reached through, a symlink below the build context is now an
  error. With no ignore file, or one with no rules, nothing changes.
- Moby's patternmatcher.New cleans an exception with its ! still on, so
  `!../../requirements.txt` becomes the rule `requirements.txt`, which
  excludes. The port kept it as an exception that matches nothing; it is now
  refused, naming the ignore file's line.

Merges main (wheelgap#624); CHANGELOG keeps every bullet once, this PR's first.
docs/cli.md says both, and the over-long line is wrapped.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@patrickballard
patrickballard merged commit 68b95b7 into wheelgap:main Nov 21, 2026
13 checks passed
@patrickballard

Copy link
Copy Markdown
Collaborator

Merged, thanks @kunalkshah1! A second read against moby/patternmatcher and fsutil agreed with the port, and every row of Moby's own test table is in the tests.

Two narrow cases from the final review now refuse instead of reading the file:

  • With ignore rules, a path that goes through a symlink. The link is matched by its own name, so a rule that excludes its target leaves the link dangling in the image.
  • An exception that climbs out of its own path (!../../name), which Moby's cleaning turns into a plain exclude.

It went in combined with #621 and #622, so the rules also apply to constraints files and to every included file.

(Reply assisted by Claude.)

patrickballard added a commit to kunalkshah1/wheelgap that referenced this pull request Nov 21, 2026
…t be pinned

main gained -c FILE and harmless pip flags (wheelgap#622), verified includes (wheelgap#621),
.dockerignore rules (wheelgap#626), install provenance (wheelgap#630), uv's Requires-Python
lower-bound rule (wheelgap#623) and MCP wording (wheelgap#624) since this branch was written.

_pip_install_files returns (files, constraints, prefer_binary, uv) and has one
flag loop with the uv branch first. On a uv line only uv's own flags are read:
--system, -r/--requirements, -c/--constraints, --no-cache, --no-cache-dir,
--upgrade/-U and --quiet/-q (checked against `uv pip install --help`, 0.13.1).
pip's --no-input, --root-user-action and --prefer-binary don't exist in uv, and
--disable-pip-version-check only warns there, so they are refused.

A uv line's files are found by the same copied_requirements closure as pip's,
so the ignore rules and the include checks apply. Three things are uv's own:
- every requirement must be pinned with == (through includes; a pin from a
  constraints file counts), using the gate --prefer-binary already had, and
  --deps is refused: wheelgap resolves a range as pip does, and uv can pick
  another release;
- a -r inside a constraints file is refused: pip installs what it names and uv
  only constrains with it (uv 0.13.1 against pip 26.2);
- included and -c files must be named *.txt or *.in, like the -r file.
A file installed by pip on one line and uv on another is refused, and a caller
that doesn't pass uv_installs gets an error rather than pip's answer.

cli.py: the stderr note keeps main's list of every file read and says which
installer ran; uv-installed files get restore_uv_python_files, as a uv.lock
with --online does, so the pip_refuses note is main's.

docs/cli.md has one paragraph for uv; CHANGELOG keeps every bullet once, this
PR's first, reworded.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
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.

--dockerfile-inputs: read .dockerignore instead of refusing every project that has one

2 participants