diff --git a/initrd/detect.go b/initrd/detect.go index acfac0df5..a94281261 100644 --- a/initrd/detect.go +++ b/initrd/detect.go @@ -12,11 +12,11 @@ import ( // New attempts to return the builder for a supplied path which // will allow the provided ... func New(ctx context.Context, path string, opts ...InitrdOption) (Initrd, error) { - if builder, err := NewFromFile(ctx, path, opts...); err == nil { + if builder, err := NewFromDockerfile(ctx, path, opts...); err == nil { return builder, nil - } else if builder, err := NewFromDirectory(ctx, path, opts...); err == nil { + } else if builder, err := NewFromFile(ctx, path, opts...); err == nil { return builder, nil - } else if builder, err := NewFromDockerfile(ctx, path, opts...); err == nil { + } else if builder, err := NewFromDirectory(ctx, path, opts...); err == nil { return builder, nil } else if builder, err := NewFromOCIImage(ctx, path, opts...); err == nil { return builder, nil diff --git a/initrd/dockerfile.go b/initrd/dockerfile.go index 10f1a362e..6b888f454 100644 --- a/initrd/dockerfile.go +++ b/initrd/dockerfile.go @@ -178,6 +178,13 @@ func NewFromDockerfile(ctx context.Context, path string, opts ...InitrdOption) ( return nil, fmt.Errorf("file is not a Dockerfile") } + fi, err := os.Stat(path) + if err != nil { + return nil, fmt.Errorf("could not check Dockerfile: %w", err) + } else if fi.IsDir() { + return nil, fmt.Errorf("supplied path %s is a directory not a Dockerfile", path) + } + initrd := dockerfile{ opts: InitrdOptions{ workdir: filepath.Dir(path),