Repository navigation
Description
Related discord thread: https://discord.com/channels/707636530424053791/1174585230649217055/1174847141265547324
Problem
We've accumulated quite a few new CLI commands as part of module support:
calldownloadshellupmod
In addition to some existing ones that have varying degrees of conceptual and/or implementation overlap
runquerylisten
It's becoming overwhelming and convoluted. Examples of confusion:
- There's 3 ways of running a container that are all subtly different:
call,shellanduptechnically all give you ways of running a container but with different features and behavior in terms of caching and what is actually executed in the container. - It's not always clear whether what you are operating on for a given command is just the final return value, the pipeline, or both
As part of this there's also been a point raised about trying to minimize the cases in which users feel compelled to wrap the CLI in complicated shell scripts. We don't want to make that impossible or anything, but in general it seems we're all of the opinion that the functionality we provide in the CLI should ideally minimize cases in which users even feel compelled to resort to complex shell script wrapping.
@shykes summed this up as:
- The CLI should be a great entrypoint: an intuitive and painless way to run pipelines with Dagger, even if you're not an expert.
- The CLI should be a good swiss army knife for power users who want to poke at a module without writing code. Debugging, troubleshooting, inspecting, etc.
- Non-goal: extreme composability, ie. your shell is now a Dagger SDK
Solutions
There's quite a few possible solutions here, and it's entirely possible the end result will be some combination of a few different solutions.
One of the top ideas currently is to consolidate as many commands as possible to a single command, with different behaviors triggered by different flags. @shykes gave a hypothetical example of consolidating around run:
dagger run --print-> just print information about the result to the terminaldagger run --export TARGET-> save the result to the local filesystem, or a remote registrydagger run --exec-> execute the result (default behavior for container results)dagger run --exec-command-> change the command to execdagger run --exec-interactive-> change whether to attach an interactive terminal on execdagger run --exec-port PORT-> forward ports on execdagger run --up-> bring a service up (redundant with exec?)
In general, consolidation in some form or another seems like a baseline requirement for any solution.
As an example of one other variation brought up: we could decide that there shouldn't be any commands whose purpose is to just "run a container" and instead require that pipelines always operate on scalars (or "simple objects" consisting only of scalars). This could look like:
dagger call- call the dagger API, including any user modules loaded into that API (must be a pipeline that ends in a scalar or simple object)dagger debug- the functionality ofshellanduprolled into one command whose focus is on debugging pipelines rather than just "running containers defined by the API"
There's of course many other viable variations on all of the above possible too, just throwing out the suggestions brought up so far.
Intertwined issues
There's also quite a few open issues/discussions that feel to me like they are potentially related and are worth considering alongside all of this. It's obviously ideal to keep decisions + designs self-contained if possible, so just bringing these up in the case that they end up overlapping to the point that they can't be self-contained:
- Support for the
coreAPI in the CLI- This especially seems highly interrelated because support for
corewould imply that a function that returns, e.g. aDirectory, could be chained with theexportAPI (dagger run ... export --path ./where/i/want/the/file), which could eliminate use cases fordownloadand/or an--exportflag on a consolidateddagger runcommand.
- This especially seems highly interrelated because support for
- With* pattern translates awkwardly to CLI
- This problem makes me question if the overall api chaining approach in the CLI needs general re-thinking (not sure, many possibilities here but worth consideration)
- Make passing caller environment variables to modules more seamless
- This may end up orthogonal, but if we decide on a solution that involves a formalized difference between
mainandlibrarymodules this will definitely overlap (see below)
- This may end up orthogonal, but if we decide on a solution that involves a formalized difference between
mainvs.librarymodules- This is still just a vague idea that gets brought up a lot in various threads/issues, so it doesn't have a dedicated issue yet
- The idea is that we could formalize the difference between modules meant to be invoked directly by end CLI users (
mainmodules) and modules meant to be used as libraries by other modules for re-usable functionality (librarymodules).mainlibraries would potentially have special features around interaction w/ the caller and possibly restrictions in terms of the APIs they expose in order to optimize them for a CLI UX - If we do end up going down this route, it definitely could have an impact on the command structure
- dagger script: invoke any function from any module, in your favorite language, from the CLI
- Basically, we may want to support both language snippet one-liners as an alternative to posix-y commands+flags in addition to potential full-blown repl support
- Duck typing for CLI verbs
- Also entangles in interface support
Activity
sipsma commentedon Dec 13, 2023
Finally had time at the end of today to start diving into this. Have just done some more thinking so far, want to checkpoint with one other promising line of thought building off the previous discussions.
One potential issue with consolidating everything to a single (or even small set) of commands is that we'll be trading "command bloat" for "flag bloat".
i.e. if everything is done via
dagger run+ flags,dagger run --helpwill show a ton of flags and whether those flags are even applicable can't be known yet (certain flags only make sense for certain pipeline "return values").I can imagine in the long term this growing more and more. E.g. we start with
--exportbut then someone wants a pipeline that results in a directory to not be written directly to your host but instead be written as a.tar.gz. Then we need to choose whether to say "no" or to add another flag like--export-tarball.This is not a deal-breaker per-se, but does seem like a legitimate downside to this sort of approach worth noting.
Idea - Chaining is all you need
One potential way to both consolidate commands but also not bloat with a ton of top-level flags is to start with the idea of adding support for the core APIs to the dagger cli.
Say we do both that and consolidate everything to
dagger run.That by itself would make the following work out of the box:
The above works because the core API's
Fileobject already today has a function defined on it calledexportthat accepts an arg namedpathand results in the file being written to the caller's filesystem at that path.Basically, there's no need for
dagger downloadordagger run --exportbecause we inherently already have that functionality due to it existing in the core api as a function already.Publishing an image would look like this:
A few of our current top-level cli commands don't quite fit as nicely as those, but I think they could with small adjustments (and with the help of some more ideas I'll mention later).
e.g. with some adjustments to the core api
dagger shellcould becomedagger upcould perhaps become something like this with some core api adjustments (pending bikeshedding, just a strawman to get idea across)dagger calljust sort of melds seamlessly intodagger runas part of this too.In this model, the CLI would have the rule that the pipeline specified ends in a scalar. So you can't just specify a pipeline that ends in
Container, you must choose something from the container or run a function that is "side-effects" only (aka void return type).To be clear, there still may be some top-level flags under
dagger run. Flags for controlling the progress output could still be there for instance. But they would be much more limited in long-term scope by being solely focused on flags for the CLI itself.Pros
dagger runthat may or may not actually work depending on the pipeline that actually gets run. Only valid subcommands are available for each function in the pipeline.Cons (with possible mitigations)
The Core API was not optimized for a CLI interface
One problem with this is that if a user had a module function called
my-containerthat returned aContainerand ran this:By default they'd see an outrageous amount of subcommands, including tons of
with*APIs.This is very significant, but interestingly it's the exact same problem we're facing today with user modules (i.e. #6115).
So as a small consolation it's not exactly introducing a new problem, just bringing an existing one to a head more immediately.
I don't want to go way off on a tangent here so I'll be brief, but I do see some potential ways of fixing this. One idea would be to add an advanced feature to our API that gives more custom control over what functions are visible in the CLI by default and which are hidden by default. Maybe this could be used for more than just visibility on the CLI level too.
This would be reserved for advanced users who want finer grain control of the CLI UX their crafting. However, as dagger developers we are most certainly advanced users and can make liberal use of it in the core API to customize how it's presented in the CLI.
Overall, whatever the solution here, I do like that at least we'd be solving it simultaneously for both users and our own core APIs.
Discoverability
Avoiding top-level-command and top-level-flag bloat does have the downside in that even if there's a ton of commands/flags, at least when you run
dagger --helpordagger run --helpyou get a "lay of the land" in terms of all the things dagger can do.I think this is just an inherent tradeoff that doesn't have one silver bullet solution. It can definitely be mitigated to a decent extent through a combination of:
dagger -m github.com/dagger/getstartedinteractive shell module? 🙂)dagger run --helpbuildthat returns aFile, we show two levels deep of functions available - bothbuildand the subcommands available onbuildlikeexport@shykes @helderco (and anyone else interested) thoughts? I'm still very much up in the air about all of this, but the line of thought here seemed interesting enough to share and bounce off every else's heads 😄
sipsma commentedon Dec 20, 2023
There's been some more ongoing discussion about #6229 (comment) in other mediums, will summarize here.
The overall status is that we're going to pursue that approach (with some modifications mentioned below). There's a "first step" PR here: #6293
I'll also separately start breaking this down into subissues that can be fanned out to the team once that PR is merged.
Loosening restrictions on return type being a scalar
(Discussed, among other things, in this discord thread: https://discord.com/channels/707636530424053791/1184618502699614298)
In the previous comment, I said that "the CLI would have the rule that the pipeline specified ends in a scalar".
However, that can be safely relaxed without compromising on the other benefits. Namely, what's actually important to the design is that the CLI only has one behavior for a given return type and that the behavior is consistent and non-surprising.
Container/Directory/File/etc. and we were resolving that ambiguity by adding lots of commands for all the stuff you could want to doThe exact behavior for different return types is TBD, but as a strawman:
Container/Directory/Fileare less immediately obvious but plenty of reasonable options to choose from--helpoutput asking the user to select what they want from them. There's not a requirement that all types must be handled, just an option in the design to do so now.stdoutof aContainerif that's the return type, which creates a backchannel way of running container execs that's now better served by having users actually select... stdoutif that's what they want to see from the returned container-oflag for writing to caller's filesystem(Discussed in this discord thread: https://discord.com/channels/707636530424053791/1186785873770074203)
The first important note coming out of that discussion is that even if the new approach gets rid of ambiguity + special casing around return types (e.g. what does the CLI do with a user function returning a
Directory), it doesn't get rid of the need for some special sugar handling of core types as function arg inputs.Directoryarg as--dir ./some/input/dirbut to write aDirectoryto the caller's filesystem you have to go through the whole... export --path ./some/output/dirComing out of that, @shykes brought up idea of supporting a generic
-o <path>(--output <path>in long form) flag on the CLI command. This flag would be applicable for any return type and result in that result being written to the caller's filesystem rather than written to stdout.For simple cases like a
stringreturn type, this would have the same end effect as a shell redirection. The difference is that we would allow some special case handling for it too. So ifmyfuncreturns aDirectory, this would work:and result in the the directory returned by
myfuncto be written to./some/output/dir.To start,
-owould be exclusively for writing to the cli caller's filesystem.scheme://type approach if we ever wanted to, but that's just a possible future extension point, not in scope now and just a random idea.Also important to note that this would not remove support for the full
... export --path ./some/output/dirstyle either, it would just be a supplement to it.sagikazarmark commentedon Jan 3, 2024
If I may add my two cents to the discussion:
dagger export, because it's clear what it does. I would also love to see some extra features (for example, extracting a file from a container) that may be less easy to implement and explain in call/run.shellin some cases, especially when I'm trying to debug a pipeline, but when the last command fails, I often have to change the code first, so it's not actually that useful on its own. Something likerun --shell --entrypoint <bash>replacing the last command (which is often what I'd like to replace during debugging) would be more useful to me. Having shell as an alias is also okay.docker-compose up -duser (if you see me run it without -d, I'll buy you a beer),upis less useful to me, since it requires a shell. It also requires me to restart containers when something changes (unlike docker compose with volume mounts). Although I'd really like to, I don't really see myself using it as it is right now. I might reconsider if it becomes more akin to docker compose.Generally speaking, Dagger seems to be getting close to a semi-replacement for some docker/docker compose commands. People already used to those (like myself) may appreciate similar commands and behavior in the Dagger CLI.
sipsma commentedon Jan 3, 2024
We are now planning on adding a
-oflag (--outputin long-form) that essentially triggers the same behaviordagger exportdoes today, but as a flag on the consolidateddagger runcommand rather than separate command entirely.Combined with the other adjustments that use case of extracting a file from a container should actually be possible entirely from the CLI.
E.g. if you have a function
foothat returns aContainer:dagger run -o ./output/foo.tar.gz fooContainerreturned byfooto./output/foo.tar.gzas a tarballdagger run -o ./output/some-file foo file --path /some/file/in/the/container/some/file/in/the/containerand write that to./output/some-fileThat makes sense. There's also the slightly more general problem of failures being possible in any execs that are executed as part of a function call too (whether the "final" container in the chain or not) and wanting to drop into a debug shell for any of those.
There's some under the hood technical complications that make the "drop into shell for failed exec" use case probably be out of scope at the moment just due to time+priorities, but I will keep it in mind while implementing the updates for all of this to make sure we at least keep our options open for supporting it down the line.
Makes sense too. Backgrounding services like that is a pretty significant can of worms for various reasons, but the utility is undeniable I agree and it has come up more than once. It'll have to be out of scope to this effort too but if you want to open a separate issue requesting support for it and describing the use case that would definitely be appreciated and we can keep it on our radar if nothing else.
sipsma commentedon Jan 3, 2024
The initial PR for exposing
coreAPIs indagger callis merged: #6293I created a handful of follow up issues for the rest of the major adjustments needed:
-oflag #6357--helpoutput #6358shellandupfunctionality as chainable APIs #6361idor to continue hiding #6360I'll also leave this issue open for the final consolidation to a single command we can do once those have been tackled.
helderco commentedon Jan 29, 2024
Now that we have core types chaining:
And since we’ve consolidated the commands:
I think we can close this issue and track the remaining work in their own issues.
helderco commentedon Jan 29, 2024
Note that I've added the removed commands, just to make it easier for users to know: