Repository navigation
Conversation
TomChv
left a comment
There was a problem hiding this comment.
You did an amazing works, it's really awesome!
Some hot reaction now, I think I'll need multiple read to get all the content.
Cache can now be configured using cue, specifically by setting a cache field under dagger.#Plan (sibling to client and actions).
That's really good but how we will handle new buildkit option? By adding a new field in cue?
It will make our core cue API having recurrent change, cannot we find a way more maintainable?
For instance, Buildkit can now export cache to s3, how would you support it in dagger? By adding another definition?
Though not put in the prototype yet as only GHA configs have been tested, it will now be possible to set registry credentials with #Secret now too. This means we have the flexibility to provide creds from anything: env vars, files, universe packages like the new 1password one, etc
That's exactly why I think we would not need CLI options anymore, those capabilities is 100% better (and secured) that flags.
Leave cache configuration as is; just bolt on ability to provide registry credentials through env vars
It's not a bad solution but we do not use the full power of Buildkit cache with it. More than that, it makes mandatory to run a sidecar registry to have cache, which can certainly be a limitation for some users.
Leave as is but solve through more advanced, long-term features
I think we should let time do his job, your proposal is already an amazing improvement and as you said, this concept of cache configuration directly from plan will certainly be reused for long term features.
There was a problem hiding this comment.
If our cue implementation is strong enough, I think it is no longer useful to keep those flag.
Cache management will be part of the plan as env input is now.
I think it's better to keep one source of truth (that one of the reason why we switched from dagger project with a values.yaml to dagger plan).
There was a problem hiding this comment.
Loading plan 2 times like this will not create logging issues and log duplication?
It's just a question, I'm not sure about this.
The cache configuration needs to be evaluated before any actions (as we have to provide it at the beginning of the buildkit session), but it may still require fields from client or even other imported packages (i.e. to get credentials)
It is not possible to evaluate both cache and client at the same time and let Buildkit/cue do the correct dependency arrangement of the DAG?
There was a problem hiding this comment.
Loading plan 2 times like this will not create logging issues and log duplication?
Yeah it does, that's one of the issues I mentioned in the description, I just accepted it for the proof-of-concept for now.
It is not possible to evaluate both cache and client at the same time and let Buildkit/cue do the correct dependency arrangement of the DAG?
Well that's what we do, we evaluate cache and client together first, then we evaluate the action and client together. What would be nice is if we could just evaluate all of them at the same time.
Part of the problem is that the action may not have an explicit reference to anything in cache, in which case cache will be ignored. I'm sure there's some cue magic I could do to overlay a forced dependency on cache or something to solve this.
The other part of the problem though is that we have to specify the cache settings when we start the buildkit session. The only clean fix I can think of here is to add upstream support for specifying cache imports/exports to the gateway api, but that's obviously something that will take a while. In the short-term I can't really think of any clean way of fixing this besides the approach here of constructing the session twice. I'll think about it more though and am open to suggestions of course.
There was a problem hiding this comment.
You could put all those definition in a cache.cue file :D
There was a problem hiding this comment.
Agreed, put them here for convenience right now but there should be a separate package for this
There was a problem hiding this comment.
This is already done in ParseImportCache and ParseExportCache functions of buildkit with loadGitHubEnv so I'm not even sure you need this function.
There was a problem hiding this comment.
Those functions in buildctl have some behavior we don't want (like writing logs and including error messages that refer to buildctl flags), so I don't think we should use them. Either way, on revisiting this TODO I think we should probably deprecate this behavior just so we can keep everything in cue and thus simple.
There was a problem hiding this comment.
Is it a typo or just to avoid conflict with type? You could name it exportType too?
There was a problem hiding this comment.
That would be better to put case function into sub function for clarity
|
Thanks @TomChv !
Yep exactly, we can just add the new cache config type to the disjunctions in
Agreed, I wasn't sure where we stood on the backwards-compat concerns here. I'll see what others think too but agree that getting rid of those options results in the cleanest end state. |
|
Haven't looked at the overall structure/design yet, but wanted to share a bit of info which I think will help:
We actually ran into this same exact issue for local directories and came up with a solution:
So basically by renaming the Line 184 in fd1393e That being said, while I'm typing this I realize this doesn't help with the second part of your statement, may still require fields from client or even other imported packages (i.e. to get credentials). I believe @helderco ran into a similar issue with |
|
Open question: This effectively makes the cache configuration declarative from within the plan. If I look at Basically the open question is: Isn't the cache configuration environment dependent, and what happens when multiple environments share the same configuration? |
The draft here does hardcode the use of GHA in
Overall, I guess the point is that when configuration is environment dependent, we can now use cue to control that behavior, which I think is preferable to the other method which is to have users write wrapper scripts (or GHA yaml) that implements this conditional behavior when invoking I will update this draft with the above conditional behavior implemented so we can get a better idea of what it will look like in practice.
Yeah I'm curious what we settled on there. As of right now, the only clean solution I can think of here is to add support to BuildKit's gateway API for specifying cache import/export settings as part of the individual solves. Otherwise I can't think of any way besides what the prototype here does. As long as performance isn't meaningfully compromised, then maybe this approach is fine for now? EDIT: to clarify, I meant "this approach with some additional fixes in place to not duplicate the execution of client tasks" (i.e. add some logic that ensures those tasks only run once, could be as simple as a |
In this case it was specifically Reading this felt like the same problem which is chicken/egg problem of needing the output of an action to bootstrap the buildkit session. Maybe the same solution can be used for both. |
Signed-off-by: Erik Sipsma <[email protected]>
|
@aluzzardi Pushed an update that shows one example of how this can work across different environments. Now Getting this to work required a lot of battling with CUE though, I was getting very strange errors about cycles where it did not seem like there could possibly be any cycles. Not sure yet, but I wonder if this is another side effect of evaluating the plan multiple times? Either way, I think my next step will be to investigate more ways to fix that whole issue cleaner. But let me know if the meantime if you think this addresses your question about environment-dependent config. |
|
I think I figured out a way to cleanup the BuildKit part of the problems here:
The above means that we can manage the whole build with one instance of dagger's The only remaining issues are the Not totally sure how to achieve this quite yet, vague ideas:
Will continue investigating options there, but it feels like something must be possible, so there should be a route to getting this cleaned up. |
|
I figured out a way to force action tasks to wait on cache import tasks before executing as described in my previous comment, but now having thought about it more I'm not sure this is the right approach:
I'm wondering if what we really need here is the ability specify explicit dependencies. As described in my previous comment, I know now it's possible to basically dynamically register cache config from tasks and then have it take hold in the build. So I think what we really want here is the ability to say "run these cache config tasks first, then run this block of CUE", where "block of CUE" is whatever block the user wants the cache settings to apply to. Could be every action, could be one action, could be a subset of tasks within one action, etc. I'm not sure of any way of accomplishing this without either explicit dependencies, "dynamic tasks", or very heavy refactorization of our CUE SDK (basically a v2), all of which are projects in and of themselves... cc @aluzzardi Do you think I'm overthinking this and it would be okay to have the implicit behavior of forcing actions to depend on the |
|
This PR is stale because it has been open 14 days with no activity. Remove stale label or comment or this will be closed in 7 days. |
|
This PR was closed because it has been stalled for 7 days with no activity. |
This is a very rough prototype of the updates I'm proposing to enable better ways of configuring cache. I'm opening this to get feedback on the design; the code here is just serving as a proof-of-concept to give everyone a rough idea of what this could look like.
Problems Being Solved
This is mentioned in the
Seamless Configurationsection of the CI caching epic, but to summarize the problems being solved here:dagger do. See our CI for example where we setup a complex system of imports/exports based on whether the run is for a pull request or a push to main.Proposed Solution
cachefield underdagger.#Plan(sibling toclientandactions).dagger.#GHAConfigdefinition in the code here, but note that even the interface there has more inputs than necessary. The final cleaned-up interface can likely just accept a single input (the whole github event object), from which all the existing fields are parsed out of.#Secretnow too. This means we have the flexibility to provide creds from anything: env vars, files, universe packages like the new 1password one, etc.client.env. I added a rough#StringConfigdefinition to assist this, which parses cache configuration from a string that matches the format we used for env var based config before this.Implementation Details
cue/flowsetup is a bit tricky. Thecacheconfiguration needs to be evaluated before any actions (as we have to provide it at the beginning of the buildkit session), but it may still require fields from client or even other imported packages (i.e. to get credentials)cachefield in the same way theactionis, just first. This is fine for the prototype, but has some issues in that it can mean thatclientfields get evaluated twice if referenced in bothcacheand theactionand a few other related side effects like that. I think we can address those by either adding some de-duplication ability or maybe there's a different approach that will avoid them.Alternatives
Some other possible solutions instead of this one: