Repository navigation
Description
Problem
Dagger doesn't support mounting NFS directories directly into containers. Instead, the user must mount them into the client machine, and copy them from there into the engine, like any other host directory. This works reliably, but is less efficient than a direct bind-mount.
Solution
At this time there is no design for bypassing the copy into the engine. Nikola Jokic has proposed implementing support for direct bind mounts, which would indirectly solve the problem for NFS. However this opens a can of worms: the host running the dagger engine container ("engine host") may not be the same host running the dagger CLI ("CLI host"), and so far we have been careful to only expose the CLI host. Allowing direct bind mounts would break this abstraction, thus forcing us to clarify the distinction between "cli host" and "engine host" and make a series of important design and architecture decisions.
So, the first step to implementing support for NFS mounts is to resolve the underlying design questions:
- Do we want to distinguish "engine host" and "cli host"?
- If so, how do we expose each in the API? How do we explain the difference?
- How do we avoid weakening and fragmenting the platform? See for example Docker, where the engine alone is blind to the client system - it requires an external wrapper (desktop app) to bridge "client host" and "engine host".
- If we want to continue distinguishing "cli" and "engine", what do we want the protocol between them to be? Today there is an experimental and undocumented "runner host" protocol. This can't go on forever.
- Do we even want the engine and cli to be two distinct entities forever? In the past we talked about "one big binary"; and we talked about clarifying that Dagger is a container engine. To decide on the above, we probably need to decide on this too.
So as you can see 👆 the road to NFS support goes through a pretty intense set of design decisions. But these decisions have been postponed for too long, so maybe this feature request is the push we needed to get it done :)
Calling for comments! @sipsma @cwlbraa @jedevc @vito @marcosnils @gerhard
Activity
jedevc commentedon Jan 7, 2025
I'm kind of interested into diving into what the NFS mounts are going to be used for 👀
The use case determines what we'd want to build here I think - whether it can be entirely transparent, or whether there's a
dag.NFSequivalent like we havedag.Git, etc.I've also really wanted to use direct bind mounts as a way to avoid the incredibly expensive file network transfer - we could just replace it with a copy (note: keeping a copy of some sort is still somewhat required to get good consistency and caching behavior). I think it's pretty doable, since the dagger container runs as privileged.
But, the way I've previously thought about this is as just an optimization - you still wouldn't be able to write directly back to the bind mount. If the cli/engine are running on different hosts, you'd just fallback to the file network transfer we use today. This use case feels a bit different, but thought I'd raise it here anyways.
Not really sure on any of the other points you've mentioned, but I'd like to avoid the concept of a distinct configurable "engine host" at all. Aside from configuring some engine settings (which enable features like GPUs, or configure garbage-collection, etc), I think we should avoid having special "pet" engines (as opposed to generic "cattle" engines).
Running
dagger -m my-moduleshould work on any engine. A potentially long-running engine shouldn't need to be setup to handle special NFS mounts, it should be able to be configured on-the-fly from the caller (whether that's one binary, or still the same cli-engine split, or whether a new engine is transparently created, or an old one reused).sipsma commentedon Jan 7, 2025
I'm curious to know the specifics of the use case here, especially around how the data in the NFS mount would be used. The two categories of data we support currently are "immutable recipe-defined layers" and "mutable cache mounts". I'm guessing the use case here probably follows the "mutable cache mounts" pattern, but want to confirm. I think this actually impacts the design pretty significantly.
I can't tell yet how much this relates back to the engine/cli split. Theoretically you could just give the engine the NFS config and have it create its own mount for it (at which point it's just a certain named cache mount). But I don't mind a forcing function around that whole design either since I agree it's been in limbo for too long.
EDIT: after posting my comment the page reloaded and revealed Justin's comment, sorry if I'm duping anything 🙂
IljaKroonen commentedon Jan 8, 2025
We run Dagger on hosts with mounted fileshares used for file uploads/downloads. Programs may read configuration files from these shares, upload files for external API processing, or download files generated by APIs.
Currently, this workflow isn't supported in Dagger, restricting its use to a subset of CI workflows.
Yes to both. These fileshares are too large to copy, and we need read/write capabilities for specific use cases.
Regarding the "one binary approach," I don’t foresee use cases requiring the engine to run separately from the client for our scenarios.
shykes commentedon Jan 8, 2025
@IljaKroonen have you tried copying the files into dagger from the host, with pre-call filtering to only copy what you need? I understand that the entire NFS mounts are surely too large to copy, but how much data do you actually need to copy into dagger? Depending on the answer you may not need a new feature at all, and may be able to get a solid implementation with pre-call filtering.
IljaKroonen commentedon Jan 9, 2025
We can use dagger to read and write files to and from the shares (using pre-call filtering for example, and file exports) but this means that we need to exactly know ahead of time what files we will need; and it means we need to use dagger DSLs / calls every time we need to interact with the actual share.
A typical suite of integration tests would read / write a variety of files (similar to how some other software would use S3 storage service) and we want to be able to tell dagger "run these integration tests" (which we can do today outside of dagger, for example running in an IDE and running in Jenkins directly), rather than re-implementing the test suite with a complicated sequence of dagger function calls.
shykes commentedon Feb 4, 2025
After live discussion with @sipsma, @jpadams , @IljaKroonen and team:
IljaKroonen commentedon Feb 24, 2025
After investigating this a bit more:
We would run a component that exposes the shares via SSH alongside the dagger engine - and the dagger engine would mount the shares from it. In terms of dependency, the dagger workflow itself would depend only on the network access needed to connect to the share.
What are your thoughts? I think we can come up with a design that makes it fairly easy to add more fileshare protocols, as mounting shares is done by invoking a command. Using a hypothetical DSL to mount a share inside a container inside dagger would probably do something along the lines of:
IljaKroonen commentedon Feb 28, 2025
Thinking ahead - what would this DSL look like?
If we take the sshfs example we would roughly have these inputs:
This does not generalize very well - if would require an additional DSL for each share type. We can have a driver = "sshfs" (and later NFS, SMB...) but the shape of the argument might be different due to the various kinds of inputs required (especially given there are different methods of authentication).
sipsma commentedon Mar 13, 2025
Ah okay, good to know. I'm guessing it gets into something deeply specific to your setup, but if you are able to share why it doesn't work I'd be curious to know. I did a quick hacky test with my own NFS server and hardcoding the engine to create NFS mounts from it and it worked, so just wondering where the delta is coming from.
Yeah that sounds like a reasonable fallback option. It would be very nice to have NFS/SMB directly but SSHFS is generally useful enough too that we could start there if it's what unblock you sooner. In the end support for all these different mount types can coexist harmoniously I think.
IIUC this will require that the userspace driver for SSHFS exists in the engine container. Those don't look to be very large dependencies at all (e.g. in alpine), so I'd be totally fine with updating the dagger engine base image with those.
@IljaKroonen one question though, how does SSHFS handle multiple clients mounting the same remote filesystem in parallel? E.g. if two containers had an SSHFS mountpoint pointing to the same remote would they be able to execute in parallel? If not, there's multiple ways of dealing with this in the engine, just want to check if any extra work would be involved there.
There's another general concern too around leaking "operator concerns" into "developer code". We've generally tried to avoid creating APIs that enable dagger code which can only possibly work on a single machine (or set of machines), for a few reasons:
with_mounted_sshfsthat then need to be updated whenever infra is modified and thus churn between infra operators and developers. Users can set up a bunch of plumbing to make it all dynamically configured, but that's extra work for them.That isn't a super-hard blocker for me necessarily, but I do think it's worth considering an alternative that might avoid them.
Summarizing two options below:
Option 1 -
with_mounted_sshfsThis is what @IljaKroonen proposed with:
In this approach, I'd personally prefer having a different API for each mount type vs. one API field that takes a million different config options. That takes advantage of dagger's type system more to ensure you can only provide the right config args to the right APIs. API bloat is a legit concern, but in the other approach we'd just be bloating the API in terms of random config options on a single field.
Given that, I think the example API you posted makes sense if we go this route. We'd want to make sure the
private_keyarg is of typeSecretso it doesn't end up persistently cached on disk. Otherwise they all look like strings.In terms of caching semantics, these types of mounts would be treated essentially the same as
CacheVolumes, i.e. treated as an opaque blob (not content hashed or layered, etc.). We'd probably just use theremoteas the cache key (which impacts when dagger re-runs containers that have the mount included).Pros:
Cons:
Option 2 - engine config mounts
In this approach we'd try to avoid an API that hardcodes infra-specifics as arguments in developer code.
Instead, we'd update
/etc/dagger/engine.jsonto handle a new config option forCacheVolumes. Sketched out:Then, we'd update
Container.withMountedCachesuch that if you run an engine with the above config and made a call likeThe cache volume would be sourced from the special sshfs mount configured in
engine.jsonrather than its usual source. The connection between the two is the name "my-sshfs-mount".{"file": "..."}I think this works reasonably well because the semantics of these types of special "external mounts" pretty closely matches the semantics of cache volumes anyways.
It also avoids mixing operator/developer concerns too deeply because if someone ran that code and "my-sshfs-mount" didn't correspond to a special configured cache volume, then it would still work and just fallback to the default cache volume behavior.
Then, whenever any configuration around infra needs to change, the infra operator just needs to update the engine container's config file and all other dagger code maintained by devs can continue working the same.
The only gotcha I can think of is if this configuration needs to update a lot and/or be dynamic somehow. But there's likely ways of dealing with it if so.
Pros:
Cons:
Overall I'm currently leaning towards Option 2 as my favorite, but let me know what you think and what I missed @IljaKroonen
cc @shykes @jedevc
IljaKroonen commentedon Mar 14, 2025
The environment where we run dagger (CLI and engine) does not have full capabilities - we are using the Linux user namespaces and identity mapping. We can use fuse, however.
I've tested this just now and it works fine - I can mount the same folders from the same source several times in different locations and these all work at the same time
Both approaches you propose will solve for our use case, and I'm happy with either.
In the particular case of SSHFS, we are using network access to mount the share - what case are you thinking of where this would be specific to a single machine / setup? The main prerequisite here would be for the SSH server to be accessible from the engine which feels similar to using an HTTP api from dagger (analogous to using S3).
FWIW in our case this would pretty much never change
sipsma commentedon Mar 20, 2025
Yeah when considering just purely your use case, putting operator specific details in code is less of an issue. I'm just thinking through what we'd be enabling in general since other users would obviously come up for this.
You're 100% right that our current API does enable hard-coding highly host/network specific details that aren't guaranteed to work on any machine (http, container images, a
withExecthat hits network endpoints, etc.). This isn't something we've been "pure" about in the past and have tried to find practical compromises (or just didn't really consider this whole issue at the time).However, when adding new APIs I think it's still worth seeing if we can avoid deepening these sort of problems. I think the fact that Option 2 enables operators to seamlessly update the infra-specific configuration w/out any code change to developers dagger code is a clear enough benefit to justify going with this sort of approach.
Current Status
shykes commentedon Mar 21, 2025
@sipsma I see the appeal of option 2: move infrastructure-specific concerns below the application/infra separation line. I'm asking myself 2 questions:
Are these particular infrastructure-specific concerns worth moving below the line, or are they more like the other "purity tradeoffs" you mentioned, like hostnames that may or may not resolve everywhere, etc.
Assuming they do belong below the line: should we follow the template of secret providers, our most recent implementation of moving infrastructure-specific concerns below the line? In practice that would mean: make your function take a cache volume as argument; then add support in the API for instantiating cache volumes from different providers. This removes one aspect of option 2 which is relying on volume name as a loose "contract" between infra and app layers. Smells of "shadow API" if you know what I mean?
sipsma commentedon Mar 24, 2025
This feels different to me, primarily because almost every setting of SSHFS/NFS/etc. endpoints is going to be infra-specific (there's not many or really any public endpoints for these protocols). Contrast that with hitting some arbitrary HTTP endpoint where the vast majority of usage is not infra-specific and thus makes the appeal of purity far lower.
Additionally, I think the benefit of this approach is pretty clear cut in the example where users can write dagger code w/ no infra-specific config and infra operators can modify it by just updating the engine config file. That saves users from the choice of:
That entire problem is just entirely eliminated in this approach.
Yeah I like that idea. I think with the right approach we can also retain the niceties mentioned above but in a way that's easier to implement iteratively.
Fleshing out with some more details:
Do go with the approach of different APIs for each type of mounted filesystem, e.g.
sshfsVolume(endpoint: String!, user: String!, privateKey: Secret!, publicKey: String!): CacheVolume!Do not allow function implementations to call
sshfsVolume; they must be provided as aCacheVolumeargument if used.The above should be enough to satisfy the most basic use cases.
To get more polish we can iteratively add support for reading the volume configuration from the engine-wide config and/or user-config, somewhat conceptually similar to
.envsupport for secrets.@shykes is that aligned with what you were thinking?
shykes commentedon Mar 24, 2025
Follow-up questions:
sshfsVolume()would only be available to external clients, kind of likehost()? And similar to my proposal for secret providers, which we punted on for now?dagger call)?Volumemore than aCacheVolume. Perhaps we could define a newVolumetype, and make it an interface so thatCacheVolumecan retroactively implement it?sipsma commentedon Mar 26, 2025
Yes
Use from an SDK executing directly on the host is a viable option too. But in terms of the CLI, yeah for a first iteration I'd be totally fine w/ just needing to use shell.
What I mentioned "to get more polish we can iteratively add support for reading the volume configuration from the engine-wide config and/or user-config" would be an improvement and make it easily configured in a file and then referred to by name/identifier in any CLI command. But that doesn't have to be part of a first iteration necessarily.
IljaKroonen commentedon Mar 28, 2025
What does "needing to use shell" entail? In the model we currently use, Jenkins invokes a single dagger function (using dagger call) and passes in the git repository and auth. What would this look like if we also wanted to make a directory available under your proposal?
sipsma commentedon Mar 28, 2025
It would be something as simple as e.g.
dagger calljust has the limitation that it's hard to provide complex objects created by other API calls as args, whereasdagger shellhas the syntax support that makes it easy.Generally speaking, any
dagger callcan very easily be translated to an equivalentdagger shell -ccommand, so this shouldn't require any big changes.shykes commentedon Mar 28, 2025
Basically, the dagger shell supports explicitly passing the output of one function as argument to another, using the familiar subcommand syntax of the bash syntax. For example:
This also works for host access, which is part of the Dagger API like everything else:
But,
dagger callon the other hand does not support this kind of composition. So as a convenience, it will decode command-line arguments in a type-aware way: depending on the type of each argument, the corresponding CLI arg will be parsed differently:Directory, the CLI will allow git URIs likehttps://github.com/dagger/dagger#main:/docswhich it will resolve by callinggit()etc. Or of you provide a local path, it will resolve it by callinghost().directory().Secret, the CLI supports URI schemes likeenv://,op://,vault://, etc.What we were discussing here was: should we implement a similar convenience for arguments of type
CacheVolume, where URIs likesshfs://are supported, and if so, what should the URI format, can it fit all the allowed parameters without becoming too complex etc.OR do we skip implementing the CLI convenience, only implement the underlying API call - but without that convenience
dagger callwill not have the ability to create those volumes.dagger call my-function --my-volume=sshfs://foo:bar#baz?a=b&x=ydagger -c 'my-function --my-volume=$(sshfs-volume foo:bar --name=baz --a=b)I hope this helps!
sipsma commentedon Mar 28, 2025
Given any convenience like that can be layered on later backwards-compatibly, I will leave it up to whoever implements this to decide if they want to pursue that. I'm fine w/ skipping it to start though.
Excluding the above, are there any blockers left on the design for you @shykes? If not, I can do a final summary of all the above and it'll be ready to be implemented
shykes commentedon Mar 28, 2025
Yeah no blockers from me, it boils down to:
Volumetype, since these new backends have very different persistence properties (not best effort in the same way) so now might be a good time to shed the baggage of the word "cache".Other than that, I agree with the direction.
sipsma commentedon Apr 10, 2025
Yeah I want there to be APIs for each volume type, if that's what you're getting at (
sshfsVolume,nfsVolume, etc.)Really no strong opinion on this. I feel like it can be safely saved until it's desired by anyone. In the meantime invoking from
shellor an SDK on the host suffices.Sure, yeah that makes sense to me. Probably what it should have been named in the first place, hindsight being 20/20 and all that.
So to summarize:
API would look like:
We'd block
sshVolumefrom being called in modules; only callable by the main client on the host.To start, would be invoke-able either from an SDK running on the host or, if using the CLI, like
cc @IljaKroonen
sipsma commentedon May 8, 2025
Local dev docs can be found here, but will outline some more pointers specific to this effort.
cc @IljaKroonen and team
Implementation
Will give a high-level outline here, obviously happy to fill in details as needed.
API schema
We'll want a new
Volumetype and associatedQuery.sshfsVolumeAPI for creating one.core/andcore/schema/packagesCacheVolumeAPI as an example, important parts areQuery.cacheVolumeconstructor for the typeYou'll also want to add
Container.withMountedVolumeContainer.withMountedCacheAfter setting up the above and any subsequent API changes you can regenerate SDKs to make the new APIs available to clients.
dagger call sdk go generate export --path .(run from the root of the dagger repo)dagger call sdk all generate export --path .Plumbing + Mount Setup
ExecutionMetadatatype with metadata on which SSHFS mounts existExecutionMetadatasetup earlier is available asw.execMDTesting
Can add a new integ test anywhere in
./core/integration.If you for example add
func (EngineSuite) TestSSHFSVolumetoengine_test.gothen you can run just that test withThat will build the engine from your local changes, run it as an ephemeral dagger service and execute that test against it, all in one command.
An alternative I often follow is to build a dev engine and run it in docker standalone and then execute tests against it. This has the advantage of being easier to debug since the engine is long-running rather than an ephemeral service. To do this:
./hack/devrebuilds the engine from your local changes and deploys it into docker (nameddagger-engine.dev)./hack/with-dev go test -v -run TestEngine/TestSSHFSVolume ./core/integration. Can re-run tests as needed w/out rebuilding the engine necessarilydocker logs dagger-engine.dev, exec into the engine withdocker exec dagger-engine.dev sh, etc../bin/dagger(from the root of the repo); it will be rebuilt by./hack/devalongside the engine and connect to thedagger-engine.devcontainer automaticallySetting up the test will be a bit intricate since it'll require running an sshfs server that's available to the engine.
If you just want to get going quickly you could just setup your own sshfs server on the side and run tests locally against that for now.
But for the final merged PR we'll want the tests to work standalone. Can figure out details later but a basic outline would be:
devEngineContainerutil to get a dev engine as a dagger containernikola-jokic commentedon Sep 23, 2025
Hey @sipsma, @shykes,
I managed to make the volume mount shared from the host, but I have a few issues I'd love to discuss about the design.
Depending on the answers, I can continue implementing this feature. So far, I've used the host mount inside the engine. That is assuming that the directory is already present. Now, I need to build on top of it, which leads to these concerns.
CC @IljaKroonen if you have anything to add, please do☺️
sipsma commentedon Sep 29, 2025
I don't follow. It would be perfectly fine for the engine to mount the sshfs once and then share that mount by just bind mounting it into each container that needs it. Where would that not work with the container API?
It's totally fine for the engine to have a dependency on sshfs/fuse/etc. You can update the engine container to install any deps (./cmd/engine/.dagger/builder.go)
IljaKroonen commentedon Sep 29, 2025
I think I might have misunderstood what the DSL does in the design above.
For example if I call
My interpretation would be that this does not do anything besides storing the values passed, such that the mount actually happens when mounting inside a container process executing a command.
But I think you are saying it would actually run the mounting upon being called?
This creates some further questions - what if I call it twice? Does it reuse based on the arguments being the same? What about unmounting?
IljaKroonen commentedon Jan 30, 2026
I can confirm that Nikola's patch is working for our use case.
You can see it here: https://github.com/G-Research/dagger/tree/nikola-jokic/sshfs-volume
Both these methods in there are suitable for us:
WithMountedHostDirectoryalso achieves what we want pretty much directly but my understand from the above that we would like to avoid exposing this kind of primitive (I think the name could be more explicit too, maybe it should be named WithMountedEngineHostDirectory or something like that)(The reason we are fine with WithMountedHostDirectory is because the directory we mount is always the same - but that might not apply to other users so I can see how SshfsVolume makes more sense for the dagger project and its design)
We're looking for feedback on getting the capability merged in. What next steps do you suggest? Is there anything we should make sure of before contributing back SshfsVolume (or WithMountedEngineHostDirectory) ?