#feat: add contextual git by jedevc · Pul...
1 messages · Page 1 of 1 (latest)
Re-reading https://github.com/dagger/dagger/issues/7647
Summarized it here https://github.com/dagger/dagger/pull/10847#issuecomment-3200001174
So, I see a few options appearing more clearly..
- We follow the path of least resistance, and add
+defaultGit,+defaultContainer, etc
- We keep the same system, but expand the semantic scope to include all address-loadable objects. eg.
+defaultObjector+defaultAddress? Then use that to supportGitRef,GitRepository,Directory,File,Container,Secretall in one fell swoop
defaultAddress would work nicely imo, though I don't love the naming 🤔
no better ideas tho lol 😆
- We make a more ambitious change, and allow Python and Typescript native default arguments in 100% of cases, using the new
address()API. eg.func foo(source = dag.address(".").directory()). Then Go can get+default🙂
mm 🤔 problem is this is now blocked until tom and helder are back
I like 3 - but can't speak with enough authority on how possible that is
(it also wont work for java fyi)
ahahaha I was about to say :p
@rotund cloud you have some decent context on the SDKs, maybe you have a gut feeling on feasibility?
um, do we wanna unblock this feature and go with path of least resistance? it's not effort to keep supporting even if we go to another route later
given that this discussion needs a bit of a time I think
i really want to use this to give us a big speed boost in our version module
@ornate turtle as a stopgap, how would you feel about allowing +defaultPath to apply to GitRef and GitRepository? That way we don't cross any one-way doors on the API side
mmmmmm not my favorite honestly 🤔 it's still a bit of a one way door, cause we'll need to support that syntax indefinitely
And conceptually it's aligned with option 2 (minus the rename)
Well we're stuck with +defaultPath anyway...
yeah if it's a choice between those two options, we should just delay until we get consensus
We support remote git & local paths in all sorts of places. dagger -m, .cd...
I don't want to overload the option we purposefully narrowed
Well we narrowed it to exclude scalar values. At the time we didn't even think of other objects (which was an omission)
So it's not reverting a past decision - more like addressing a blind spot of the original decision
yeah, so 🙂 it's not actually a "true" path.
it can be a url to a remote git, or it can be the "contextual" path, "/" or "."
it could be opened up to be an arbitrary path to a git repo... in a git repo which is the module? but i felt like that case is suitably bizarre, i wanna wait for someone to ask for it
Oh right, you're saying even today, I could do +defaultPath="https://github.com/dagger/dagger#main:docs" and it would work for a Directory type?
But as a user I would expect defaultPath= to work that way today, to be consistent with our CLI
fair, if only there was a pr that was working to resolve that 😛
There is?
isn't that what address is all about
i guess if that's the future we're going for
i'm okay with overloading defaultPath
My point is, even before expanding past Directory and File, I think there's a very strong argument that +defaultPath can naturally support git paths, and users won't be surprised or unhappy.
but we would have a temporary inconsistency
(since we set the precedent that directories can be loaded from git addresses)
yeah okay, that's fair to me, i'm happy with that compromise
How about this:
- We quietly expand
defaultPathto support all address-loadable object types - Later we find a better alternative to
defaultPath(either option A or B below ) and soft-deprecate it - Developers slowly adopt the better alternative. We probably continue supporting
defaultPath, even deprecated, for a long time (if only in compat mode)
Possible alternatives to +defaultPath:
-
Option A: semantic change only. Rename
+defaultPathto+defaultAddress,+defaultObject,+defaultRef, or another name that makes it clear all address-loadable object types are supported. -
Option B: Python and Typescript always use native default arguments, using the new address() API. eg.
func foo(source = dag.address(".").directory()). In Go, rename+defaultPathto+default
i would say we can expand but only for path-like things
e.g. we shouldn't support it for things that aren't paths, we should just wait to add those until we have a better option
shouldn't be an issue, i can't think of any of those off the top of my head we want to add (rn)
@eager pasture any other comments r.e. that pr? will probably context switch back to it today, but wanna make sure i get as much fixed as possible
Why not something like defaultRef (regarding naming of defaultAdress or other alternatives)? A reference can be local, remote, a directory or git, etc
This might sound a little bit less obvious for a local path, but if it encapsulates multiple types (dir, file, git, etc) and multiple provenances that might cover it
Yeah that's a variation of option A. I added ref as an option in the summary above
What we're also curious about @rotund cloud is "option B" which would be more ambitious (not just a rename of the pragma):
Python and Typescript always use native default arguments, using the new address() API. eg. func foo(source = dag.address(".").directory()). In Go, rename +defaultPath to +default
Last year that seemed to be difficult, because of engine and SDK internals, but it was seriously considered. Maybe now it's easier?
One big difference is that now (with the address() PR) there already is an API to call
@ornate turtle back to the PR, why go through defaultGit in the first place, instead of eg. dag.CurrentModule().GitRepository() ?
aha
Not that I'm not enjoying the rabbit hole conversation that led to 🙂
blueprints 😄
if i write a blueprint, then i want to get the git repository of the "app" usually
i guess we should probably support both actually 😄 not hard to do that
What about getting a source directory, and just calling asGit? Didn't you already add that?
you can do this - but for a remote ref, the default depth is set to 1 (for efficiency, it's bad to clone the entire history just to get the code for the module)
so, the asGit result would just be a single commit, which is why we have so much hackery in the version module in the first place
i did consider just cloning everything to max depth for a directory, but it's a crap experience
I remember part of the motivation was to query relatively "small" metadata about the repo without having to download tons of data
yup, that's pretty much it - you can very easily query a lot of the history, and for a lot of operations, it's going to be very quick, because those operations are cached because we've needed to do them to run the module code in the first place
Ironically that original issue is phrased as "git information about the context" which is not ambiguous even with blueprints
I think I don't know enough about py/ts SDKs to say something here. When I'm reading func foo(source = dag.address(".").directory()) I feel that makes sense, but hard to say more, especially I don't know what were the previous limitations.
From Java SDK pov, to rename defaultPath to default (and add more types there) sounds ok. We already have some code that handles differently the default value (because of some nice things like enums...) So we should be able to extend it to handle directories, files, git, etc.
having to switch to asGit means you've done ModuleSource -> Git -> Directory -> Git, and that's both somewhat lossy, and sad
dag.context().git()? 🙂
Yeah I know there were questions around caching, and maybe runtime vs. buildtime introspection?
yeahhhh? i mean the reason we didn't do this for directories is because that's bad for cache.
we need it to be in the schema somehow, so that we know when changes occur we can invalidate the cache
i remember a very long discussion about this before, i'm forgetting the finer points
personally, i think the contextual args is a neat solution (it also lets you override them!), i think it makes sense to extend it here
Yes that makes sense. I guess the reason it feels slightly sad in this particular case, is that all I want is to query a few basic fields about the current git context. Like "what's the current tag", "am I in a dirty commit". And although the default arg system is powerful and cool... it's complicated
Meahwhile a github actions workflow can go if [ $$GITHUB_BRANCH ] or whatever
"am in a dirty commit" hell, yeah, i know, i want that api so badly
i tried, it's such a mess
You know what I mean though, maybe dirty commit is particulary hard to implement
yeah yeah 🙂
but it feels different from contextual directories because it's much less open-ended
feels more like dag.CurrentModule().Source()
But maybe I'm just describing a different API, which could be smaller and layered on top of your PR as a convenience
yeahhh
Since I wouldn't need the full power of GitRepository or even GitRef
just a bunch of scalars
i think i'd like dag.CurrentModule().Git() which does the same as source (gets the source, not the blueprinted version)
and also defaultGit
maybe one day, we could think about dag.context()? i don't know how we'd do the cache but i have some ideas with theseus
e.g. we could configure the cache key post operation based on what you loaded
What does dag.CurrentModule() return today when running from a blueprint?
it gives you the upstream source (the platform, not the app)
so the blueprint module
yeahh
that makes sense to me
sorry, not the "blueprinter?"
hehe
okay, i'll rework the pr:
- add
CurrentModule.Git - change to use
defaultPathfor now
But, won't CurrentModule.Git return the blueprint's git information, instead of the downstream module's which you want?
yeah! but if you want the downstream version, you use contextual defaultGit
just like you do with defaultPath
@ornate turtle if I want to know if I'm in a tag, or a branch, or neither, can I do that with CurrentModule.Git?
Just checking that we cover the basic CI use cases
you can use Git.ref, which gives you the fully resolved ref. dagger -c 'git https://github.com/dagger/dagger.git | branch main | ref' gives you refs/heads/main
so refs/tag is tags, refs/head is branches
we can obviously add more helpers
i love the git type. honestly, just my favorite thing to work on.
i wanna add a way to author new commits (maybe using the patch api we recently added)
and then, being able to push would be awesome
My dream is to wire it to the CLI flow somehow, so that I can open a remote branch, go through a complete devloop completely stateless, and when I exit, all the changes get saved to a pre-arranged cow branch