Repository navigation
Description
Overview
Currently the cloak prototype is configured by a project file called cloak.yaml.
We propose replacing this file with dagger.gql. The file would be functionally equivalent, but with 3 important differences:
- It avoids encoding a temporary project codename into user's repositories. This assumes "cloak" is simply a future release of Dagger, like Europa was for Dagger 0.2.
- It uses the GrapqhQL query language instead of YAML. Since Cloak is decidedly a GraphQL-centric engine, it makes sense that GQL should be the default, and the burden should be on other options (including YAML) to show that they are decidedly better.
- In addition to "cosmetic" changes of syntax and filename, we also propose slight changes in terminology, to reflect the deeper changes we are discussing in the overall DX, and hopefully stabilize our vocabulary.
Benefits
Benefits of this change include:
-
Consistency. Dagger developers need to learn GQL queries anyway. Why not reuse and reinforce that knowledge for their configuration file too?
-
Tooling. The same tooling can be used when writing the project config and dagger queries. For example the API playground can detect errors, auto-complete etc. This applies to future tooling as well, so the benefits compound over time.
-
No YAML DSL. Parts of the current yaml file are re-inventing parts of the Dagger API, in order to specify how to fetch an extension. With a GQL file, you can simply use the API directly.
-
Creates a "magnet" for more graphql content. A common best practice in graphql is to write and maintain an "operations file" to save and organize your queries and mutations.
dagger.gqlcan naturally become your operations file. This opens possibility (all optional) for dagger to help load queries; share them; document them etc. For example Netlify Graph defines a very promising workflow around sharing and reusing example queries for learning and collaboration. cc @marcosnils @crjm @slumbering .
Spec
FIXME. See highlights and examples for now.
Design highlights
- Special query names.
ExtensionsandSDKhave special meaning. Other operations in the document are ignored. Same pattern asmainfunction co-existing with other functions in the same file. Extensionsmakes use of Aliases to define all extensions in one query. This looks superficially familiar even without knowing graphql, or how aliases work. Later developers will learn how aliases really work, but it's not necessary to get started.- "Extension" is used interchangeably with "dependency". There is no such thing as a project "having its own extensions". A project may have an API, in which case it needs an
SDKquery to configure how to build it.
Other options which were explored and abandonned:
- Use of custom directives
- Use of mutations + input type
Terminology
graph LR;
subgraph projectA
fileA["dagger.gql"]
end
subgraph projectB
fileB["dagger.gql"]
end
subgraph projectC
fileC["dagger.gql"]
end
Example
Dagger file for a frontend project:
query Extensions {
yarn: git(url: "ssh://[email protected]/dagger/cloak") {
branch(name: "main") {
tree {
directory(path: "examples/yarn") {
id
}
}
}
}
netlify: git(url: "ssh://[email protected]/dagger/cloak") {
branch(name: "main") {
tree {
directory(path: "examples/netlify") {
id
}
}
}
}
vercel: workdir {
directory(path: "./extensions/vercel") {
id
}
}
}
query SDK {
universe {
sdk {
typescript(version: "1.14", path: "./api") {
id
}
}
}
}Top-level Dagger file in a monorepo shared by a frontend, backend and machine learning team:
query Extensions {
frontend: workdir(path: "./frontend") {
id
}
backend: workdir(path: "./backend") {
id
}
ml: workdir(path: "./ml") {
id
}
}
Activity
shykes commentedon Sep 14, 2022
FYI @aluzzardi @sipsma @samalba
sipsma commentedon Sep 28, 2022
100% onboard with all of this, it's certainly better than yaml and great in that we can get the full power of our API for configuring projects.
Just notes for the implementer of this (possibly me):
The change to get rid of the difference between project extensions and dependencies will require some subtle changes to the extension loading process.Currently dependencies point to a differentcloak.yamlsomewhereNow, you directly point to extensions that you want to use (not to a differentdagger.gql)This means that when you load an extension, you need to find its SDK (so you know what runtime to use and make it executable). This will require reimplementing the "find-up" logic but now inside the cloak server and on top of LLB (whereas that find-up logic previously happened in the local engine on local dirs).dagger/router/router.go
Lines 68 to 80 in d0f4a4e
sipsma commentedon Sep 28, 2022
Oh also, as mentioned in discord, updating all of this is also a good opportunity to figure out how the current project schema (prototype-quality, not thoroughly designed) could be updated to integrate with the new API (Container/Directory/etc.). Not strictly necessary, but we will be touching that whole part of the codebase so worth consideration.
shykes commentedon Sep 28, 2022
Actually, in this proposal I am using the word "extension" as a synonym to "dependency" (think "vscode extension"). So as I imagine it, the directory for each extension must contain its own
dagger.gql. Otherwise, as you note we would be missing SDK information (and possibly other project-specific information in the future).Given my previous comment, I think perhaps this is not needed after all? Not sure as I don't completely understand it :)
sipsma commentedon Sep 28, 2022
Ahhh okay, that sounds familiar now from the discussions previously, thanks. I was still imagining that we have the same model where
dagger.gqlserves as the project config for the entire directory tree under it.We can avoid that for now actually though. If we start by just colocating
dagger.gqlwith extensions like you're saying, that's simpler at the moment and also doesn't stop us from re-implementing the older behavior in the future (I think it would be a completely backwards compatible update actually).So yeah ignore what I said before.
aluzzardi commentedon Sep 28, 2022
re: the conversation we just had about multi-tenancy.
One downside of switching to GraphQL is it will be harder to machine generate manifests (and parse as well).
This will limit possibilities such as the playground generating a list of extensions to be provided alongside the request (e.g. as a header).
sipsma commentedon Sep 28, 2022
Couldn't it just provide the contents of
dagger.gqlas a header value? Agree that there are less libraries for programmatically generating graphql than there are for yaml, but in our very particular case we have to create a whole editor for crafting graphql queries anyways, so unless I'm not thinking of something it shouldn't expand the scope of what the playground has to do very much.jpadams commentedon Sep 28, 2022
@kpenfound and I were chatting about using this file to contain metadata for Universe marketplace as well. Something like GitHub's action.yml.
https://github.com/actions/setup-dotnet/blob/main/action.yml#L1-L6
cc @slumbering
mircubed commentedon Oct 3, 2022
@sipsma this is in the GA bucket, but do we need this for preview release?
sipsma commentedon Oct 3, 2022
@mircubed Yeah I think we should try to get this in the preview. Otherwise we will be asking all users to completely rewrite all of their configs after preview.
mircubed commentedon Oct 4, 2022
@sipsma after talking with @aluzzardi it seems like you are the only one who can own this, so are you going to have time? If not, is there a way to make this a smaller issue to tackle for preview and then leave some work in another issue to complete before GA?
sipsma commentedon Oct 4, 2022
@mircubed Short answer: yes it should be doable but it will be close.
Long answer: My current top goal is to finish code-first schema support for go
. I think it will be out of draft tomorrow. Then I will be able to start on
dagger.gql(while also having to go back and address comments on previous PR).So that gives me starting thursday of this week and the next week (7 weekdays). I currently imagine that the implementation of dagger.gql should take 2 days (assuming there's lots of distractions as usual, not 100% focused work), so multiplying x2 gives 4 days, so then that leaves 3 days to review+merge+update docs?
So there's risk to it, but it feels within reason.
I will allow myself to take shortcuts and not implement features if time starts running short. The main thing has to be that it's a graphql format and not yaml anymore. That's the transition that will be painful for users to make and is thus needed pre-preview. If there's niceties missing from the graphql format for some reason that'll be acceptable.
shykes commentedon Oct 5, 2022
Logging concerns from @aluzzardi today, originally posted on discord:
sipsma commentedon Oct 5, 2022
My reply at the time in discord:
I don't like this either, but I still consider this a step up from forcing use of a yaml DSL on top of our graphql api.
I also find it interesting that since we are creating language abstractions on top of graphql queries, there may be a door where we someday support specifying the dagger.gql queries with actual languages too. That's a quarter-baked idea, extremely hypothetical, but it is an example of the potential benefit of dogfooding what we're building rather than just bolting yaml on top.
Doesn't the playground need a graphql query editor anyways though? I'd rather re-use that than have to support a yaml editor too. But I may be misunderstanding the concern.
Wouldn't we have the same questions with yaml?
This is possible and not that bad IMO. It's not as nice as yaml unmarshal but the vektah gql library has been pretty reasonable to use I think.
I also think we want codegen in the API anyways so I'm not sure this would be a concern for very long
sipsma commentedon Oct 6, 2022
There was a long discussion in discord, we ultimately decided to go a different route that @aluzzardi suggested to:
This allows us to focus on making the UX wrappers nice and care less about making the format itself easily human readable/writable/interoperable. The file will still be possible to read/edit by a human (i.e. not binary), but we won't optimize for that experience.
Other nice side effects mentioned in discord:
dagger add <extension>)dagger add <<EOF <graphql query>)daggercli commands will be copy-pasted rather than snippets of some file formatThe other changes around
dagger.gqlinvolving simplifications to extensions vs dependencies, scripts, etc. should all still apply here though.We will see if we get the CLI changes in for preview. There is risk they are tied w/ cloud-side changes (i.e. ux of updating this file in a browser), so we may defer those and just have a hand edited file in the short term. Will see once I try tomorrow.