Repository navigation
PROPOSAL: An Easier-to-Use, More Flexible Dagger #1058
Replies: 14 comments 43 replies
This comment has been hidden.
This comment has been hidden.
|
Just wanted to pop in and say, i'm glad to see a proposal like this! I (still 😢 ) haven't had much time to really grok Dagger's codebase, so don't have an informed opinion on Dagger's current architecture, but many of the basic principles here - e.g., eliminate special input paths, express as much of the logic as possible natively in CUE - are hard-won friction-reducing ideas i've come to over the past six months. With polly, we gyrated for a couple weeks on what "passing in variables" should look like, until we finally realized that the best thing to do in most cases is to just to lean heavily on well-defined schema, especially default values, and then expect a polly user to provide a .cue/.json/whatever variables file that mirrors the pop's path structure, which we unify with the pop in order to concretize it. (We're still going slowly on polly work, because getting the Grafana schemas into shape is a challenge, but we're turning that corner now.) Expressing as much logic natively in CUE is huge, as well. This PR in particular pulled the logic for composing plugin sub-schema into the main dashboard schema out of Go and into CUE. (Not quite completely, or it'd be another 250 lines of removed code - that stuff'll be gone soon enough, though.) The code is more maintainable and understandable, but it also allowed me to see far enough that i could conceptualize a key abstraction: generic scuemata composability. (composition implemented here, enabling this delightfully simple use of it). Last quick thing, since scuemata was mentioned - i talked with @shykes @samalba @aluzzardi in July about the applicability of scuemata to Dagger's case, at least for your package imports, and have neglected to give an update since then (sorry!). There are cases where scuemata will be worthwhile natively in CUE, and the case you're describing may be appropriate. But the more general case i was hoping for in that conversation - allowing for stable package imports in general CUE programming - i currently have marked as one of the most distant goals for scuemata, largely because of how much more complicated it makes defining lenses. i think we can hash this out pretty well once i split off scuemata, which should happen shortly after i finish my...very overdue talk recording about scuemata for CONFLANG. (back to working on that now...) |
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
|
We are getting closer :) Here is my list of outstanding questions and comments, and an example to wrap it all it up. Outsdanding questions and commentsConvention for Cue package nameDagger should define the following convention for use of the
Optional
|
|
Taking a step back. At this point there are various minor / cosmetic points to discuss (see my other comment for a non-exhaustive list). But there is a more pressing issue we should address first: what does a complete working plan look like? In particular when developing an action, say “deploy to netlify”, what does the package code look like, and how does it change the DX compared to today? I would prefer that we prioritize getting a clear answer on the DX, rather than debating minor points like “should there be a buildkit field”, “is environment optional” etc. We’re essentially merging values.yaml into the plan and that’s a major change. Let’s make sure the DX is actually improved before going to far down the path. |
|
Regarding a live conversation with @shykes @samalba @aluzzardi and @jlongtine as it relates specifically to @shykes raised a good point that Stepping back and looking at the whole DX here are a few thoughts to keep in mind:
We went "all in" with CUE, let's go "all in" with declarative programming! I see the following problems with introducing CLI flags as a way of injecting values into
We have an opportunity to dispense with an old paradigm entirely, keep CUE as the source of truth, and make the invocation of Dagger as simple as If Considering this along with the core type system proposal I propose the following change to
package dagger
#Plan: {
environment?: string | *""
// Invocation context
context: [string]: dagger.#Value
// the things Dagger actually does
actions: [string]: {...}
// output values to cli (state too?)
outputs: [string]: _
}
#FileSystem: #LocalDirectory | #Git | #S3 | #SFTP
#Service: #Tcp | #UnixSocket
#Value: | #FileSystem | #Secret | #Service | #EnvVar | #YAML | #JSON | {[string]: #Value}This structure allows Example project
package todoapp
import (
"alpha.dagger.io/dagger"
"alpha.dagger.io/os"
"alpha.dagger.io/docker"
"alpha.dagger.io/js/yarn"
)
dagger.#Plan & {
// plan remains unopinionated as to where these values are derived
// only that they are a particular type
context: {
appSource: dagger.#FileSystem
docker: {
socket: dagger.#Service
username: string | *"myDefaultDockerUsername" // plan authors can set defaults!
secret: dagger.#Secret | string // allow some plans to bypass encryption
}
}
actions: {
app: yarn.#Package & {
source: context.appSource // IS a collection of files
}
image: os.#Container & {
image: docker.#Pull & {from: "nginx"}
copy: "/usr/share/nginx/html": from: app.build
}
// push the image to a registry
push: docker.#Push & {
target: "localhost:5000/todoapp"
source: image
auth: {
username: context.docker.username
secret: context.docker.secret
}
}
run: docker.#Run & {
ref: push.ref
name: "todoapp"
ports: ["8080:80"]
socket: context.docker.socket
}
}
}Now invocation can be so flexible without having to write a new version of the plan! All I need are different `plans/local/context.cue' package main
import (
"alpha.dagger.io/dagger"
)
context: {
appSource: FileSystem.#LocalDirectory & {path: "./app"}
docker: {
socket: FileSystem.#UnixSocket & {unix: "/var/run/docker.sock"}
secret: "thisIsmYlocAlS3cr3t" // not too worried here, its local, prod wouldnt do this
}
}Perhaps I want to test a specific branch or commit:
package main
import (
"alpha.dagger.io/dagger"
)
context: {
appSource: context.#Git & {url: "github.com/dummyOrg/dummyProject", ref: "joel/feature"}
docker: {
socket: context.#Tcp & {address: "x.x.x.x:x"} // some docker running somewhere, maybe on a mac mini in Richard's basement cause he has symetrical gigabit fiber internet
username: dagger.#EnvVar & {var: "DOCKER_USER"} // perhaps previously set by something like aws ecr get-login . Dagger retrives it.
secret: dagger.#Secret & {sops: {file: "path/to/encrypted/sops.yaml"} } // dagger executes sops
}
}Or perhaps I have values in a YAML file: package main
import (
"alpha.dagger.io/dagger"
)
context: {
appSource: context.#Git & {url: "github.com/dummyOrg/dummyProject", ref: "joel/feature"}
_dockerYaml: dagger.#YAML & {path: "path/to/docker.yaml"}
docker: _dockerYaml.values
}The main point here is that the plan remains unopinionated as to where |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
The Issues
The current version of Dagger requires imperative CLI commands that complicate the use of the tool as well as forcing the user to do the very operations Dagger sets out to eliminate. The
dagger inputcommands are a regular source of confusion, both for developers new to and experienced with CUE. Furthermore, Dagger has overloaded some concepts such as inputs and left other concepts such as environments and plans rather vague.This proposal will describe a version of Dagger that is CUE-native, that leverages the declarative, commutative, idempotent, and composable nature of CUE in order to reduce the required CLI commands to merely
dagger up <path/to/plan>. Any other commands such asdagger querywould remain solely for informational or debugging purposes.dagger initmay also remain, but should be for convenience only; the effects of this command could be replicated by manually creating files.This proposal will address the following concepts and primitives:
Inputs
Currently inputs are confusing in terminology, the backend implementation, the syntax to define them, and the mechanics of providing them. The various
dagger inputcommands use hidden YAML files to abstract away data that can just as easily be written in CUE. It is quite natural for developers to instinctively try to edit a YAML file directly, but doing so currently results in errors, and this further complicates the tool by forcing the user to go through yet another command,dagger editto change values. None of this is self-evident nor is it intuitive.Non-sensitive values should just be expressed in CUE, and many can be with Dagger currently. There are however, certain types of values, namely those that are derived from the host machine, such as a
directoryorsocket,that would be vulnerable to exploitation by third-party packages and these need to be evaluated and executed in a secure way. This proposal will address these concerns.Environments
Environments currently relates to Inputs in that input values are specified per environment and stored in a hidden folder named after the environment. Dagger currently requires the
dagger newcommand to imperatively define a new environment; again running counter to the goal of a declarative, portable tool, tool. Furthermore, the current implementation of environments is rigid and does not allow for pattern matching, or dynamic generation of environments without wrapping dagger in shell scripts, which again, is antithetical to its purpose.Plans
Currently Dagger thinks of a "plan" as the collection of resources found in the CUE value lattice which is generated from all the Cue files loaded recursively from the environment path. The relationship between the plan and the environment and inputs so far is not clear or intuitive, and the rigid nature of environments makes it more difficult to create variations of a plan. Dynamic creation or pattern matching is also severely limited.
Proposal
All data that Dagger needs to execute a project can, and should be expressed in CUE directly. Making Dagger "CUE-native" makes it a truly declarative tool and removes the need for imperative commands, and makes authoring a project more flexible.
The concept and implementation of "Inputs" as they exist today was a solution to several issues, which are in fact non-issues with the right approach. To understand the vision for this proposal it is necessary to completely dispense of the idea of "inputs" all together. In fact we must dispense of the notion that variable data must come from outside of CUE-with host-dependent data being the notable exception addressed herein.
Instead we should think about data in terms of concrete values, where they are defined, where they are allowed to be defined, and when they become concrete.
Eliminate the following:
dagger inputand its sub-commandsdagger newdagger editvalues.yamlfiles under the.daggerdirectoryIntroduce the following:
dagger.#Planas a schema for the top-level CUE valuemain.cueas an idiomatic conventional starting pointpackage mainas the default project packagedagger up <path>where<path>is the only positional argument and defaults to./A Dagger project is the collection of CUE files which may import third-party packages. The presence of
cue.modand at least 1.cuefile shall be the only things necessary to perform dagger commands.dagger.#Plan
A Dagger plan is the top-level CUE value that contains all the data Dagger needs to execute a pipeline. It may also reference data specific to a particular machine such as access to file system, sockets, environment variables, and secrets. A Dagger project must define at least 1 plan which is defined as such:
alpha.dagger.io/dagger/plan.cueenvironment (optional):
This field is for convenience when authors want to distinguish between plans written for different environments. Can be used statically or dynamically.
environment: localorenvironment: prod.environment: =~"pr-[a-zA-Z0-9-_]*"Dynamically named plans provide a very powerful and convenient mechanism that is not currently possible with Dagger. One exciting possibility is that of programmatically generated review environments. Imagine wanting to deploy resources for each repository branch upon a push to which a branch has an open PR. A user could define a dynamic plan in the Dagger project like so:
environment: =~"pr-[a-zA-Z0-9-_]*"By running
dagger up ./pr-plan/ --environment pr-my-feature-branchDagger will take the string argumentpr-my-feature-branch, fill theenvironment:field, and if it results in a validdagger.#Plan, deploy it.actions:
This will be the list of items Dagger will operate on. Each field, at some point in its depth, will contain an
#up:[...dagger.#Op]context: directories
These will be relative to the project root since that is the known constant, always identifiable by the presence of
cue.modwhereas sub-directories of the project will come and go and extend to an unknown depth.outputs:
Replaces
@dagger(output). Needs more thoughts, and...input. Pardon the pun.main.cue
This file serves as a starting point in which a user can define a plan or a template for plan variations, but is merely an idiom. Its name is arbitrary and can be changed if it makes sense for a particular project. This idiom provides a pattern which can be easily recognized and repeated and makes it easier to switch between different code bases, or teams, or even organizations, and get right to work without having to learn a one-off convention specific to that project. Again, developers should feel free to abandon this idiom if it "gets in their way."
package main
Each CUE file used to write a Dagger plan—those a part of the project scope—must specify a package name and Dagger will assume this to be
package main. To provide advanced CUE developers more flexibility, Dagger commands will support a--package,-pflag to specify a package and will default tomain.Loading CUE Files
Currently, Dagger relies on the imperatively created environmental
values.yamlfiles to determine what path to load CUE files from. Having eliminateddagger new, Dagger will need an inherent opinion and command line argument to determine where files are loaded. The CUE command line tool is very flexible in this regard, and allows loading in the following ways:cue export ./main.cue ./path/to/another.cuethese files will be loaded into the same context and scope and merged to a single valuecue export ./in which case CUE will load all.cuefiles from the specified directory including ancestor directories until the project root (denoted bycue.mod) again all loaded into a single valuecue export ./...which will create a "value instance" from each directory, loading files recursively, but this creates a separate scope, and separate value for each "instance".Dagger will avoid supporting a list of individual files because it is tedious and provides too much room for differing results in cases where one forgets a file or mistypes a file.
Attempting to maintain as similar behavior to
cue evalas possible, Dagger will accept a path as its only positional argument, defaulting to./. The CUE API will then load the provided directory recursively until it stops at the project root (denoted bycue.mod). This enables very flexible, very composable projects. Beginners new to Dagger can author a single plan in 1 or more files in the project root. With little effort multiple variations of the plan can be split into sub-directories. In short this method provides both simplicity for beginners, and ultimate flexibility for the advanced; something for everyone.When executing
dagger up <path>, Dagger will return fatal error if:cue.moddagger.#PlanSecrets
Dagger will no longer perform encryption or decryption of data directly, but instead rely on specific trusted external processes to perform decrypted reads only. If a user has data that needs to be encrypted they will be responsible for doing that using tools like
sops orgpgas examples. Dagger will provide a schema that allows the forked execution of specific processes, each with a curated list of options. Arbitrary processes or arbitrary options will not be allowed; furthermore while the value of an option may be an arbitrary string it may not invoke a sub-shell via$().Secrets will be defined in a CUE schema as a curated set of trusted
secrets.#Providers. The Dagger binary will have a hard coded list of select external tools (the same list defined in the Providers schema) that it can execute viaexec.Command().Run(). Dagger will avoid executing arbitrary external processes.Dagger will start with support for
sops, and add support for additional providers over time.State Management
This is a larger on-going discussion, to some degree a proposal on its own. This proposal eliminates some of the mechanisms on which the current state management depends but can still be compatible. Dagger will now store the same state file it currently writes, but the location will change from
.dagger/<env>/to the path specified indagger up <path>. For example If a user executesdagger up ./prodand follows a plan whoseenvironment:value isprod, a state file will be written to./prod/prod.jsonwhere the name of the file is based on theenvironmentfield of the plan.Host-Dependent vs Host-Independent Config
The
contextkey is where all host-dependent data will be referenced via map. In order to facilitate truly portable code, best practice will be for the plan author to leave thecontextkey as a schema—in CUE terms "incomplete"—so that individuals can add values specific to their local machines by authoringcontext.cuefiles which may be added to.gitignore.Dagger will provide a way for novice users to easily add values specific to their local machines, perhaps through a wizard, or opening an editor with keys already defined. It will then save those to
context.cue. For loosely knit communities of open source developers, they may choose to .gitignore those files. For enterprise teams with tightly controlled common environments, some or allcontext.cuefiles may be added to the repo.The
contextkey within the plan also completely obviates attributes such as@dagger(input)and simplifies scanning. All references to external data must be mapped in the context key. Whendagger upfinds this key to be incomplete, it can either error or prompt the user to fill in the missing concrete values viadagger context editdescribed below.The Best DX This Side of Alpha Centauri
dagger initwill be a convenience method for addingcue.modpopulated withalpha.dagger.io, andmain.cuewith the following scaffolding:dagger contextwill be a set of convenience methods for listing and editing thecontextfields:dagger context listwill enumerate context fields, highlighting which are concrete and which still need to be filled by the user.dagger context editwill open a preferred editor (configurable via DAGGER_EDITOR) and allow the user to make changes to the concrete values of the context fields. These values will then be stored incontext.cuefiles, automatically split and saved to the directory where the field was originally defined.An Example Dagger Project
main.cueInvoking the same plan across multiple environments such as
dev,stage,prod, etc. will be accomplished by writing the environment specific CUE files to a sub-directory, e.g.:./dev/dev.cuePoints to Solve
Conclusion
This proposal envisions a Dagger that is easy to get started with, easy to use, but flexible and powerful enough to solve the needs of the most advanced engineers. While there are plenty of low-level implementation details to work out, the overall architectural design is believed to be sound.
Bodies of Work
Branch strategy: an over arching all encompassing branch, with various feature branches.
simplify-daggerwill be the overarchiving branch. Forked branches get merged to this.While there are still points yet to resolve, I propose the following bodies of work:
arg[0]default to./--package, -pdefaults tomaininput,new,editsopsintegration@dagger(input)dagger.#Planand executes items inactionspulling what are now "inputs" fromcontextAll reactions