Skip to content

Commit

Permalink
Report ignorefile location when no content added
Browse files Browse the repository at this point in the history
Users have accidently had a .containerignore or .dockerignore
file in their context directly which blocked all content.
Currently we report that no globs matched, but do not
identify where the globs came from.

This change is an attempt to add this data to the error.
Example: #3318

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
  • Loading branch information
rhatdan committed Oct 7, 2021
1 parent 211972a commit 7765100
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
12 changes: 11 additions & 1 deletion add.go
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,17 @@ func (b *Builder) Add(destination string, extract bool, options AddAndCopyOption
}
}
if itemsCopied == 0 {
return errors.Wrapf(syscall.ENOENT, "no items matching glob %q copied (%d filtered out)", localSourceStat.Glob, len(localSourceStat.Globbed))
ignoreFile := filepath.Join(contextDir, ".containerignore")
if _, err := os.Stat(ignoreFile); err != nil {
ignoreFile = filepath.Join(contextDir, ".dockerignore")
if _, err := os.Stat(ignoreFile); err != nil {
ignoreFile = ""
}
}
if ignoreFile != "" {
ignoreFile = " using " + ignoreFile
}
return errors.Wrapf(syscall.ENOENT, "no items matching glob %q copied (%d filtered out%s)", localSourceStat.Glob, len(localSourceStat.Globbed), ignoreFile)
}
}
return nil
Expand Down
1 change: 1 addition & 0 deletions tests/bud.bats
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ symlink(subdir)"
@test "bud with .dockerignore #2" {
run_buildah 125 build -t testbud3 --signature-policy ${TESTSDIR}/policy.json ${TESTSDIR}/bud/dockerignore3
expect_output --substring 'error building.*"COPY test1.txt /upload/test1.txt".*no such file or directory'
expect_output --substring "${TESTSDIR}/bud/dockerignore3/.dockerignore"
}

@test "bud-flags-order-verification" {
Expand Down

0 comments on commit 7765100

Please sign in to comment.