From 7765100b8dfaa5cd63fc6b50b508aa96e37960e6 Mon Sep 17 00:00:00 2001 From: Daniel J Walsh Date: Thu, 7 Oct 2021 09:10:22 -0400 Subject: [PATCH] Report ignorefile location when no content added 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: https://github.com/containers/buildah/issues/3318 Signed-off-by: Daniel J Walsh --- add.go | 12 +++++++++++- tests/bud.bats | 1 + 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/add.go b/add.go index f17e3a9c943..24efdb566a4 100644 --- a/add.go +++ b/add.go @@ -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 diff --git a/tests/bud.bats b/tests/bud.bats index 9f379b8b336..971d0d88cd8 100644 --- a/tests/bud.bats +++ b/tests/bud.bats @@ -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" {