Repository navigation
Description
Overview
In the new cloak core API, cache volumes are associated with a key provided by the client. Buildkit does not provide a facility for namespacing these keys, so by default every client that looks up the cache volume foo on the same engine, will use the same cache volume. This is not practical, and will probably lead to ad-hoc namespacing solutions. It would be better for Dagger itself to handle namespacing. But how?
As explained by @vito (see original discussion below), the answer is probably namespacing by something roughly equivalent to a "project". This issue is to discuss whether this feature is actually needed, and if so how to design it.
Original discussion
As discussed in #3287 (comment)_ :
I agree that we'll need scoping really soon if not on day 1. I wonder if it's closer to "project" than "user" though. I may be using the same machine/user to work on multiple projects that all use Dagger and it'd be awkward if they collided with one another.
You are right. I see two possible paths here:
- We introduce the smallest possible concept of namespace, just enough for have basic scoping, and improve later.
- We defer namespacing entirely. We take the leap of faith that we can introduce it later and not break the UX (similar to extensions).
I'm leaning towards option 1. Mostly because it seems really hard to ship a UX with global scoping, then change it to support namespacing that can support something like a project. I could be wrong though.
Note: I think @vito 's use of "project" is roughly equivalent to @sipsma 's use of "session" in this discussion, is this accurate?
In some cases you might want to share caches across projects though, for example it should be safe to share one big Go build/module cache.
This part I'm OK with deferring to later. I think if we have a good project scoping primitive, we can find a way to add this feature later.
Also one thing worth clarifying: we're aiming to prevent cache collisions just from a usability perspective, not a security perspective, right? So it should be OK to let the user provide the scope key. Multiple untrusted tenants on the same Buildkit is never a safe thing to do anyway.
IMO we need a UX primitive that works in a single-tenant and multi-tenant context. Totally agree that we don't want to actually make a buildkit instance multi-tenant (at least not with untrusted tenants) but we might want to implement multi-tenancy at a higher level (with cloud etc). So if the UX has a hook for that, it would be ideal.
Activity
[-]Basic project management[/-][+]Basic project scoping[/+]sipsma commentedon Oct 12, 2022
"Session" and the use of "project" here are related but not entirely the same.
Session is an already existing concept today. It's how buildkit scopes certain resources (localdirs, gateway containers, among others). Sessions have a random ID (they also have a name you can set, but that's different than the ID) and are tied to a single client connection. Once that connection is closed, the session is gone.
Project as it's used here (and as I understand it, correct me if wrong) would be more persistent than a session because it would be scoping cache dirs. If you use a cache dir, disconnect and then reconnect, it should be possible for the cache dir to still exist (as contrasted with e.g. gateway containers where they are gone when the session ends).
The direction I've been leaning more and more towards for a while is that the session concept we get from Buildkit is really hard to work with and often not what we want. What we really want is more like the "project" concept above where resources are less ephemeral. You should be able to let a service keep running even if you disconnect.
The vague, incomplete idea that's been knocking around my head is that we maybe should invent our own "dagger session" concept which encompasses not only services and local dirs (like Buildkit sessions) but probably also the loaded schema. Can add cache dirs to that too. Dagger sessions would have some degree of persistence.
If we wanted to call "dagger session" a project instead that'd make sense to me in isolation, we just need to sort of the conflicts with the existing concept called project. The two concepts have overlap in that they may both be associated with a schema, but in other ways they are not really the same. I'd actually be in favor of calling the "persistent-session thing" a "project" and the "config for an extension" (i.e. what's currently called "project") something else.
Hard parts:
shykes commentedon Oct 12, 2022
In order to avoid confusion with existing definitions of "session" and "project", for the purpose of this discussion I propose using the more neutral and functional "namespace". Analogy is eg. to kubernetes namespaces, containerd namespaces, and perhaps docker context?
Doesn't have to be the actual name we use, it just seems useful to have our own name for now, to avoid interference.
EDIT: add comparison to containerd namespace
[-]Basic project scoping[/-][+]Basic namespacing in API[/+]sipsma commentedon Oct 12, 2022
containerd has namespaces too, which could be especially relevant to us if we decide to use the containerd worker
shykes commentedon Jul 7, 2023
Update: we have gone with option 2 (defer namespace entirely). Now we are facing an urgent need to introduce namespacing, in order to implement persistence of cache volumes in Dagger Cloud.
I am resurrecting this thread to make sure we avoid breaking the UX.
cc @sipsma @vito @marcosnils
8 remaining items
shykes commentedon Jul 10, 2023
I didn't understand this part, what does "vendored out to users in your org" mean?
sipsma commentedon Jul 10, 2023
I'm imagining a top-hat for an org creating their org's standalone environment and including
CacheVolumetypes as part of that environment's API. The low-level plumbing for this would be easy to support, but this doesn't clearly fit into any of the existing entrypoint types (commands, artifacts, shells, etc.), so I suppose we could consider adding aCachesentrypoint type?The DX would be that when users in that org need to use a cache volume, they just import their org's environment and then can choose cache volumes from it. So if top-hat wants their support
pip_cacheandgradle_cache, the user would use them in their pipelines either like:client.Environment().Load("my-org").Cache("pip_cache")client.MyOrg().PipCache()Either one of those above would be returning a
CacheVolumetype, so it would just plug into the rest of the APIs seamlessly. You could also imagine APIs for querying what caches exist, etc.The overall idea is that Zenith gives orgs a way of cataloguing cache volumes for end-users, which solves the problem of "when I write code describing my pipeline logic (which includes creating and naming my cache volumes). I shouldn't have to know everything else that runs, or will run in the future, in the same Dagger Cloud org as my pipeline." You know what to use because your org's environment tells you what is available to use.
There's actually a bunch more interesting features we could layer on top of something like this, but I'll try to not derail the conversation too much yet :-)
shykes commentedon Jul 11, 2023
OK that's pretty cool - perhaps even mindblowing ;) This gives me a glimpse of a deeper integration with Dagger Cloud, where devs can take advantage of its features programmatically. Which I love.
BUT it also scares me a little bit, wouldn't this cause cloud-specific, and org-specific details to leak all over the place into otherwise perfectly portable code?
I feel like we could have the best of both worlds, if we could make this similar to the dynamic secrets API: 1) fully programmatic; but also 2) traces a path to keeping the code portable in the future, with "secret providers".
I feel like your idea for cache volumes isn't quite there, but perhaps it could be?
sipsma commentedon Jul 19, 2023
@shykes Sorry I just remembered this whole thread and realized I never got back
I'd argue that "cloud-specific, and org-specific details" are not something to be avoided. We absolutely 100% want portable, re-usable environments, but ultimately end-users need to take those environments and use them to their precise needs, and it's great if that's just code too. I guess the analogies would be:
I can't totally imagine what this would look like in a way that's different than just having the ability to import a cache mount definition that's defined in an external environment, might need clarification on what you are imagining for something like this.
mircubed commentedon Sep 12, 2023
@marcosnils @aluzzardi can you provide additional context on the current status of this?
sagikazarmark commentedon Dec 19, 2023
This is what I ran into recently:
I have a project with two Go binary builds and an e2e test run (not to mention a golangci-lint module that uses the same Go module under the hood).
The binary builds run in one GHA workflow, the e2e test in another (although I don't think that really matters).
All three steps use the same Go module that define the following cache volumes:
That results in the behavior outlined above: essentially the last one to complete wins and overwrites the cache of the other two.
In this case each three step would need their own "namespace" to work.
I also wonder if the namespace should include other information, like branch or commit hash (similarly to how caching works on GHA and other SaaS CI providers). Let's say I have two PRs running the same builds in parallel. They would also overwrite the cache.
One potential solution I can imagine is initializing a new module with some context accessible from the module:
I considered adding a cache key argument to my Go module (I may still do it), but considering the rather complex API (partly due to the method chaining) it wouldn't be trivial. (For reference: here is the module)
shykes commentedon Dec 19, 2023
@sagikazarmark in your case I think you are running into 3 distinct (but related) consequences of lack of namespacing :
Global Go cache. All your invocations of go share the same Go cache because they use the same cache volume name. This is actually OK (I think) because Go supports sharing the same cache across projects.
Concurrent access. In the default sharing configuration, cache volumes allow concurrent writers. So if you invoke go multiple times concurrently, they will hit the same cache volume at the same time. This is also OK (I think) because Go also supports concurrent writers to its global cache.
Last run wins. You are seeing some runs overwrite the result of other runs. I think this is an artifact of Dagger Cloud’s distributed caching implementation. At the moment cache volumes are shared between all engines connected to the same Dagger Cloud organization. The Dagger Cloud organization is a global namespace for cache volumes. Synchronization is done by uploading a snapshot of the entire volume. The last upload wins. There is no merge mechanism at the moment.
In summary: the core namespacing problem is not specific to Dagger Cloud, but it can manifest itself in more visible ways when using Dagger Cloud with cache volumes, and that is what you are encountering.
If I’m right, then grouping all three steps in the same Dagger session (ie. in the same CI job) should solve the “last writer wins” problem.
sagikazarmark commentedon Dec 19, 2023
@shykes makes sense, I'll try that, thanks.
TBH, I'm not that comfortable with bundling all CI steps into a single run though.
For one, I don't get the same feedback on GH right now with checks if I do that.
Also, in some projects it's just not possible to scale the runner vertically (eg. OSS projects), so splitting CI runs is often for performance reasons (I don't have the numbers to back that up though...yet).
shykes commentedon Dec 19, 2023
I completely understand. To be clear I only suggested this as a stopgap to alleviate the immediate pain. I absolutely agree that you shouldn’t have to combine runs in order to get the cache volume sharing semantics you expect.
shykes commentedon Apr 26, 2024
I am deprecating this issue in favor of #7211 , which is more up-to-date and more narrowly focused on cache volumes.