From 1dffa3a814c462f7be4f3070806d1f8a89491bce Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Wed, 23 Aug 2023 00:50:05 +0200 Subject: [PATCH 1/2] vendor: github.com/moby/patternmatcher v0.6.0 - integrate frontend/dockerfile/dockerignore from buildkit full diff: https://github.com/moby/patternmatcher/compare/v0.5.0...v0.6.0 Signed-off-by: Sebastiaan van Stijn (cherry picked from commit a479b287c70631eca104713cdc25928d09239416) Signed-off-by: Sebastiaan van Stijn --- vendor.mod | 2 +- vendor.sum | 4 ++-- vendor/modules.txt | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/vendor.mod b/vendor.mod index 38ef1bceb5..93f5c691ef 100644 --- a/vendor.mod +++ b/vendor.mod @@ -59,7 +59,7 @@ require ( github.com/moby/buildkit v0.11.7-0.20230908085316-d3e6c1360f6e // IMPORTANT: when updating, also update the version in builder/builder-next/worker/worker.go github.com/moby/ipvs v1.1.0 github.com/moby/locker v1.0.1 - github.com/moby/patternmatcher v0.5.0 + github.com/moby/patternmatcher v0.6.0 github.com/moby/pubsub v1.0.0 github.com/moby/swarmkit/v2 v2.0.0-20230531205928-01bb7a41396b github.com/moby/sys/mount v0.3.3 diff --git a/vendor.sum b/vendor.sum index af7288f89a..27e579cad9 100644 --- a/vendor.sum +++ b/vendor.sum @@ -1049,8 +1049,8 @@ github.com/moby/ipvs v1.1.0 h1:ONN4pGaZQgAx+1Scz5RvWV4Q7Gb+mvfRh3NsPS+1XQQ= github.com/moby/ipvs v1.1.0/go.mod h1:4VJMWuf098bsUMmZEiD4Tjk/O7mOn3l1PTD3s4OoYAs= github.com/moby/locker v1.0.1 h1:fOXqR41zeveg4fFODix+1Ch4mj/gT0NE1XJbp/epuBg= github.com/moby/locker v1.0.1/go.mod h1:S7SDdo5zpBK84bzzVlKr2V0hz+7x9hWbYC/kq7oQppc= -github.com/moby/patternmatcher v0.5.0 h1:YCZgJOeULcxLw1Q+sVR636pmS7sPEn1Qo2iAN6M7DBo= -github.com/moby/patternmatcher v0.5.0/go.mod h1:hDPoyOpDY7OrrMDLaYoY3hf52gNCR/YOUYxkhApJIxc= +github.com/moby/patternmatcher v0.6.0 h1:GmP9lR19aU5GqSSFko+5pRqHi+Ohk1O69aFiKkVGiPk= +github.com/moby/patternmatcher v0.6.0/go.mod h1:hDPoyOpDY7OrrMDLaYoY3hf52gNCR/YOUYxkhApJIxc= github.com/moby/pubsub v1.0.0 h1:jkp/imWsmJz2f6LyFsk7EkVeN2HxR/HTTOY8kHrsxfA= github.com/moby/pubsub v1.0.0/go.mod h1:bXSO+3h5MNXXCaEG+6/NlAIk7MMZbySZlnB+cUQhKKc= github.com/moby/swarmkit/v2 v2.0.0-20230531205928-01bb7a41396b h1:w07xyBXYTrihwBqCkuXPLqcQ1a2guqXlRIocU+e9K7A= diff --git a/vendor/modules.txt b/vendor/modules.txt index 6de240d235..2115baa49e 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -730,7 +730,7 @@ github.com/moby/ipvs # github.com/moby/locker v1.0.1 ## explicit; go 1.13 github.com/moby/locker -# github.com/moby/patternmatcher v0.5.0 +# github.com/moby/patternmatcher v0.6.0 ## explicit; go 1.19 github.com/moby/patternmatcher # github.com/moby/pubsub v1.0.0 From daf599ea0a518ee9d4ad02493fcee8a846627160 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Wed, 23 Aug 2023 00:53:18 +0200 Subject: [PATCH 2/2] replace dockerfile/dockerignore with patternmatcher/ignorefile The BuildKit dockerignore package was integrated in the patternmatcher repository / module. This patch updates our uses of the BuildKit package with its new location. A small local change was made to keep the format of the existing error message, because the "ignorefile" package is slightly more agnostic in that respect and doesn't include ".dockerignore" in the error message. Signed-off-by: Sebastiaan van Stijn (cherry picked from commit 3553b4c68490387d51e99368bdbe868c52a2119c) Signed-off-by: Sebastiaan van Stijn --- builder/remotecontext/detect.go | 6 +- .../patternmatcher/ignorefile/ignorefile.go | 73 +++++++++++++++++++ vendor/modules.txt | 1 + 3 files changed, 77 insertions(+), 3 deletions(-) create mode 100644 vendor/github.com/moby/patternmatcher/ignorefile/ignorefile.go diff --git a/builder/remotecontext/detect.go b/builder/remotecontext/detect.go index 93cceef6b3..a7b991f416 100644 --- a/builder/remotecontext/detect.go +++ b/builder/remotecontext/detect.go @@ -14,9 +14,9 @@ import ( "github.com/docker/docker/builder/remotecontext/urlutil" "github.com/docker/docker/errdefs" "github.com/docker/docker/pkg/containerfs" - "github.com/moby/buildkit/frontend/dockerfile/dockerignore" "github.com/moby/buildkit/frontend/dockerfile/parser" "github.com/moby/patternmatcher" + "github.com/moby/patternmatcher/ignorefile" "github.com/pkg/errors" "github.com/sirupsen/logrus" ) @@ -123,10 +123,10 @@ func removeDockerfile(c modifiableContext, filesToRemove ...string) error { case err != nil: return err } - excludes, err := dockerignore.ReadAll(f) + excludes, err := ignorefile.ReadAll(f) if err != nil { f.Close() - return err + return errors.Wrap(err, "error reading .dockerignore") } f.Close() filesToRemove = append([]string{".dockerignore"}, filesToRemove...) diff --git a/vendor/github.com/moby/patternmatcher/ignorefile/ignorefile.go b/vendor/github.com/moby/patternmatcher/ignorefile/ignorefile.go new file mode 100644 index 0000000000..94ea5a0ef5 --- /dev/null +++ b/vendor/github.com/moby/patternmatcher/ignorefile/ignorefile.go @@ -0,0 +1,73 @@ +package ignorefile + +import ( + "bufio" + "bytes" + "io" + "path/filepath" + "strings" +) + +// ReadAll reads an ignore file from a reader and returns the list of file +// patterns to ignore, applying the following rules: +// +// - An UTF8 BOM header (if present) is stripped. +// - Lines starting with "#" are considered comments and are skipped. +// +// For remaining lines: +// +// - Leading and trailing whitespace is removed from each ignore pattern. +// - It uses [filepath.Clean] to get the shortest/cleanest path for +// ignore patterns. +// - Leading forward-slashes ("/") are removed from ignore patterns, +// so "/some/path" and "some/path" are considered equivalent. +func ReadAll(reader io.Reader) ([]string, error) { + if reader == nil { + return nil, nil + } + + var excludes []string + currentLine := 0 + utf8bom := []byte{0xEF, 0xBB, 0xBF} + + scanner := bufio.NewScanner(reader) + for scanner.Scan() { + scannedBytes := scanner.Bytes() + // We trim UTF8 BOM + if currentLine == 0 { + scannedBytes = bytes.TrimPrefix(scannedBytes, utf8bom) + } + pattern := string(scannedBytes) + currentLine++ + // Lines starting with # (comments) are ignored before processing + if strings.HasPrefix(pattern, "#") { + continue + } + pattern = strings.TrimSpace(pattern) + if pattern == "" { + continue + } + // normalize absolute paths to paths relative to the context + // (taking care of '!' prefix) + invert := pattern[0] == '!' + if invert { + pattern = strings.TrimSpace(pattern[1:]) + } + if len(pattern) > 0 { + pattern = filepath.Clean(pattern) + pattern = filepath.ToSlash(pattern) + if len(pattern) > 1 && pattern[0] == '/' { + pattern = pattern[1:] + } + } + if invert { + pattern = "!" + pattern + } + + excludes = append(excludes, pattern) + } + if err := scanner.Err(); err != nil { + return nil, err + } + return excludes, nil +} diff --git a/vendor/modules.txt b/vendor/modules.txt index 2115baa49e..98d93fccc9 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -733,6 +733,7 @@ github.com/moby/locker # github.com/moby/patternmatcher v0.6.0 ## explicit; go 1.19 github.com/moby/patternmatcher +github.com/moby/patternmatcher/ignorefile # github.com/moby/pubsub v1.0.0 ## explicit; go 1.19 github.com/moby/pubsub