Skip to content

[BUG] shp build upload matches .gitignore patterns against the full path on disk #417

Description

@psrvere

Is there an existing issue for this?

  • I have searched the existing issues

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.

  1. 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.
  2. 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

  1. Create a Build with source.type: Local and the buildah strategy.
  2. Create a project at /tmp/src/app, with a Dockerfile and a .gitignore that contains src/.
  3. Run shp build upload <build> /tmp/src/app --follow.
  4. 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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    • Status
      No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions