Fix broken artifact path matching#126
Open
refi64 wants to merge 1 commit into
Open
Conversation
Collaborator
|
Is it broken or do you mean it didn't match gitlab's runner behaviour? If the former can you point to the commit that introduced the brokeness. In the latter case apart from the bits you documented is this change the behaviour of the runner in other ways that might impact users? |
Older versions of gitlab-runner did not filter uploaded artifacts at all, regardless of the value of `artifacts` the user gave. Despite this, several downstreams (most notably places where obs-gitlab-runner is used) would specify the artifacts there anyway, with the usual syntax/semantics that gitlab-runner uses, for consistency and as a "safety" for when this would later be implemented. In commit eccfdbc, artifact filtering was added, by treating `artifacts` entries as glob patterns and matching them against the artifact paths the runner instances proposed. However, gitlab-runner itself instead uses doublestar to traverse the current tree for artifacts, which has a few notable implications: - Paths are normalized first with filepath.Clean & filepath.ToSlash: https://github.com/bmatcuk/doublestar/blob/a9ad9e0ef4d6b7e4443090e9a7201d847a881711/utils.go#L74-L80 So `file` and `./file//` are both the same pattern. (We don't care too much about ToSlash for now, since that should only have an effect for the Windows path separator). - If a pattern matches a directory, the full subtree is added to the archive. - Wildcards `*` and `?` retain the usual filesystem-level semantics of not crossing path components. All of these behaviors were "broken" with the move to glob matches, which will only do an exact match on the full artifact path with the default glob options (`require_literal_separator: false`). To fix this, both the declared artifact path and UploadableFile's path (for consistency) are normalized, and then the patterns are matched on successive ancestors of the current path, while telling `glob` that it needs to give the `/` special treatment. Technically this leaves some other gitlab-runner behavior on the table, such as support for brace expansion, or the aforementioned Windows separator support, or handling absolute paths: https://gitlab.com/gitlab-org/gitlab-runner/-/blob/fc6a8943d99928a9d293186be03674c333fd09fa/commands/helpers/file_archiver.go#L191 But that's all leaning more towards fringe functionality that we probably don't care about here (at least not for now).
1bfd08f to
7013664
Compare
Collaborator
Author
|
I updated the commit message / PR body. I guess strictly speaking, it's not "broken" in that before we weren't doing any filtering at all, but I'd argue it's still "broken" in that we have a bunch of consumers of the runner (e.g. ci-package-builder) that actually give "correct" values for |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Older versions of gitlab-runner did not filter uploaded artifacts at all, regardless of the value of
artifactsthe user gave. Despite this, several downstreams (most notably places where obs-gitlab-runner is used) would specify the artifacts there anyway, with the usual syntax/semantics that gitlab-runner uses, for consistency and as a "safety" for when this would later be implemented.In commit eccfdbc, artifact filtering was added, by treating
artifactsentries as glob patterns and matching them against the artifact paths the runner instances proposed. However, gitlab-runner itself instead uses doublestar to traverse the current tree for artifacts, which has a few notable implications:Paths are normalized first with filepath.Clean & filepath.ToSlash:
https://github.com/bmatcuk/doublestar/blob/a9ad9e0ef4d6b7e4443090e9a7201d847a881711/utils.go#L74-L80
So
fileand./file//are both the same pattern. (We don't care too much about ToSlash for now, since that should only have an effect for the Windows path separator).If a pattern matches a directory, the full subtree is added to the archive.
Wildcards
*and?retain the usual filesystem-level semantics of not crossing path components.All of these behaviors were broken with the move to glob matches, which will only do an exact match on the full artifact path with the default glob options (
require_literal_separator: false).To fix this, both the declared artifact path and UploadableFile's path (for consistency) are normalized, and then the patterns are matched on successive ancestors of the current path, while telling
globthat it needs to give the/special treatment.Technically this leaves some other gitlab-runner behavior on the table, such as support for brace expansion, or the aforementioned Windows separator support, or handling absolute paths:
https://gitlab.com/gitlab-org/gitlab-runner/-/blob/fc6a8943d99928a9d293186be03674c333fd09fa/commands/helpers/file_archiver.go#L191
But that's all leaning more towards fringe functionality that we probably don't care about here (at least not for now).