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

integrate frontend/dockerfile/dockerignore from BuildKit #1

Merged
merged 22 commits into from
Aug 22, 2023

Conversation

thaJeztah
Copy link
Member

Integrating the "frontend/dockerfile/dockerignore" package from
github.com/moby/buildkit at commit moby/buildkit@9da03ce

Steps taken:

# install filter-repo (https://github.com/newren/git-filter-repo/blob/main/INSTALL.md)
brew install git-filter-repo

# create a temporary clone of docker
cd ~/Projects
git clone https://github.com/moby/buildkit.git buildkit_temp
cd buildkit_temp

# commit taken from
git rev-parse --verify HEAD
9da03ce42beb47d0d0a34c68ea90cac793b79851

# remove all code, except for 'frontend/dockerfile/dockerignore', and rename to /ignorefile
git filter-repo \
  --path-match 'frontend/dockerfile/dockerignore/' \
  --path-rename frontend/dockerfile/dockerignore/dockerignore.go:ignorefile/ignorefile.go \
  --path-rename frontend/dockerfile/dockerignore/dockerignore_test.go:ignorefile/ignorefile_test.go

# go to the target github.com/moby/patternmatcher repository
cd ~/go/src/github.com/moby/patternmatcher

# create a branch to work with
git checkout -b integrate_dockerignore

# add the temporary repository as an upstream and make sure it's up-to-date
git remote add buildkit_temp ~/Projects/buildkit_temp
git fetch buildkit_temp

# merge the upstream code
git merge --allow-unrelated-histories --signoff -S buildkit_temp/master

Tibor Vass and others added 21 commits December 14, 2015 14:59
filepath.Clean converts filenames to filenames with native path
separators. Use ToSlash to normalize.

Signed-off-by: Anusha Ragunathan <[email protected]>
This fix tries to address the issue raised in #20083 where
comment is not supported in `.dockerignore`.

This fix updated the processing of `.dockerignore` so that any
lines starting with `#` are ignored, which is similiar to the
behavior of `.gitignore`.

Related documentation has been updated.

Additional tests have been added to cover the changes.

This fix fixes #20083.

Signed-off-by: Yong Tang <[email protected]>
This fix tries to address issues related to #23221 where Dockerignore
may consists of UTF-8 BOM. This likely happens when Notepad
tries to save a file as UTF-8 in Windows.

This fix skips the UTF-8 BOM bytes from the beginning of the
Dockerignore if exists.

Additional tests has been added to cover the changes in this fix.

This fix is related to #23221 (UTF-8 BOM in Dockerfile).

Signed-off-by: Yong Tang <[email protected]>
…matting

text does not appear to contain a placeholder

Signed-off-by: Helen Xie <[email protected]>
According to documentation (https://docs.docker.com/engine/reference/builder/#dockerignore-file), absolute paths like `/foo/bar` should have the same effect as `foo/bar`. This is not the case today.

This fix normalize paths when reading the .dockerignore file by removing
leading slashes.

Signed-off-by: Simon Ferquel <[email protected]>
Signed-off-by: Daniel Nephin <[email protected]>
Signed-off-by: Daniel Nephin <[email protected]>
Signed-off-by: wingkwong <[email protected]>
Signed-off-by: Sebastiaan van Stijn <[email protected]>
Signed-off-by: David Gageot <[email protected]>
This commit replaces `os.MkdirTemp` with `t.TempDir` in tests. The
directory created by `t.TempDir` is automatically removed when the test
and all its subtests complete.

Prior to this commit, temporary directory created using `os.MkdirTemp`
needs to be removed manually by calling `os.RemoveAll`, which is omitted
in some tests. The error handling boilerplate e.g.
	defer func() {
		if err := os.RemoveAll(dir); err != nil {
			t.Fatal(err)
		}
	}
is also tedious, but `t.TempDir` handles this for us nicely.

Reference: https://pkg.go.dev/testing#T.TempDir
Signed-off-by: Eng Zer Jun <[email protected]>
Required for gosec

Signed-off-by: Justin Chadwell <[email protected]>
- 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 thaJeztah force-pushed the integrate_dockerignore branch from 47300f2 to 9736100 Compare July 30, 2023 10:37
Integrating the "frontend/dockerfile/dockerignore" package from
github.com/moby/buildkit at commit 9da03ce42beb47d0d0a34c68ea90cac793b79851

Steps taken:

    # install filter-repo (https://github.com/newren/git-filter-repo/blob/main/INSTALL.md)
    brew install git-filter-repo

    # create a temporary clone of docker
    cd ~/Projects
    git clone https://github.com/moby/buildkit.git buildkit_temp
    cd buildkit_temp

    # commit taken from
    git rev-parse --verify HEAD
    9da03ce42beb47d0d0a34c68ea90cac793b79851

    # remove all code, except for 'frontend/dockerfile/dockerignore', and rename to /ignorefile
    git filter-repo \
      --path-match 'frontend/dockerfile/dockerignore/' \
      --path-rename frontend/dockerfile/dockerignore/dockerignore.go:ignorefile/ignorefile.go \
      --path-rename frontend/dockerfile/dockerignore/dockerignore_test.go:ignorefile/ignorefile_test.go

    # go to the target github.com/moby/patternmatcher repository
    cd ~/go/src/github.com/moby/patternmatcher

    # create a branch to work with
    git checkout -b integrate_dockerignore

    # add the temporary repository as an upstream and make sure it's up-to-date
    git remote add buildkit_temp ~/Projects/buildkit_temp
    git fetch buildkit_temp

    # merge the upstream code
    git merge --allow-unrelated-histories --signoff -S buildkit_temp/master

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

Thanks! I'll bring this one in 👍

@thaJeztah thaJeztah merged commit 347bb8d into moby:main Aug 22, 2023
@thaJeztah thaJeztah deleted the integrate_dockerignore branch August 22, 2023 20:52
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.