Skip to content

Commit

Permalink
fix(initrd): Ensure proper ordering and checks of (docker)files (#1964)
Browse files Browse the repository at this point in the history
Reviewed-by: Cezar Craciunoiu <[email protected]>
Approved-by: Cezar Craciunoiu <[email protected]>
  • Loading branch information
craciunoiuc authored Nov 19, 2024
2 parents 442234b + 0f92d3a commit b918178
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 3 additions & 3 deletions initrd/detect.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions initrd/dockerfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit b918178

Please sign in to comment.