Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

frontend/dockerfile/dockerignore: assorted cleanups #4062

Merged
merged 3 commits into from
Jul 27, 2023

Conversation

thaJeztah
Copy link
Member

I'm considering moving this package to https://github.com/moby/patternmatcher (but no final "decision" yet). At least let's clean up this package a bit in case.

frontend/dockerfile/dockerignore: cleanup unit test

  • don't use a temp-file for the test as all we need is a reader
  • use a const and string-literal for the test-content, which makes it
    slightly more readable
  • don't use hard-coded tests for each line, but use an "expected" slice
  • don't fail early if line-numbers don't match

frontend/dockerfile/dockerignore: touch-up godoc and code

Use "doc links" where possible, and better describe the function.

Before:

Screenshot 2023-07-25 at 10 25 09

After:

Screenshot 2023-07-25 at 10 24 37

frontend/dockerfile/dockerignore: remove hard-coded filename from error

While this function would usually be used for read a .dockerignore file,
it accepts a Reader and can also be used to handle ignore patterns from
other files (e.g. Dockerfile.dockerignore) or other sources. The error
was also wrapped multiple times in some code-paths, which could lead to
an error being formatted as:

failed to parse dockerignore: error reading .dockerignore: <some error>

Let's remove mention of the .dockerignore filename from the error, and
leave it to the caller to include the filename.

@crazy-max
Copy link
Member

I'm considering moving this package to https://github.com/moby/patternmatcher (but no final "decision" yet). At least let's clean up this package a bit in case.

Could we do the other way around and first have the implementation forked in github.com/moby/patternmatcher and open this PR there with your changes and then vendored here?

@thaJeztah
Copy link
Member Author

My intent was to "mostly" keep the files the same. Then, when we (if we) vendor it from moby/patternmatcher, the PR should just show a "rename" of the files, with no changes (other than package name)

thaJeztah and others added 3 commits July 26, 2023 13:15
- don't use a temp-file for the test as all we need is a reader
- use a const and string-literal for the test-content, which makes it
  slightly more readable
- don't use hard-coded tests for each line, but use an "expected" slice
- don't fail early if line-numbers don't match

Signed-off-by: Sebastiaan van Stijn <[email protected]>
Use "doc links" where possible, and better describe the function.

Signed-off-by: Sebastiaan van Stijn <[email protected]>
While this function would usually be used for read a `.dockerignore` file,
it accepts a Reader and can also be used to handle ignore patterns from
other files (e.g. `Dockerfile.dockerignore`) or other sources. The error
was also wrapped multiple times in some code-paths, which could lead to
an error being formatted as:

    failed to parse dockerignore: error reading .dockerignore: <some error>

Let's remove mention of the `.dockerignore` filename from the error, and
leave it to the caller to include the filename.

This patch also brings the  MainContext dockerignore error inline with the
NamedContext dockerignore error, now printing the exact name of the file.

Co-authored-by: Justin Chadwell <[email protected]>
Signed-off-by: Sebastiaan van Stijn <[email protected]>
@thaJeztah
Copy link
Member Author

Updated with @jedevc's patch (I squashed it into the last commit, but added you as co-author; also updated both errors to be "failed parsing ..")

@jedevc jedevc merged commit 405f75f into moby:master Jul 27, 2023
56 of 57 checks passed
@thaJeztah thaJeztah deleted the cleanup_dockerignore branch July 27, 2023 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants