diff --git a/cmd/podman/images/build.go b/cmd/podman/images/build.go index 8ae93e86a8..5c925406b0 100644 --- a/cmd/podman/images/build.go +++ b/cmd/podman/images/build.go @@ -8,6 +8,7 @@ import ( "os/exec" "path/filepath" "strings" + "syscall" "time" buildahDefine "github.com/containers/buildah/define" @@ -281,10 +282,19 @@ func build(cmd *cobra.Command, args []string) error { return fmt.Errorf("context must be a directory: %q", contextDir) } if len(containerFiles) == 0 { - if utils.FileExists(filepath.Join(contextDir, "Containerfile")) { + switch { + case utils.FileExists(filepath.Join(contextDir, "Containerfile")): + if utils.IsDir(filepath.Join(contextDir, "Containerfile")) { + return fmt.Errorf("containerfile: cannot be path or directory") + } containerFiles = append(containerFiles, filepath.Join(contextDir, "Containerfile")) - } else { + case utils.FileExists(filepath.Join(contextDir, "Dockerfile")): + if utils.IsDir(filepath.Join(contextDir, "Dockerfile")) { + return fmt.Errorf("dockerfile: cannot be path or directory") + } containerFiles = append(containerFiles, filepath.Join(contextDir, "Dockerfile")) + default: + return fmt.Errorf("no Containerfile or Dockerfile specified or found in context directory, %s: %w", contextDir, syscall.ENOENT) } } diff --git a/test/buildah-bud/apply-podman-deltas b/test/buildah-bud/apply-podman-deltas index bf51369b9a..13ceed6638 100755 --- a/test/buildah-bud/apply-podman-deltas +++ b/test/buildah-bud/apply-podman-deltas @@ -143,7 +143,7 @@ errmsg "no such file or directory" \ "bud without any arguments should fail when no Dockerfile exists" errmsg "is not a file" \ - "Error: containerfile: .* cannot be path to a directory" \ + "Error: no Containerfile or Dockerfile specified or found in context directory" \ "bud with specified context should fail if assumed Dockerfile is a directory" errmsg "no such file or directory" \ diff --git a/test/system/070-build.bats b/test/system/070-build.bats index 728b5ba7bd..72c6a82c3d 100644 --- a/test/system/070-build.bats +++ b/test/system/070-build.bats @@ -660,8 +660,7 @@ EOF mv $tmpdir/Dockerfile $tmpdir/foofile run_podman 125 build -t build_test $tmpdir - is "$output" ".*Dockerfile: no such file or directory" - + is "$output" "Error: no Containerfile or Dockerfile specified or found in context directory, $tmpdir: no such file or directory" run_podman build -t build_test -f $tmpdir/foofile $tmpdir # Clean up