Skip to content

Commit

Permalink
frontend/dockerfile/dockerignore: remove hard-coded filename from error
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
thaJeztah and jedevc committed Jul 26, 2023
1 parent d116081 commit 7eb2cea
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
4 changes: 1 addition & 3 deletions frontend/dockerfile/dockerignore/dockerignore.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (
"io"
"path/filepath"
"strings"

"github.com/pkg/errors"
)

// ReadAll reads an ignore file from a reader and returns the list of file
Expand Down Expand Up @@ -69,7 +67,7 @@ func ReadAll(reader io.Reader) ([]string, error) {
excludes = append(excludes, pattern)
}
if err := scanner.Err(); err != nil {
return nil, errors.Wrap(err, "error reading .dockerignore")
return nil, err
}
return excludes, nil
}
7 changes: 5 additions & 2 deletions frontend/dockerui/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ type Client struct {
g flightcontrol.Group[*buildContext]
bopts client.BuildOpts

dockerignore []byte
dockerignore []byte
dockerignoreName string
}

type SBOM struct {
Expand Down Expand Up @@ -375,6 +376,7 @@ func (bc *Client) ReadEntrypoint(ctx context.Context, lang string, opts ...llb.L
})
if err == nil {
bc.dockerignore = dt
bc.dockerignoreName = bctx.filename + ".dockerignore"
}

return &Source{
Expand Down Expand Up @@ -435,13 +437,14 @@ func (bc *Client) MainContext(ctx context.Context, opts ...llb.LocalOption) (*ll
dt = []byte{}
}
bc.dockerignore = dt
bc.dockerignoreName = DefaultDockerignoreName
}

var excludes []string
if len(bc.dockerignore) != 0 {
excludes, err = dockerignore.ReadAll(bytes.NewBuffer(bc.dockerignore))
if err != nil {
return nil, errors.Wrap(err, "failed to parse dockerignore")
return nil, errors.Wrapf(err, "failed parsing %s", bc.dockerignoreName)
}
}

Expand Down
2 changes: 1 addition & 1 deletion frontend/dockerui/namedcontext.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ func (bc *Client) namedContextRecursive(ctx context.Context, name string, nameWi
if len(dt) != 0 {
excludes, err = dockerignore.ReadAll(bytes.NewBuffer(dt))
if err != nil {
return nil, nil, err
return nil, nil, errors.Wrapf(err, "failed parsing %s", DefaultDockerignoreName)
}
}
}
Expand Down

0 comments on commit 7eb2cea

Please sign in to comment.