Check on client side for Containerfile, if none specified

Fixes: https://github.com/containers/podman/issues/16354

Currently we check on the server side, which ends up generating a bad
error message.

$ podman --remote build foo/
ERRO[0000] While reading directory /home/dwalsh/go/src/github.com/containers/podman/foo: EOF
Error: stat /var/tmp/libpod_builder1249622306/build/Dockerfile: no such file or directory

With this change you will get

./bin/podman --remote build foo/
Error: Containerfile not specified and no Containerfile or Dockerfile found in context directory, /home/dwalsh/podman/foo

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
This commit is contained in:
Daniel J Walsh
2023-05-07 07:13:20 -04:00
parent a330974c73
commit 332b47fefb
3 changed files with 14 additions and 5 deletions

View File

@ -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)
}
}

View File

@ -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" \

View File

@ -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