Repository navigation
Closed
Labels
Description
Overview
I propose adding a new feature to the Dagger API: saving & loading of pipelines.
- Save: snapshot the state of a pipeline, encode it as text, send it to the client
- Load: restore the state of a pipeline, decoded from text received from the client
This would be a very powerful primitive that we could use in many ways:
- Stitching. Allows clients to "stitch" pipelines together into more complex pipelines. This is necessary since some pipelines cannot be expressed as a single GraphQL query. Note: this feature already exists, see next session
- Shareable content. The encoded pipeline state can be shared and reused across Dagger installations. Because it's text, it's easy for users to send each other a pipeline as a text file, or even copy-paste its contents, like they would a Dockerfile.
- Callbacks. Possibly, some API features could be built on top of the concept of a "callback": an executable pipeline, passed by the client in encoded form, to be executed by the engine in the future: for example as a secrets provider, or as an events handler, a middleware or hook, scheduled execution, etc. etc. This may or may not require changes to the existing format and call convention (arguments? inputs/outputs?)
** Advanced UI. Image a visual UI where you can not only visualize your DAG, but select any part of it and move them around, copy-paste their contents like you copy-paste an image, or export them to another DAG..
Relationship to existing IDs
The foundation for this feature already exists, in the form of content-addressable "IDs" in the Dagger API.
I propose that we keep this feature, but change how we think of it, and how we use it.
- When we query the "id" of a container, directory, secret or file, we're actually saving the state of the pipeline that produces that object
- When we lookup by "id" a container, directory, secret or file, we're actually 1) loading the state of the pipeline, and 2) asserting the type of the pipeline's output (eg. a file "id" can't be loaded into a container).
Pipeline Executable Format
To implement this feature, we need to specify a standard format to encode/decode the pipeline "code". The starting point of this format should be the current ID format. The process of formalizing the specification will probably require some clarifications, cleanup etc. This is probably a good thing.
Activity
shykes commentedon Nov 18, 2022
cc @aluzzardi @sipsma @davidwallacejackson
sipsma commentedon Nov 18, 2022
Many thoughts, but one immediate note is that this has significant overlap with some of the problems and possible solutions to session stickiness that @vito and I talked about previously. Specifically, see possible solution
A) Pin sources in returned IDsin this issue: #3613This issue and that one aren't the exact same (just overlapping venn diagrams), but that other issue may have some helpful context around the general idea of making IDs more re-usable.
shykes commentedon May 11, 2023
pinging @kjuulh who expressed interest in this topic today :)
vito commentedon Sep 11, 2023
Spent some time thinking about this and have a proposal to pick apart. There are still some loose ends and potential paths to explore, but there's enough to riff on async for now.
I started by defining a protocol format for IDs on the basis that they're closest thing we have to "save/loadable pipelines" and we've been kicking the can down the road with regard to their structure and format. We're going to want a canonical way to serialize/deserialize these, and JSON ain't it, so I sketched out a Protobuf definition and a Cap'n'Proto equivalent. The advantage of Cap'n'Proto is that there is 0 cost to marshaling/unmarshaling, which will be handy for all those times that we want to take a digest. The disadvantage is that the generated Go code copies the
IDstruct all the time. (Upstream issue)I like to think of these IDs as "constructor-addressed content." They embed a recipe for creating content, and if the content isn't found, the recipe can be used to create it.
The structure should be unsurprising: an ID contains the sequence of chained GraphQL field selections that created it, paired with the GraphQL return type.
But there are some interesting twists:
taintedif the field is not "pure" (same inputs=>same output).taintedif any of its inputs aretainted.withExec/ modules:withExectainted by default, but module functions pure by default, encouraging people to modularize CLIs.withExectainted by default, with an optional param to indicate that it's pure.withPureExecAPI.meta, allowing it to be removed from the ID without changing its semantics.pipeline,withFocus,withoutFocus.metaselectors recursively removed.Future possibilities, need more thought:
digestof the content they create so we can verify that they created the right content, or even detect IDs that are actually impure.ni://sha-256;...URIs.container.from("alpine")to return an ID that is actually equivalent tocontainer.from("alpine@sha256:..."). It's a bit sneaky but I think this practice could save our butts more easily than using Buildkit's source pinning, and it's more general.git.branch("main").tree.metafields, since it's important to preserve things likepipelineandfocus.vito commentedon Oct 13, 2023
Follow-up before I forget: one pretty neat property following above is that SDKs would be able to construct IDs client-side. This means that rather than making multiple requests to calculate IDs and then pass them in to another request, the client can compute one big DAG and send it all at once.
shykes commentedon Oct 13, 2023
@vito thanks for keeping this fire going! A few questions to fan the bikeshedding flames:
Is pure/tainted the same concept as hermetic / non-hermetic or reproduceable/non-reproduceable? I'm trying to understand if we're dealing with one concept with fuzzy terminology, or several distinct concepts. (For the rest of this comment I will assume they are all the same concept).
Do we need to encode pure/tainted in the ID payload itself? It would make more sense to me if we didn't, since that information is already encoded in the Dagger API spec itself, so encoding it in the ID would be redundant. Or am I missing something?
Re-inventing an entire format to serialize what is essentially a graphql operation + additional metadata, seems like a slippery slope to me. I would be more reassured if we built on top of the existing GraphQL specs for encoding GraphQL documents (which by the way can contain multiple operations). Then an ID would be literally a GraphQL document inside an envelope containing additional metadata, like engine version, cached digests, etc. This clean layering seems very important to me.
vito commentedon Oct 14, 2023
@shykes Fun questions!
Same concept - sorry, I might hop around a lot based on how the sentence flows 😅
There are cases where the same API may be tainted given one input (
from("alpine")) and pure given another (from("alpine@sha256:...")), so I think it's important to include this distinction.Part of me also just likes having all of the relevant metadata together at one point in time.
In the context of having clients construct IDs ahead-of-time, however, it might make things more difficult. I think there's a path forward where the server always returns "fully hydrated" IDs, so if you submit a query with a hand-constructed ID like
[container, from("alpine")]as an input, the full ID you get back actually includes whatever ID was returned on the object returned byfrom("alpine").(This is also a related concept mentioned above where querying
container.from("alpine")would actually return a 'pure' ID representing whateveralpineresolved to at the time, but that's orthogonal; if it returned an impure ID, you'd get that back instead.)To my knowledge there is no prior art for what we're trying to do here, but I'd be very happy to be wrong.
Traditionally GraphQL is used for querying "real" data that exists somewhere (or across various systems). The queries themselves are immaterial. Our case is somewhat unique in that the queries represent repeatable (assuming hermetic) transformations applied to immutable objects, giving the queries a whole new use case described by this issue. (The "transformations applied to immutable objects" phrasology is lifted from a chat with @sipsma.)
Further, I think it's important to have a standard canonical representation for cases like this where the data encoding is a critical component of caching. GraphQL documents, much like JSON, don't have a canonical representation. Overloading them could lead to awkward footguns like relying on presence/absence of whitespace and the ordering of fields (which some language APIs might not let you control). @jedevc also had some fun rants about "3-space-indented JSON" ending up as a de-facto standard somewhere in Docker/OCI. 😱 I remember being bitten by something similar in the past where I was disappointed to realize that the way that I marshalled a manifest JSON really mattered to the digests that come out.
So considering we plan to use these IDs as cache keys, I think we should care a whole lot about the format, and considering Cap'n'Proto makes calculating digests super cheap, just hit 1.0 recently, and already has bindings in most popular languages, it seems like the ideal choice to me atm. (Also just to note: the language bindings are only important if you want to do client-side ID construction.)
This part in particular is an anti-feature at least as far as IDs are concerned because they need to identify a single object. If we were to use GraphQL documents for IDs we would likely need this to be a validation error. IDs as specified above can still contain multiple operations via their inputs, they just have to produce a single object in the end.