Repository navigation
feat: lift git logic out of buildkit into dagop - #9980
Conversation
da9b927 to
eec4125
Compare
e0f1c1c to
a85e630
Compare
| if repo.URL.Host == "bitbucket.org" { | ||
| // NOTE: bitbucket.org is picky, and needs *this* username | ||
| username = "x-token-auth" | ||
| } |
There was a problem hiding this comment.
cc @grouville, this is a simplification of part of #8778 - it turns out, we don't need the whole credential helper here?
Anyways, just wanted to check that this bit seemed good to you, all our tests seem to pass correctly 🎉
| // TODO: this feels completely out-of-sync from how we do the rest | ||
| // of the clone - caching will not be as great here | ||
| _, err = checkoutGit.Run(ctx, "submodule", "update", "--init", "--recursive", "--depth=1") |
There was a problem hiding this comment.
Note to the reviewer: the TODOs in this PR are mostly intentional, they don't need to be done here, since they're not a regression from the existing behavior.
However, just marking them for future improvement.
| // also include what auth methods are used, currently we can't | ||
| // handle a cache hit where the result has a different auth | ||
| // method than the caller used (i.e. a git repo is pulled w/ | ||
| // a token but hits cache for a dir where a ssh sock was used) | ||
| strconv.FormatBool(ref.Repo.AuthToken.Self != nil), | ||
| strconv.FormatBool(ref.Repo.AuthHeader.Self != nil), | ||
| strconv.FormatBool(ref.Repo.SSHAuthSocket != nil), |
There was a problem hiding this comment.
@sipsma so I think this is right.
Instead of having this be on tree, I've moved it up to the ref selection - so it'll apply to every operation on a GitRef.
The reasoning being, we should have a content hash here, which means we should easily get the following behavior:
- Cache the results of
dag().git().ref()per session (which effectively means we only resolve each remote + ref combo once per session, similar to buildkit today). - And then when it's not cached between sessions, get a "content hashed" call, that includes the ref + commit + remote + etc. So we don't need to invoke the actual op multiple times when this is shared.
But would really love a bit of a closer inspection, just to make sure I'm definitely thinking about this right.
There was a problem hiding this comment.
Looks like this moved back to be in tree IIUC, curious if something came up that motivated the move back (or if I'm not following something)
There was a problem hiding this comment.
Uh yeah, I moved this back 🤔 I'm now slightly struggling to remember exactly why.
I think it was related to accidentally edge merging way earlier than we should be 🤔 but yes, ended up deciding to lift it up for now, just to entirely avoid that problem.
|
|
||
| // CachePerSession is a CacheKeyFunc that scopes the cache key to the session by mixing in the session ID to the original digest of the operation. | ||
| // It should be used when the operation should be run for each session, but not more than once for a given session. | ||
| func CachePerSession[P Typed, A any]( |
There was a problem hiding this comment.
Just thought this would be worth having? It wasn't useful until #9682, but with this, there should be a way to scope cache to just a session (so if two parallel sessions are running, that we won't share results).
Then this'll become more useful when we have true global function caching.
There was a problem hiding this comment.
Decided to start carving out a util directory - happy to reconsider and put it somewhere else, but IMO, it's just not clear what component should own this.
a85e630 to
b55b0fc
Compare
| svcs, err := ref.Repo.Query.Services(ctx) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to get services: %w", err) | ||
| } | ||
| detach, _, err := svcs.StartBindings(ctx, ref.Repo.Services) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| defer detach() |
There was a problem hiding this comment.
Heh, pretty happy with this - cc @vito
This lets us only spin up services when we're doing the operations that need them - if we don't do a git fetch, then we never need to access them.
8b3441c to
a40b064
Compare
a40b064 to
fe49377
Compare
Signed-off-by: Justin Chadwell <[email protected]>
Add some long-awaited enhancements to the CLI helper: - Integrate each `git` command with dagger telemetry for improved tracing - Skip all the weird retry logic, this isn't really needed (and if it is, we should implement it *way* better) - Add dagger-specific `GIT_ASKPASS=echo` And improve the URL parsing: - Don't store the `Remote` directly, but instead compute it on the fly: this allows for modifying properties, and getting the result out. Signed-off-by: Justin Chadwell <[email protected]>
Signed-off-by: Justin Chadwell <[email protected]>
Signed-off-by: Justin Chadwell <[email protected]>
Signed-off-by: Justin Chadwell <[email protected]>
Adds several features: - Allow specifying the depth to get a `GitRef.tree` at (defaults to 1) - Get the fully resolved ref string for a `GitRef` Signed-off-by: Justin Chadwell <[email protected]>
There was technically only *one* way to use this left - if you created a container, bound a service, and then built a dockerfile in that container. However, there are no tests for this. We've discussed deprecating `Container.build` for `Directory.dockerBuild` which has no such functionality. So I think it should be safe to remove, and assume that no one was using this. Signed-off-by: Justin Chadwell <[email protected]>
Signed-off-by: Justin Chadwell <[email protected]>
Signed-off-by: Justin Chadwell <[email protected]>
- Preserves shallow cloning behaviour - Ensure correct caching behavior for checkouts (we were accidentally early-merging refs in some cases) Signed-off-by: Justin Chadwell <[email protected]>
This is automatically added by all clients on connection - sipsma correctly pointed out we don't need this duplication. Signed-off-by: Justin Chadwell <[email protected]>
fe49377 to
c77b8b7
Compare
Fixes:
would clobber existing tag#9405--depthwhen usingdag.git#7637This PR lifts the implementation for
dag.Gitentirely out of buildkit, and into dagq; (using DagOp #9395). While in the area, I also modernized and refactored a lot of the cruft out - there's a lot of logic that handles ancient backwards compatibility case that we really just don't need to worry about. Potentially I've missed something that is actually required, but I'd prefer to accidentally remove it (and add it back later), than to keep holding on to legacy code that we don't understand the purpose of.Finally, we update the API with a couple small low-hanging features:
GitRef.refto get the fully resolved ref, likerefs/tags/xyz. This is useful so you can actually see what you're cloning - and we needed to use it internally, so it was easy to expose.GitRef.treenow takes adeptharg, which is very easy to add since we now own the entire backend.I've also forked
gitutilout of buildkit, we needed quite a few changes for this to work nicely in dagger. Some of these maybe could still be upstreamed at some point.