You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I propose setting the following design principle for our CUE APIs:
Dagger CUE APIs should define default values explicitly, rather than relying on implied default values from other APIs they depend on.
For example, our CUE bindings to Buildkit calls should explicitly define default values in CUE, rather than rely on Buildkit’s own defaults.
This CUE-first approach to default values improves the developer experience in several ways:
It makes our CUE APIs more explicit
It improves API documentation, since the defaults can be captured by our docs generation tools
API authors can take fuller responsibility for the stability of their API, instead of depending on the stability of dependencies outside of their control.
Working on #1247, it became clear that trying to set defaults in docker.#Run, on top of engine.#Exec doesn't work.
In discord, I proposed setting defaults for tasks in the Go code that handles them. That would free abstractions in CUE to set their defaults differently from engine tasks.
Yeah combining defaults from multiple layers is an issue in CUE in general
My thinking is:
Ideally we could handle this in pure CUE. I consider it a limitation in the language that we can’t.
I think it’s fine to implement a workaround where we do this in Go. But it should be explained as such. Perhaps with FIXMEs etc. so we don’t lose track of the fact that, in a perfect world, it would be in CUE
We open an issue to track this particular problem, and keep it open so we can share it with upstream CUE devs, in the hope that down the road they provide a solution in the language to remove the workaround
I've looked around and this is what Marcel has to say:
This touches upon a fundamental aspect and design goals of CUE, namely that one should avoid having more than one level of inheritance at all cost, as this is one of the key reasons why configuration becomes unmanageable. Default values are a form of inheritance. As such CUE is particularly restrictive there.
[...]
Rather than fixing this by changing the language, it will be mostly a matter of education of patterns. Generally it is good practice for base schema definitions to not have defaults. Instead, defaults can be defined in a separate value that can be "composed in" as needed.
You can essentially remove a default by making it evaluate to _|_, but in this case you have other things to consider as well.
Sometimes though, I feel that we try to do too much in CUE which is stretching the language beyond it's design philosophy.
In light of all this, I still think the cleaner solution is to set task defaults in Go code, but not as a temporary workaround. In CUE, you can document the field ending in something like // ... (defaults to "root").
I agree, and in setting those defaults we should prefer *<value> | <type> rather than using if {} statements wherever possible since they are more easily documented and gleened.
I agree with moving task defaults to Go, as a practical matter
I do think this will become a problem for CUE developers as the ecosystem grows, because it basically means package developers cannot safely set defaults in their package unless they are 100% sure that their package will not be wrapped in a higher-level package that will want to set their own default. But, it’s often impossible to know that for sure.
TLDR I don’t know what the new defaults policy should be for package developers. What’s the rule?
In the case of #ImageConfig though, you're not guaranteed to to have User in there, so setting exec's defaults in Go is still the best option here.
But this is essentially what I'm doing in my compose.yaml generation use case, and in that case I don't think it's ugly 😁 It feels natural to be composing in this way.
Example:
Php: {
// no defaults here
}
_PhpLegacy: Php& {
// also no defaults here
}
Php56: _PhpLegacy& {
// now we're talkingservices: app: image: string|*"<full ref here>"
}
Php74: Php& {
services: app: image: string|*"<full ref here>"
}
_Bolt: Php56& {
services: {
// end of the line for you!web: image: "<full ref here>"
}
}
app1: Php56& {
...
}
app2: _Bolt&lib.Msmtp& {
// here's an smtp mixin for you
}
Point is, I'm deciding when I'm introducing defaults based on my needs. If I'd need to base something else on top of _Bolt, I'd have to change that. But whenever you introduce it for others, you're limiting them. Unless you provide a base to extend, with accompanying mixins to compose (or not), and perhaps a case for most common use (e.g., #Run).
My initial proposal is out of date, because it didn't account for the limitations in how CUE handles default values. This issue is addressed in #857 (point 10). Closing this since it's not immediately actionable.
Activity
aluzzardi commentedon Jan 7, 2022
Makes sense to me. @jlongtine @talentedmrjones ?
@shykes Would it make sense to start a document in the repo to encode such policies?
shykes commentedon Jan 10, 2022
Yes agreed. I will take this and combine with #1360.
helderco commentedon Jan 20, 2022
Working on #1247, it became clear that trying to set defaults in
docker.#Run, on top ofengine.#Execdoesn't work.In discord, I proposed setting defaults for tasks in the Go code that handles them. That would free abstractions in CUE to set their defaults differently from engine tasks.
@shykes replied:
I've looked around and this is what Marcel has to say:
Originally posted by @mpvl in cue-lang/cue#1449 (comment)
I do have a workaround in CUE though:
You can essentially remove a default by making it evaluate to
_|_, but in this case you have other things to consider as well.Sometimes though, I feel that we try to do too much in CUE which is stretching the language beyond it's design philosophy.
In light of all this, I still think the cleaner solution is to set task defaults in Go code, but not as a temporary workaround. In CUE, you can document the field ending in something like
// ... (defaults to "root")./cc @jlongtine
talentedmrjones commentedon Jan 20, 2022
I agree, and in setting those defaults we should prefer
*<value> | <type>rather than usingif {}statements wherever possible since they are more easily documented and gleened.helderco commentedon Jan 20, 2022
@talentedmrjones Yes, that would become possible if
#Execdoesn't have a default in CUE:shykes commentedon Jan 21, 2022
helderco commentedon Jan 21, 2022
CUE's recommendation is to not have defaults and compose with unification. The issue is that it looks a bit ugly (or the DX is less great)? 😅
In the case of
#ImageConfigthough, you're not guaranteed to to haveUserin there, so setting exec's defaults in Go is still the best option here.But this is essentially what I'm doing in my
compose.yamlgeneration use case, and in that case I don't think it's ugly 😁 It feels natural to be composing in this way.Example:
Point is, I'm deciding when I'm introducing defaults based on my needs. If I'd need to base something else on top of
_Bolt, I'd have to change that. But whenever you introduce it for others, you're limiting them. Unless you provide a base to extend, with accompanying mixins to compose (or not), and perhaps a case for most common use (e.g.,#Run).aluzzardi commentedon Jan 31, 2022
Rolled over into the next milestone
shykes commentedon Feb 11, 2022
My initial proposal is out of date, because it didn't account for the limitations in how CUE handles default values. This issue is addressed in #857 (point 10). Closing this since it's not immediately actionable.