Skip to content

Commit

Permalink
Fix Containerfile/Dockerfile lookup to favor source files instead of …
Browse files Browse the repository at this point in the history
…spec files
  • Loading branch information
akclace committed Sep 23, 2024
1 parent b8aa732 commit 1968063
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 2 deletions.
17 changes: 15 additions & 2 deletions internal/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,13 +422,26 @@ func (a *App) loadContainerManager(stripAppPath bool) error {
var fileName string
switch src {
case types.CONTAINER_SOURCE_AUTO:
if _, cfErr := a.sourceFS.Stat(CONTAINERFILE); cfErr == nil {
// Look for a file in the source fs (ignoring spec). If not found,
// look in spec files also.
if _, err := a.sourceFS.StatNoSpec(CONTAINERFILE); err == nil {
fileName = CONTAINERFILE
} else {
if _, dErr := a.sourceFS.Stat(DOCKERFILE); dErr == nil {
if _, err := a.sourceFS.StatNoSpec(DOCKERFILE); err == nil {
fileName = DOCKERFILE
}
}

if fileName == "" {
// Containerfile/Dockerfile not found in source, check in spec files also
if _, err := a.sourceFS.Stat(CONTAINERFILE); err == nil {
fileName = CONTAINERFILE
} else {
if _, err := a.sourceFS.Stat(DOCKERFILE); err == nil {
fileName = DOCKERFILE
}
}
}
case types.CONTAINER_SOURCE_NIXPACKS:
return fmt.Errorf("nixpacks container source not supported yet")
default:
Expand Down
5 changes: 5 additions & 0 deletions internal/app/appfs/disk_fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ func (d *DiskReadFS) Stat(name string) (fs.FileInfo, error) {
return fi, err
}

func (d *DiskReadFS) StatNoSpec(name string) (fs.FileInfo, error) {
absName := d.makeAbsolute(name)
return os.Stat(absName)
}

func (d *DiskReadFS) Glob(pattern string) (matches []string, err error) {
// TODO glob does not look at spec files
return fs.Glob(d.fs, pattern)
Expand Down
1 change: 1 addition & 0 deletions internal/app/appfs/source_fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type ReadableFS interface {
fs.GlobFS
// Stat returns the stats for the named file.
Stat(name string) (fs.FileInfo, error)
StatNoSpec(name string) (fs.FileInfo, error) // Stat the FS without looking at spec files
Reset() // Used to reset the file system transaction for the DbFs, no-op for others
StaticFiles() []string // Return list of static files
FileHash(excludeGlob []string) (string, error) // Return a hash of the source file contents
Expand Down
4 changes: 4 additions & 0 deletions internal/app/tests/app_test_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,10 @@ func (f *TestReadFS) Stat(name string) (fs.FileInfo, error) {
return &TestFileInfo{file}, nil
}

func (f *TestReadFS) StatNoSpec(name string) (fs.FileInfo, error) {
return f.Stat(name)
}

func (d *TestReadFS) StaticFiles() []string {
staticFiles := []string{}
for name := range d.fileData {
Expand Down
8 changes: 8 additions & 0 deletions internal/metadata/dbfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,14 @@ func (d *DbFs) Stat(name string) (fs.FileInfo, error) {
return &fi, nil
}

func (d *DbFs) StatNoSpec(name string) (fs.FileInfo, error) {
fi, ok := d.fileInfo[name]
if !ok {
return nil, fs.ErrNotExist
}
return &fi, nil
}

func (d *DbFs) Glob(pattern string) (matches []string, err error) {
matchedFiles := []string{}
for name := range d.fileInfo {
Expand Down

0 comments on commit 1968063

Please sign in to comment.