Repository navigation
core: mount a set of files read-only - #14872
Merged
Merged
Conversation
grouville
approved these changes
Oct 27, 2026
sipsma
force-pushed
the
sipsma/engine-mounted-files
branch
from
October 27, 2026 07:30
302cfd9 to
da3c914
Compare
Container.withMountedFiles mounts a list of files read-only in a directory at a path, each under the base name of its own path. Two files with the same name are an error, and so is the container's root: a few read-only files can't be a root filesystem. Paths under the mount can't be read back from the container, as for cache and tmpfs mounts. Mounting files together took a directory made for them: Directory.withFiles creates a snapshot, links the files into it, commits it, and gives it an owner lease and a cache result, all to be mounted once. A Go build that mounts each package's imports this way pays that for every package. A files mount makes none of it. The container holds the files as dependencies, as it holds a volume, and the exec links them into a directory of its own, on the snapshots' filesystem so the links are hard links, and binds that directory read-only. The engine removes directories left by execs it didn't finish when it starts, with the executor's other leftovers. Signed-off-by: Erik Sipsma <[email protected]>
Regenerated with go test ./core/schema -run TestBaseSchemaAllowlist -update. Signed-off-by: Erik Sipsma <[email protected]>
sipsma
force-pushed
the
sipsma/engine-mounted-files
branch
from
October 27, 2026 12:53
75e0383 to
8886d8b
Compare
This was referenced Oct 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This adds
Container.withMountedFiles(path, sources). It mounts a list of files read-only in a directory atpath, each under the base name of its own path, without first copying them into a new directory.Why
Mounting several files together took a directory made for them.
Directory.withFilescreates a snapshot, links the files into it, commits it, and gives it an owner lease and a cache result, all for a directory that's mounted once. If the client hasn't asked for that directory yet, it also costs the client one more request for its ID before the exec's own request.A Go build that compiles each package in its own exec mounts each package's imports this way, so it pays this for every package. In a cold build of dagger's CLI, that's about 9.6 ms of engine time before each compile on the critical path, and 9–10 s of engine time over the build.
What it does
The container holds the files as dependencies, the way it holds a volume. When an exec starts, the engine:
Directory.withFilesuses, so the files are hard links where the filesystem allows;There's no snapshot, owner lease or cache result for the set.
When the engine starts, it removes directories left by execs it didn't finish, in the same start-up cleanup that removes the executor's leftover
hostsandresolv.conf. These directories have to live on the snapshots' filesystem for hard links, rather than in the engine's temporary directory like other per-exec scratch space. Leftovers would otherwise keep deleted snapshots' files on disk.Semantics
Directory.withFiles.withFileslets the later replace the earlier; for a mount, that would hide a wrong input.Container.directoryorContainer.file, as with cache and tmpfs mounts. The files are the ones passed in.What it changes for users
withFiles:withFiles+ mounted directorywithMountedFilesAWS c8gd.4xlarge (arm64, 16 cores), one fresh dev engine per build, 3 interleaved builds per arm. The module's two versions differed only in that one call. Top-level requests per first build fell from 5,170 to 3,837, the directories' ID requests.
Tests
TestWithMountedFiles(core/integration,TestContainer) checks:It runs in CI's
test-split/test-containercheck.Rebased onto main after #14871, with one conflict in core/integration/container_test.go: both sides added a test at the same place, and both are kept unchanged. Rebased again after #14875, with no conflicts.