Repository navigation
Description
This issue was previously named "engine drivers", but "compute drivers" is proving more clear.
Problem
The Dagger CLI has a builtin “compute driver”: a software interface which allows it to install, run and manage a the Dagger Engine as a container. This compute driver cannot be customized or swapped out: it always uses the docker CLI. Users who need to customize how or where the engine container is run, simply cannot use it. Instead they must manage the engine container themselves, which is cumbersome and will only get worse as the engine becomes more ephemeral.
See also:
Solution
Allow users of the Dagger CLI to swap out the default compute driver, by either selecting a builtin alternative, or loading their own.
Use cases
This is a non-exhaustive list of known use cases for engine drivers:
Alternative container runtimes
The builtin engine driver invokes the docker CLI. A common request is to run Dagger without a hard dependency on docker. Alternatives that have been requested include:
- Podman
- Nerdctl
- Kubernetes
- Firecracker
Remote runner machines
An increasingly popular production architecture is to run the Dagger Engine on remote machines, and configure the CLI to connect to them remotely. Currently this requires an experimental environment variable: EXPERIMENTAL_DAGGER_RUNNER_HOST. Compute drivers could be used to stabilize this feature: each driver would be responsible for discovering, connecting to, and establishing a secure channel to, the remote compute.
Developing the Dagger Engine or CLI
When developing the Dagger engine or CLI, running the dev version involves a wrapper script to make sure the Dagger CLI runs the correct version of the engine. This wrapper could be replaced by a special "dev mode" compute driver.
Design considerations
Standardize on containerd?
As far as I know, the consensus is to standardize on containerd as the compute interface for running the engine container. In this design, a compute driver would be responsible for giving the CLI access to a containerd daemon which it can use to run engine containers.
Open questions:
- Is the above still the consensus?
- How much work is required for the engine internals to make this possible?
- Do we wish to ship a stopgap version of this feature before the standardization on containerd is complete? And if so, what does that look like?
Activity
[-]Customize engine with `dagger run`[/-][+]Swappable Engine Drivers in the CLI[/+]shykes commentedon Aug 7, 2023
FYI @gerhard
gerhard commentedon Aug 7, 2023
Thoughts on the problem
I definitely see the problem.
As soon as the CLI stops managing the Engine, the burden falls on the "ops person" to ensure that the CLI/SDK run against the correct Engine version. This brings further complications, e.g.:
Ultimately, this results in poor DX, which I know is super important to us.
Thoughts on the solution
Allowing users to select from various built-in Engine provisioning mechanisms is essential for good DX.
dockerseems like an important built-in provisioning mechanism - not sure about the default one, but let's put a pin in this for now.A built-in
k8sprovisioner is something that I would be excited to contribute.As for a built-in
flyprovisioner, this could be a good start: https://github.com/thechangelog/changelog.com/pull/471/files#diff-1fd071d093832bcb6c4a3a4c9d5b3740a0a71a68a42a8a52b422e43e7c84f12cThoughts on the design / implementation
I think of this as client-side Dagger pipelines since there is no Engine to run these provisioners in. I can also imagine a world where we have an Engine built into the CLI by default, but I remember us looking at this in the past, and it not being straightforward enough. FTR:
The reason why I strongly believe that we should approach the design as a DAG problem is because:
Afirst, but fall-back toBwhenAfails (there is no doubt in my mind that it will at some point)A&B, first Engine runtime to complete my pipeline wins, I don't care which oneI have already implemented the first scenario in GitHub Actions YAML, and the DX didn't feel right: https://github.com/thechangelog/changelog.com/blob/6bf40eed0a0cc6400f69b30bf4fe45dc7e419431/.github/workflows/ship_it.yml . This outcome was worth it though:

