Repository navigation
Description
Overview
A Dagger workspace should be configured by one simple file, instead of a combination of special directories, yaml files and cue modules like today. This requires a design change across several dimensions:
- System design: change the contents and lifecycle of workspaces and environments
- CLI: change
daggersubcommands to reflect the change in system design - Filesystem layout: change what files and directories are stored on the user’s filesystem
- Developer experience: change how and when Dagger users interact with the Cue developer experience.
Objective
The desired results of this design change are:
- a simpler design: less code, less concepts, etc.
- a streamlined user experience: more consistency between the different parts; remove cruft and legacy accumulated along the way.
- A stronger distinction between basic usage and advanced usage; with the learning of the Cue development environment as the determining criteria. Basic=no cue dev required; Advanced=cue dev required.
Design proposal
This is a baseline proposal. Omissions and disagreements are an opportunity to find the final design together.
Role of the dagger.cue file
Any directory can become a Dagger workspace, by adding a valid dagger.cue file. Its role is analogous to docker-compose.yaml or waypoint.hcl for example: it defines every aspect of a workspace that can be safely version-controlled. In terms of the current design, it replaces all the values.yaml files for a workspace, into a single workspace-wide file
Use of cue in the dagger.cue file
dagger.cue is a standalone file which happens to use the Cue syntax for convenience:
- It is not part of a cue module
- It is not allowed to import external packages, and its package clause is ignored.
- It must be concrete (ie. can be exported to json or yaml at any time). It is invalid for a dagger.cue file to not be concrete.
Example of dagger.cue file
An example of a dagger.cue file might look roughly like this:
// User-friendly workspace name and description
name: “TODO-app”
description: “Everything you need to ship TODO-app”
// Schema version
version: “0.1.0-alpha5”
// First layer of a Dagger environment: the plan
// It may be a Cue package name, or a path to a local directory
plan: “alpha.dagger.io/templates/jamstack”
// Artifacts provided by user
artifacts: {
“src”: {
type: “dir”
path: “./app/src”
}
}
// Secrets provided by user
secrets: {
“frontend.account.token”: {
value: “lkjsdflkjdflkjsdlkfjsdlfjsdlkfjklsdjfklsdfjkldsf”
}
}
// Settings provided by user
// NOTE: structure fully exposed in Cue
settings: {
api: awsConfig: region: “us-west-2”
}
Environments
By default, a workspace has a single implicit environment. Optionally, several environments can be defined, each with their own plan, artifacts, secrets and settings.
Compared to the current design, environments are less important. It is expected that creating multiple environments is an intermediate-to-advanced use case, that most simple configurations will not use. This is reflected in the dagger.cue schema:
- One should not need to know about environments unless more than one is needed..
- ..therefore, one does not need to write the word “env” in
dagger.cueunless more than one is needed
This makes the schema slightly more complex to implement (moderately more work for us) but simpler to understand and use (less work for all users).
Example:
name: “TODO-app”
// Advanced manoeuver: use Cue to define an overrideable default plan
env: _: _ | *”acme.infralabs.io/templates/jamstack”
env: staging: {
// Override the default plan
plan: “./dagger-configs/todoapp-staging”
}
env: prod: {
artifacts: source: {
type: “git”
remote: “https://github.com/dagger/examples”
subdir: “todoapp”
ref: “f424242424242”
}
}
Relationship to Cue module
Each Dagger workspace manages its external Cue dependencies in a special directory called a Cue module.
A workspace can be embedded in an existing Cue module: in that case the parent module is used by default. Otherwise a module is initialized in the workspace directory. A custom module directory can also be configured by setting the cuemod field in dagger.cue, but most users won’t need to.
Dagger is strictly compatible with Cue module interfaces and conventions. As a result, the Cue module may be managed by the regular cue command, the dagger command, or both.
A Cue module may safely be shared between several Dagger workspaces. Workspaces with a shared Cue module simply have shared dependencies: updating a dependency in the module will update dependencies for all workspaces using that module.
Plan as a Cue dependency
The plan is the base configuration for a Dagger environment. It must be a valid Cue package, either local or external.
If it’s an external Cue package (for example plan: “acme.infralabs.io/templates/jamstack”), it is managed like any other external dependency in the Cue module.
Request for proposals
Below are points of the design which are not finished, and require proposals. Probably not an exhaustive list :)
Where to store encryption metadata?
What we know: user-supplied secrets can be safely written to dagger.cue, in their encrypted form. It is an error to store unencrypted secrets.
What we don’t know: how to keep the benefits of the current secrets system, without its downsides? The current design:
- encrypts secrets with sops (good)
- pollutes the values.yaml file with verbose sops metadata (bad: confuses user)
- requires re-computing a signed digest of the entire file, including unencrypted parts, after every change (bad: makes manual edits difficult)
An ideal solution would keep the benefits (1) without the downsides (2 and 3), and without splitting the secrets themselves into a separate file (see the title: “one simple config file”).
Can dagger safely and cleanly manage a Cue file?
dagger.cue is intended for mixed use: you can modify it directly with a text editor; and the dagger tool can modify it. This requires:
-
Mutating a Cue tree. This is an implementation problem (not user-facing). The Cue APIs are not optimized for this use case, so it may require additional work and technical tradeoffs. Do they make this design so hard that it becomes unpractical?
-
Minimal diff. There are many valid ways to encode the same Cue tree to a file. The human user will choose one way; the tool may choose another. How do we make sure changes to
dagger.cueproduce clean diffs, so that tracking them in source control is not frustrating?
Conflict between dagger.cue and other Cue files
One issue with using the .cue file extension, is that it may conflict with unrelated cue files in the same directory.
Generally, Cue does not tolerate unrelated Cue files co-existing in the same directory. If dagger.cue is added to a directory with unrelated cue files already present, a variety of bad things may happen:
- If the other files have a package clause, then
cue evalwith no argument will stop working. - If the other files have no package clause, then
cue evalwith no argument will attempt to combine the contents ofdagger.cueand the other files.
Also, if there is already an unrelated file called dagger.cue:
- Dagger will attempt to load it, and return an error
- The new
dagger.cuecannot be added without moving or deleting the old one
Activity
samalba commentedon Jul 8, 2021
tl;dr: I like having a simplified cue file at the root to configure your envs and values.
About the values.yaml: I would keep the secrets values separate from dagger.cue - maybe a "secrets.json" file on the side to emphasize that you should edit it yourself. Sops requires the whole file to be sign and it's sometimes annoying to have the entire encrypted content to change simply because of a small edition to the file. It's only related to secrets, so I would keep them separate for that reason.
It's fine to have a default environment: I would keep environments explicit, it makes the env definition in dagger.cue more intuitive. Because the keys inside
envwill directly map to what the user sees in adagger list.A proposed variation to the env mapping: have the notion of env to only exist in dagger.cue. The plan needs to be designed to handle multi-envs (if you need multi-envs, you can simply ignore them).
shykes commentedon Jul 8, 2021
Good point, that’s an unresolved point of the design. I added a section: “where to store encryption metadata?”
Thanks, I added more details in the “environments” section to address this (TLDR: environments become less important, so we hide them more).
Did you mean “have the notion of env only exist in the plan, and NOT in dagger.cue”?
shykes commentedon Jul 8, 2021
Updated “relationship to cue module” to support embedding the workspace in an existing cue module.
shykes commentedon Jul 8, 2021
Paging @myitcv and @mpvl as this is a linchpin of Dagger’s integration with Cue, across many dimensions: technical integration, developer experience, learning curve, etc.
shykes commentedon Jul 8, 2021
New section: “plan as a Cue dependency”.
shykes commentedon Jul 8, 2021
New section: “conflict between dagger.cue and other cue files”
aluzzardi commentedon Jul 27, 2021
Didn't comment earlier because there's a lot to digest.
I like the simplified format.
Some feedback:
1) Can this be reconciled with the current
values.yaml? I think the two are redundant and this format replaces it.Field by field analysis:
name: ✅description: ❌version: ❌plan: ✅ The plan used to be a regular input that supported git. It was replaced by a relative path recentlyartifacts: ✅ Encoded as "inputs"secrets: ✅ Encoded as "inputs"settings: ✅ Encoded as "inputs"This seems like an evolution of
values.yamlbut rather than being in.dagger/envit's directly in the source tree.However, it opens up a bunch of questions:
dagger list) if they're not in.daggeranymore?2) What's in the template?
We brainstormed "template stacks" in a previous iteration of Dagger and I had the same feedback: I think they lack composability and no two applications realistically share the same stack.
To me a jamstack is frontend only, possibly pushed to netlify or s3+cloudfront. To you it might be frontend+api server. To someone else it might be frontend + a couple of of lambda functions and a long running worker on ECS.
I think templates work for a single service (e.g. if it's a frontend, you get to pick between the netlify or s3+cloudfront template) but it doesn't work well with multiple services (because for example you'd be looking for the netlify+a couple of lambdas+long running ECS template, small chance something fits your use case properly).
3) New mechanism?
Do we actually need a built-in concept for those files, can't we just piggyback to the regular CUE flow?
Taking the example above with some slight tweaks:
shykes commentedon Jul 29, 2021
Yes that’s correct. To quote the proposal:
Yes, in this proposal,
planis renamed totemplate, with the hope of simplifying the user experience by reducing the number of unusual concepts and terms.Correct. Another difference is that it’s workspace-wide.
Good question. Two thoughts:
dagger. This is similar to howgititself works.Also good question. My assumption is that we continue to manage state in the same way. The only change would be the name of the file or directory holding the state. For example
.daggerstate,dagger.state,.dagger?“Template” is simply a new name for “plan”. So
templatemay reference a cue package name (possibly imported), or a local directory (for custom templates).I agree with all of this. Most power users will develop their own custom templates/plans, and they will benefit from the full CUE development experience and Buildkit APIs. This proposal stays out of the way of power users, and focuses on beginner users, by making it easy to learn and experiment:
“Template” is more familiar and therefore reduces friction: one less word to memorize is one more other thing I can memorize later.
Reusable templates like my example
alpha.dagger.io/templates/jamstack, even if they won’t satisfy every power user, would still be a huge UX improvement, because 1) they illustrate how Dagger works so I can understand it faster, 2) they help me actually deploy something while I learn, 3) they provide a reference implementation for the emerging power user community, 4) IMO lots of apps would actually be fine deploying from a standardized, opinionated jamstack template.Since
dagger.cueis an improved version ofvalues.yaml, you could ask the same question for both.I think there are 3 problems with piggybacking on a full-blown CUE development flow.
Your example wouldn’t merge. Since a “template” is just a plan under a new name, its contents are to be merged directly in the environment’s Cue tree. But
src: { type: “dir”, path: “./app/src”}for example requires further processing before being merged. Same as forvalues.yaml.One goal of this proposal is to lower the barrier to entry. To quote the “objectives” section in the proposal:
I’m trying to define a basic usage of Dagger which does not require learning advanced Cue contepts such as unification (
&) and definitions (#MyTemplate). The priority is to make the config file simple and familiar for a wide audience.aluzzardi commentedon Jul 29, 2021
I agree with all the benefits. I'm skeptic however by the lack of composition of the template (e.g. it's one template containing a set number of components). What would we include for instance in the jamstack template? To me (as a user) an example of jamstack is our docs website (JS frontend querying GitHub and a few other APIs). In your example I assume it implies a backend as well (I see 2 different tokens in the config file), which wouldn't fit my docs requirement.
To sum up, I agree with the benefits, in practice I'm failing to visualize an all in one template which would work for me as a user.
I'm concerned about creating a 2 tiered system with two different formats. Not actually concerned, but it makes me question other things.
We explain having a single syntax as one of the big advantages compared to other tools. Instead of having, for instance, a "user facing" configuration in HCL and a "power-user syntax" in Go, we have a single CUE syntax all the way. With accompanying trade-offs for both users (it's a bit harder for end users, it's a bit limiting for power users). With this simplified DSL I feel we end up in the same situation with 2 different languages. At that point why not whip out Go, Python or JS for power users to write new components? If a user has to learn something new to write components, might as well use something they already know, the learning curve will be smaller and the tooling arguably better.
On top of that, I'm also concerned about the number of layers: There's the simplified file, then the power users writing CUE directly, then the power power users writing low level packages using
#up. Understanding what's going on is quite challenging.shykes commentedon Jul 29, 2021
Mapping this to my list: it looks like you agree with benefits 1, 2, and 3 - but not 4. Is that right?
I think this concern is orthogonal to my proposal. All the negative points you describe are already present in the current design with
values.yamlcombined withdagger edit. In fact this proposal could just as easily define adagger.yamlinstead ofdagger.cue. It just felt weird to talk about the benefits of Cue, and not use it for our main config file, which is why I proposed switching to Cue.Maybe you should “rebase” this part of your feedback to target the current design instead of my proposal? It could even become a standalone proposal in its own right.
aluzzardi commentedon Jul 29, 2021
I do agree with 4, to a degree.
I do think apps would benefit from deploying from a standardized, opinionated "jamstack template" if that template was all about a single component. For instance, an AWS template for yarn/npm build + s3 + cloudfront CDN (which I would use for the docs site, or for the BL dashboard, etc)
I don't agree (or rather, I don't think it would fit a realistic use case) if that template spanned across multiple services: e.g. a dashboard on top of yarn+S3+cloudfront AND an API on top of ECS+RDS.
Maybe all I want is the website. Maybe I want the website and 2 APIs. Maybe those APIs are on ECS, maybe on Lambda. Maybe I want RDS, maybe I want DynamoDB. And maybe it's a combination of all the above.
If I take the "docs" stack as an example, here's what I'd need:
I would greatly benefit from 3 opinionated templates (or 4 if DynamoDB is on its own?). I don't care about the nitty gritty details of each service (e.g. what the ECS template looks like), but I do care about my app architecture and don't want to bend it to fit the template mold.
If the template contains the entire stack, it's very unlikely it will fit my use case (which I believe is fairly trivial). And even if it did today, I might outgrow it rather rapidly if it's not composable. In the docs stack scenario, we don't have the lambda+dynamo parts yet (querying the GH API directly) but are thinking of adding them in the near future. If the template described the stack, I would need to move away from a different template when adding those services (which again, the chances that one exists with the exact services I want is pretty thin).
shykes commentedon Jul 29, 2021
I think I understand what you’re saying. In terms of this proposal, your feedback is that:
Is that correct?
aluzzardi commentedon Jul 29, 2021
Yes, that's correct.
[...] would not be useful for real apps in my opinion [70% confidence]. I can't think of a good template but haven't thought that hard.
Yes. Or rather, same kind of template but being able to use more than one in
dagger.cue(similar in spirit as docker compose)shykes commentedon Jul 29, 2021
Do you agree with the other 3 benefits I listed?
Even if you don’t believe pre-packaged templates will be useful as-is in production, they can still vastly improve the onboarding & learning experience. For example you would start with jamstack template, perhaps while following a tutorial; later you might extend it (a template itself can be made customizable); then finally you can fork it when you need even more customization. Even for power users, starting from an official template is a better way to learn Cue development than starting from scratch.
And just to clarify: this feature is already implemented. Dagger already supports pre-packaged templates today. They’re just called “plans”.
Sadzeih commentedon Sep 18, 2021
As a new user to cue and to dagger, I think this would have greatly improved the learning process.
Having the dagger files not "hidden" away is good because it becomes obvious what adding inputs does, it allows the user to more easily edit the file manually, which in turns makes it easier to learn how dagger works.
On the subject of the template, I think it's a good idea. It reminds me of Gitlab CI files that you can include in others to compose your pipelines. I do agree that only having one template could be an issue. They would make users believe you have to cram everything into one package instead of cleanly splitting things into different ones.
shykes commentedon Sep 20, 2021
Thanks to all the feedback here, I am going to open a revised version of this proposal.
aluzzardi commentedon Jan 7, 2022
@shykes I believe this has been implemented in Europa. Closing now, please to re-open if I missed something!