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

Allow exclude section to point at existing ignore file #2265

Open
nickhammond opened this issue Sep 22, 2024 · 4 comments
Open

Allow exclude section to point at existing ignore file #2265

nickhammond opened this issue Sep 22, 2024 · 4 comments
Labels
help wanted Need some extra hands to get this done. status/ready Issue ready to be worked on. type/enhancement Issue that requests a new feature or improvement.

Comments

@nickhammond
Copy link

nickhammond commented Sep 22, 2024

Description

Most container-based applications already have a .dockerignore, it'd be great to be able to point to one of these files for the exclude section of your project descriptor.

Proposed solution

  1. Add a file-based reference to the exclude section, something like:
exclude_list = ".dockerignore"
  1. Potentially add a CLI option --exclude_list .dockerignore

Either option would read .dockerignore and utilize that as the exclude option for the pack instead of listing them out.

Describe alternatives you've considered

  1. Open .dockerignore
  2. Copy entire file contents
  3. Create project.toml with base spec and an exclude section
  4. Within the exclude section paste in the lines from your .dockerignore file
  5. Remove all comments and empty lines
  6. Quote each line and turn into a proper array of directives so that it looks something like this:
[io.buildpacks]
exclude = [
  "/.git/",
  ".env"
]
  1. Remember to maintain two ignore/exclude lists, the one in project.toml and the other one in .dockerignore

Additional context

@nickhammond nickhammond added status/triage Issue or PR that requires contributor attention. type/enhancement Issue that requests a new feature or improvement. labels Sep 22, 2024
@natalieparellano natalieparellano added status/ready Issue ready to be worked on. help wanted Need some extra hands to get this done. and removed status/triage Issue or PR that requires contributor attention. labels Sep 23, 2024
@jjbustamante
Copy link
Member

Thinking about this feature, the challenge is the semantics of those ignored files are the same. Searching a little bit I found the following:

Relative Path

In .gitignore, a relative path (e.g. filename) matches the path under any directory;

while in .dockerignore, a relative path (e.g. filename) is the same as a rooted one (e.g. /filename) and matches only ones under the root. To match the path under any directory, **/filename should be used.

Files Under Ignored Path

In .gitignore, if a path is listed as ignored (e.g. /dir), then any files or folders under that path is ignored and it is not possible to re-include them via negation (e.g. !/dir/file) as the parent directory of them is excluded;

while in .dockerignore, even if a parent path is ignored, files or folders under it can still be re-included via negation.

In case where pack takes .dockerignore or .gitignore as input, would we need to implement a different parser for both to handle the semantic of rules of each of them?

@nickhammond
Copy link
Author

@jjbustamante I think the focus should just be on .dockerignore since that's what Docker supports and looks for out of the box https://docs.docker.com/build/concepts/context/#dockerignore-files.

I've removed the mention of .gitignore from the description.

@jjbustamante
Copy link
Member

@jjbustamante I think the focus should just be on .dockerignore since that's what Docker supports and looks for out of the box https://docs.docker.com/build/concepts/context/#dockerignore-files.

I've removed the mention of .gitignore from the description.

Thanks!

But now checking our documentation

Note the include and exclude sections in the below project.toml file use gitignore syntax. So "/README.md" excludes the README file at the root of the application. For more on gitignore matching see these docs.

Maybe we need to define which syntax from .dockerignore we will implement and which not

@nickhammond
Copy link
Author

@jjbustamante That's fun.

I mean I suppose since project.toml uses .gitignore syntax it could just use the same matching for this. Not as obvious but it seems like it'd be more confusing to omit certain matching rules to try to make the .dockerignore matching rules work.

It's also a more straightforward transition if you decide to move your exclude rules from your project.toml to their own file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Need some extra hands to get this done. status/ready Issue ready to be worked on. type/enhancement Issue that requests a new feature or improvement.
Projects
None yet
Development

No branches or pull requests

3 participants