The above is the provisioning DAG that I think I would really enjoy implementing with Dagger one day 💪
In terms of design / implementation, what are your thoughts on a Zenith-based extension @shykes?
marcosnils commentedon Aug 8, 2023
👋 another use-case for this discussion about engine autostart once the machine reboots but before connecting to a VPN which breaks networking:
https://discord.com/channels/707636530424053791/1138365590290038794
aweris commentedon Aug 16, 2023
🙌 having a custom engine without hassling a custom wrapper would be great.
☝️ I would love to see this. This would also solve the issue overriding the engine container if you have two different versions of the
daggerwhen you're executing a pipeline.shykes commentedon Aug 17, 2023
@gerhard I think it's a cool idea to have dagger pipelines to provision the dagger engine, but I think we should avoid making that a core requirement. I think an engine driver should be something you can implement with just a shell script. Then of course, it should also be possible to create an engine driver that under the hood runs dagger pipelines on a bootstrap engine.
shykes commentedon Aug 17, 2023
I updated the issue with known use cases.
shykes commentedon Sep 19, 2023
👋 @jedevc
[-]Swappable Engine Drivers in the CLI[/-][+]Compute Drivers[/+]shykes commentedon Feb 5, 2024
FYI @gerhard @sipsma @jedevc I gave this issue a fresh coat of paint, so we can use it to advance the discussion started in #6486 .
shykes commentedon Feb 5, 2024
@jedevc I'm picturing this compute driver as squarely standardized on containerd. You mentioned a possible stopgap, that would allow us to ship something to users before the full engine refactoring is complete. Could you share your latest thoughts on this?
jedevc commentedon Feb 6, 2024
Hey, sorry this has sat for so long - I tried to get some stuff kickstarted in #6288, to provide the foundations for this work (I'll try and kick that today, and get it merged soon).
Ok, so sort of. To quote from https://github.com/containerd/containerd/blob/main/SCOPE.md:
There is (by design) no remote containerd API - so we can't just "expose a containerd socket" and speak the containerd API, we need a layer on top of this.
I see a couple of potential ways forward:
I don't think running the CRI is that much more work tbf, so I'd be tempted to push in that direction.
Note
We'd be using the CRI API from the dagger cli to spawn dagger engines, but still using the containerd API from within buildkit. Potentially, it could be fun to have buildkit implement a "CRI worker" one day, but this maayyyy be tricky, since CRI can be remote (and pretty much all of buildkit assumes that a single host - though we need to break this assumption to do clustered buildkit one day anyways).
Before going too far down the CRI idea, we'd need to check that this definitely works, and that it definitely can be used remotely 🤔
So assuming something like the CRI, what would this look like? An illustrative example:
Now, we have a gRPC CRI API! We can use this to start/stop containers, pull images, etc.
But, suppose we start a dagger engine container - how do we connect to it?
Potentially, for cases where we know we can create a direct access (like containerd-in-docker), we could do this:
The compute driver for docker could start the containerd service, and map all the unix sockets to the host, so we would know how to access it (note, this only works for docker engines running locally!)
For a potential service that had a dagger-compute-driver, this might be implemented over the internet:
The compute driver for this service would start the containerd service directly on the host, and then the CLI (through the CRI) can ask that the ports would be exposed on that endpoint.
Then, suppose we had a much more complicated case, where we didn't have an
accessimplementation:For this case, we could create a tunnel through the CRI, using either
PortForwardorAttachfor these https://github.com/kubernetes/cri-api/blob/c75ef5b473bbe2d0a4fc92f82235efd665ea8e9f/pkg/apis/runtime/v1/api.proto#L95-L98. These would only be a backup option ifaccesswasn't implemented, since it has pretty substantial perf implications.Agh - so, we kind of could, it would be very simple to add a little command line adapter to #6288.
Here's an illustrative example what this could look like pre-engine rearchitecture:
Instead of having a
--containerd-version, we have a direct--dagger-version. Instead of spinning up a containerd API, the driver is instead responsible for spinning up a dagger instance directly.We could do this pretty easily - whether we should or not depends on a couple of non-technical constraints:
Bikeshedding the name of this is probably not the most important part at this stage, but - to me compute drivers conjures images of other drivers - like network drivers, storage drivers. None of these really make sense in terms of the engine.
I think engine driver still makes the most sense to me, but would also be happy with:
jedevc commentedon Feb 6, 2024
One other thought about this - one of the big open questions around drivers for me is how we should handle lifetimes.
Who manages an engine's lifetime?
Or we could simplify this and just kill engines as soon as they're not running jobs, but this does mean that then we actually need to work out how we can avoid the caching service bind mount syncronization at every startup.
jedevc commentedon Feb 6, 2024
Just had a scratch idea, could we do all the CRI magic without needing a huge engine refactor? The thing we didn't like before was the idea of doing lots of extra nesting - but in reality, I wonder if this is actually as non-performant/weird as we think - it's just namespaces. If we're okay with the nesting, we could do this really easily:
runccontainersThe only extra step is the CRI layer. We could just... nest one more time. This would avoid needing to refactor everything, and do all the weird containerd mounting (with rootfs propagation), and refactor all of our networking.
I might try taking some measurements here if this seems interesting - it would potentially avoid us needing to spend months on a huge low-level refactor which would likely add lots of nasty bugs.
shykes commentedon Feb 6, 2024
My assumption has been the CLI. But important that we discuss this vigorously, and get consensus. It affects everything else in the design.
I think having the CLI manage it is the best option. Managing the engine's lifecycle is delicate to get right, with lots of edge cases to worry about (how to handle crashed clients being one of them). IMO that should only implemented once - which means in the CLI. Pushing it to drivers would be too much work per driver.
I don't have a good answer to garbage collecting, but that seems solvable (the process inside the container could terminate after a set period; the inert container itself could be garbage-collected later)
I didn't understand this part. Couldn't be add to the CLI support for running different versions of the engine?
All the downsides of CLI + extra redundant work per driver.
Engine can't clean up its own container.. Can't manage multiple versions of itself... Can't decide whether to reuse a pre-existing container vs. start a new one.
Compute driver should be responsible for provisioning the compute (up to containerd/CRI(?)). But IMO not responsible for what runs on top.
I don't have the answer to this, but the CLI seems like the best place to try and implement a solution.
jedevc commentedon Feb 6, 2024
Potentially it's this simple:
However, we probably want to allow each engine driver to set the "timeout". e.g. for local docker instances, there's no harm in having this be quite long, but for a cloud-compute backend, where each instance could be costing money, we'd probably want to have this set lower (minutes instead of hours).
We could do this through another command to the driver something like
dagger-compute-driver config, which would output a JSON blob to allow custom configuring some of the connection behavior in the CLI.shykes commentedon Feb 8, 2024
@jedevc the CRI + nesting approach seems promising! Take my opinion with a grain of salt since I'm not aware of all the complications of either nesting or containerd backend change. But I'm curious to find out more! wdyt @sipsma ? Worth investigating this while you're on vacation?
gerhard commentedon Feb 12, 2024
I am not convinced about adding more layers to our stack.
Today, most of us run a Dagger Engine container in Docker which runs in a VM. Some run Docker on Linux directly, and skip the VM layer. Either way, we end up with:
If we standardise on
containerdas the default runtime, then we would have:This makes me wonder about:
containerd? CVEs, new features, upgrades, etc.containerdhas available?containerdhave on services in Dagger?Instead of following on the
containerdpath, I am tempted to redirect this conversation towards what it would take to implement the following DX:This DX implies support for:
DAGGER_RUNTIMEDAGGER_RUNTIME_VERSIONI would also introduce
DAGGER_HOST(an iteration on_EXPERIMENTAL_DAGGER_RUNNER_HOST) and only supportunix://andtcp://.Are we OK to continue in this direction, or should we sync on the
containerdapproach @jedevc? If you feel strongly about it, I am more than happy to load synchronously - 1:1 - on thecontainerd& CRI context which I may be missing.The stopgap that I am thinking is implementing compute drivers via modules. We still need an Engine to run these, but we already have that today, so this wouldn't require any changes in the Engine itself. What are your thoughts @shykes on a compute driver module?
shykes commentedon Feb 15, 2024
@gerhard the idea is that almost always, there is already a containerd in the stack. It's the most ubiquitous and reliable container runtime imout there. With CRI we potentially keep the option of also supporting other runtimes (I think? @jedevc ?). So I don't think it's accurate that it would add layers to the stack.
jedevc commentedon Feb 15, 2024
I think there's two pieces of work here that are both important to clarify:
While scoping this out, I wondered - could we just ignore the stateless engine and have all this logic in the compute driver? I think that's what you're suggesting @gerhard.
I think this works for super simple setups, like
dockerorpodman- but starts to work less well when trying to deploy dagger at scale: e.g. how should I deploy a helm chart in my kubernetes cluster that manages dagger? If I have to pick a version of dagger, then the CLI can be out of sync - which is the whole thing we want to avoid.So here are the ways I can see of "collapsing" versioning:
remotedriver, instead of thekubernetesdriver.The last option seems like the most reasonable to me - but maybe there's some other options I'm missing.
Depends - I suspect we should ship a "dagger runner helper", and bundle containerd ourselves. This would be a separate component, we version it separately, and track containerd releases as closely as possible.
For advanced use cases, users can always run it themselves.
I'm not sure this affects much. The engine itself should actually have relatively low overhead, the main expense is in the build containers that are actually being run: and in this model, we're still running roughly the same number.
Eventually, we should aim to specify limits not for the engine, but for the build containers that are spun up on demand. This requires new config options, new apis, etc, but IMO, this would be the way forward.
Depends on whether we're okay with that extra layer of nesting. If we have it, should not really have any affect, if we don't, we might need to do a bit of hackery 🎉
Obviously, services wouldn't be able to talk from one engine to another, but I think that's fine and expected.
The big one for me about this new architecture idea is that it does have rather profound impacts on how we might add rootless mode one day. Containerd rootless is a thing, but then if we're nesting more containers, that might be painful.
Potentially this isn't really an issue - we could just require that rootless in the future use "direct connect" (connect directly to the dagger version you need, instead of going through containerd).
I had a fun idea just now.
What if we could kind of get the best of all the worlds? Here's the idea:
tcp/unix/etc as "low-level connection protocols" - these take an address.containerdorcrias "higher-level connection protocols" - these take an image name (similar todocker-imagetoday), as well as a way to connect to the CRII quite like this idea, since it means the CRI connection bits would just exist as "another" way of connecting.
The CLI gets it's way - for almost every case (except direct connect with low-level
tcp/unixconnections to a dagger instance), it can spin up it's own container version, either through the CRI, or through some higher level API.In this world:
gerhard commentedon Mar 4, 2024
After a long absence, I am trying to load all this context. The thing which I am missing right now is a whiteboard session. I am trying to re-create that here:
flowchart LR CLI subgraph "Container Runtime" subgraph dagger-runner-helper subgraph containerd EA[Engine A] EB[Engine B] end end end CLI -.-> |provisions| dagger-runner-helper CLI --> |runs against| EAIf the above diagram is correct, where do the following components fit?
I have a lot of follow-up questions, but my focus is to resume this, not to be comprehensive. I suspect that some sync time with @jedevc would help us make quicker progress. Reaching out via DM to organise something.
gerhard commentedon Mar 7, 2024
CLI controls which version of the Engine gets provisioned.
A Compute Driver is a
daggerCLI plugin..dagger/driverswith e.g.dockerbinary,kubernetes, etc. Versioned separately from the CLI. STDIN/STDOUT with anet.Conn. Could be a simple shell script.jedevc commentedon Mar 7, 2024
Synced with @gerhard, just wanted to write up some of my notes:
Agreed that the purpose should be to provide an agnostic way of provisioning dagger engines - not just tied to the docker CLI. Additionally, this should provide part of the solution for collapsing versions - where the version of the CLI dictates the version of the engine.
We discussed what the DX should look like - should we have an explicit
dagger provisioncommand, or should this be implicit? How should a driver be configured?We ended up on the code snippet above, where a user can set an environment variable (naming hard ofc), pass a flag, etc with a URL. The URL scheme is the name of the driver of lookup in
~/.dagger/drivers, while the rest of the URL can be user-defined (just similar to buildkit's connhelpers today).We discussed the complexity of interacting with pre-provisioned environments - where we would connect directly using
tcp:///unix://or even to our own CI environment. My end proposal for this would be to:We discussed that we liked the idea of it being very simple to create a driver - something as simple as a shell script. This does limit the interface a bit, but makes the barrier for entry very low.
We discussed the issue of lifetimes and implicit vs explicit provisioning. If a
dagger call/etc causes an engine to be provisioned, when should it be shut-down?clientexits, some might want to configure the engine to terminate after some amount of time after no builds have been run.docker-imagegarbage collection today, and secondly, they require some sort of shared state/synchronization - which not every driver would be able to do.In general, I think we're on a similar page:
If we do this, I have funny little idea - I'd like to (personally) make a
cri://driver. All that would do would allow provisioning dagger engines through the CRI interface as we discussed above.Now, this would potentially be another (a bit more limited) way to deploy dagger in kubernetes:
Small thought that came up as a little implementation detail that I had in discussion with @sipsma and @shykes: how does this interact with clustered dagger / dagger module versions / etc.
One thought I had is that for this, we could create a new session API that the client exposes to "spin up a new engine with version X" - when a dagger instance wants a new node (maybe for more compute power, or maybe with a different version, or a different architecture), it could use this session API to create the node.
For pre-provisioned instances, we obviously couldn't do that - but there's some options there:
shykes commentedon Feb 9, 2025
Resurrecting this thread in the context of #9516 .
I worry that we have not made progress towards consensus on these issues. cc @gerhard @jedevc @sipsma