Skip to content

Commit

Permalink
Fix image build for relative paths. (#83)
Browse files Browse the repository at this point in the history
Fix #73 

* LocateRoot needs to only operate on absolute paths
* Path the absolute path to LocateRoot in the image reconciler; don't
use the relative path.
  • Loading branch information
jlewi authored Mar 27, 2024
1 parent 2d35fa0 commit 145eb1d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 8 additions & 1 deletion pkg/gitutil/gitutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,14 @@ import (

// LocateRoot locates the root of the git repository at path.
// Returns empty string if not a git repo.
func LocateRoot(path string) (string, error) {
func LocateRoot(origPath string) (string, error) {
// If we don't get the absolute path then for a relative path such as "image.yaml" we end up returning "." as the
// dir and the loop never terminates
path, err := filepath.Abs(origPath)
if err != nil {
return "", errors.Wrapf(err, "Could not locate git root for %v because the absolute path could not be obtained", origPath)

}
fInfo, err := os.Stat(path)
if err != nil {
return "", errors.Wrapf(err, "Error stating path %v", path)
Expand Down
2 changes: 1 addition & 1 deletion pkg/images/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ func ReconcileFile(path string) error {
return errors.Wrapf(err, "Failed to open file: %v", manifestPath)
}

gitRoot, err := gitutil.LocateRoot(path)
gitRoot, err := gitutil.LocateRoot(manifestPath)
if err != nil {
return errors.Wrapf(err, "Failed to locate git root for %v", path)
}
Expand Down

0 comments on commit 145eb1d

Please sign in to comment.