Skip to content

Commit 7eb2cea

Browse files
thaJeztahjedevc
andcommitted
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. 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 <me@jedevc.com> Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent d116081 commit 7eb2cea

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

frontend/dockerfile/dockerignore/dockerignore.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import (
66
"io"
77
"path/filepath"
88
"strings"
9-
10-
"github.com/pkg/errors"
119
)
1210

1311
// ReadAll reads an ignore file from a reader and returns the list of file
@@ -69,7 +67,7 @@ func ReadAll(reader io.Reader) ([]string, error) {
6967
excludes = append(excludes, pattern)
7068
}
7169
if err := scanner.Err(); err != nil {
72-
return nil, errors.Wrap(err, "error reading .dockerignore")
70+
return nil, err
7371
}
7472
return excludes, nil
7573
}

frontend/dockerui/config.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ type Client struct {
8080
g flightcontrol.Group[*buildContext]
8181
bopts client.BuildOpts
8282

83-
dockerignore []byte
83+
dockerignore []byte
84+
dockerignoreName string
8485
}
8586

8687
type SBOM struct {
@@ -375,6 +376,7 @@ func (bc *Client) ReadEntrypoint(ctx context.Context, lang string, opts ...llb.L
375376
})
376377
if err == nil {
377378
bc.dockerignore = dt
379+
bc.dockerignoreName = bctx.filename + ".dockerignore"
378380
}
379381

380382
return &Source{
@@ -435,13 +437,14 @@ func (bc *Client) MainContext(ctx context.Context, opts ...llb.LocalOption) (*ll
435437
dt = []byte{}
436438
}
437439
bc.dockerignore = dt
440+
bc.dockerignoreName = DefaultDockerignoreName
438441
}
439442

440443
var excludes []string
441444
if len(bc.dockerignore) != 0 {
442445
excludes, err = dockerignore.ReadAll(bytes.NewBuffer(bc.dockerignore))
443446
if err != nil {
444-
return nil, errors.Wrap(err, "failed to parse dockerignore")
447+
return nil, errors.Wrapf(err, "failed parsing %s", bc.dockerignoreName)
445448
}
446449
}
447450

frontend/dockerui/namedcontext.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ func (bc *Client) namedContextRecursive(ctx context.Context, name string, nameWi
208208
if len(dt) != 0 {
209209
excludes, err = dockerignore.ReadAll(bytes.NewBuffer(dt))
210210
if err != nil {
211-
return nil, nil, err
211+
return nil, nil, errors.Wrapf(err, "failed parsing %s", DefaultDockerignoreName)
212212
}
213213
}
214214
}

0 commit comments

Comments
 (0)