Is there an existing issue for this?
Kubernetes Version
v1.32.2 (kind) and OpenShift on ROSA
Shipwright Version
Builds for OpenShift 1.9.0, and upstream Shipwright on kind. shp built from main @ a45e1612, and from #409.
Current Behavior
shp build upload checks each file against the .gitignore in the source folder. It passes the file's full path on disk to MatchesPath, for example /home/me/work/src/app/main.go. It should pass the path inside the source folder, main.go. This causes two problems.
- A pattern that matches a parent folder drops every file. With
src/ in .gitignore and the project at .../src/app, the upload is empty. The build then fails with DockerfileNotFound.
- Patterns that start with
/ never match. /build and /dist should leave out those two top-level folders, but both are uploaded.
Expected Behavior
Patterns match the way git matches them, against the path relative to the folder that holds the .gitignore. src/ doesn't match anything above the source folder. /build leaves out build/ at the top, but keeps sub/build/.
Steps To Reproduce
- Create a Build with
source.type: Local and the buildah strategy.
- Create a project at
/tmp/src/app, with a Dockerfile and a .gitignore that contains src/.
- Run
shp build upload <build> /tmp/src/app --follow.
- The build fails with
DockerfileNotFound, because no files were uploaded.
To see the second problem, put /build in .gitignore and add a build/ folder. Its files appear in the build.
Anything else?
The fix is to pass the relative path to MatchesPath. #409 already computes it in skipPath.
relPath, err := filepath.Rel(t.src, fpath)
if err != nil {
return false
}
relPath = filepath.ToSlash(relPath)
if strings.Contains("/"+relPath+"/", "/.git/") {
return true
}
return t.gitIgnore != nil && t.gitIgnore.MatchesPath(relPath)
I tested this on OpenShift and on kind, with buildah and kaniko. Both problems went away, and sub/build/ was still uploaded. I can open a PR once #409 is merged.
Is there an existing issue for this?
Kubernetes Version
v1.32.2 (kind) and OpenShift on ROSA
Shipwright Version
Builds for OpenShift 1.9.0, and upstream Shipwright on kind.
shpbuilt frommain@a45e1612, and from #409.Current Behavior
shp build uploadchecks each file against the.gitignorein the source folder. It passes the file's full path on disk toMatchesPath, for example/home/me/work/src/app/main.go. It should pass the path inside the source folder,main.go. This causes two problems.src/in.gitignoreand the project at.../src/app, the upload is empty. The build then fails withDockerfileNotFound./never match./buildand/distshould leave out those two top-level folders, but both are uploaded.Expected Behavior
Patterns match the way
gitmatches them, against the path relative to the folder that holds the.gitignore.src/doesn't match anything above the source folder./buildleaves outbuild/at the top, but keepssub/build/.Steps To Reproduce
source.type: Localand thebuildahstrategy./tmp/src/app, with aDockerfileand a.gitignorethat containssrc/.shp build upload <build> /tmp/src/app --follow.DockerfileNotFound, because no files were uploaded.To see the second problem, put
/buildin.gitignoreand add abuild/folder. Its files appear in the build.Anything else?
The fix is to pass the relative path to
MatchesPath. #409 already computes it inskipPath.I tested this on OpenShift and on kind, with
buildahandkaniko. Both problems went away, andsub/build/was still uploaded. I can open a PR once #409 is merged.