Repository navigation
Description
Motivation
I have to constantly add "exclude": ["sdk", ".venv"] to dagger.json after dagger init.
I don't expect these files to be uploaded. They're not completely replaced in codegen. During local dev, some files can be created in there and they will stay after codegen in the container. It affects the Source dir cache and slows down module loading.
Solution
The engine already loads dagger.json first. Load .gitignore too. Prepend the .gitignore patterns to the exclude patterns from dagger.json when collecting the patterns for loading the module’s files.
As an escape hatch, if the user needs to include something in .gitignore they can add the same pattern manually to include in dagger.json.
Rationale
This seems like the easiest solution, with less work for the user but keeping control.
Doesn’t require extra work. Most modules in the Daggerverse have the automatically generated .gitignore but no patterns in "exclude". By using .gitignore, those modules would benefit automatically. Of course, this is only necessary when dagger developing modules locally.
When a module is loaded via a git reference, those patterns are already applied because the git clone won’t have those files. So using .gitignore is actually more consistent because it avoids differences in dirty working copies.
It’s still possible to have dirty woking copies because global ignores won’t be picked up, but rather than adding some of those to exclude, users might as well just add them to .gitignore which also helps other users contributing to a module that don’t have the same global ignores.
It’s also possible for files in a module to be ignored by some other .gitignore up the file tree until the git repo root, but we could automatically find those and add their patterns, prefixed with their file path relative to the context directory, to the module’s excludes.
Activity
[-]Zenith: GeneratedCode.VcsGeneratedPaths should be added do `exclude` in `dagger.json` by default[/-][+]`GeneratedCode.VcsGeneratedPaths` should be added do `exclude` in `dagger.json` by default[/+][-]`GeneratedCode.VcsGeneratedPaths` should be added do `exclude` in `dagger.json` by default[/-][+]Runtime modules should be able to configure default excludes in `dagger.json`[/+]helderco commentedon Jul 5, 2024
@sipsma, I updated the description. Previously, my thinking was just to add the ignore patterns to the
execludeindagger.jsonindagger { init | develop } --sdk=, but wdyt about loading from.gitignore?shykes commentedon Jul 25, 2024
This seems reasonable to me but I may not be aware of all the subtleties of the design.
In general I'm in favor of adopting the standard gitignore format whenever we need to express filters on directories (see for example the
ignorepart of #7647 ). This is one step further in the same general direction.How would the default behavior be disabled or customized?
jpadams commentedon Jul 25, 2024
@drmikecrowe love to get your thoughts ☝️
drmikecrowe commentedon Jul 26, 2024
I guess my base question would be: Why wouldn't you adopt
.gitignoreas the standard? In my case, I'm controlling the release target contents via.gitignore. There's no situation where I want to use local files in dagger that are outside.gitignorebecause they will never be in my target environment (unless I'm missing something).As background, here was my new user experience:
dagger init --sdk=typescriptand wait 6 minutesdagger init)In my local directory, I have
.yarn/cachewhich is 6G. Yes, it probably shouldn't be there, but in this case we were experimenting with yarn's pnp mode, which includes the cache in the git lfshelderco commentedon Jul 26, 2024
Yes, that's what I'm suggesting. I'll reformulate the description when I can to provide more details on how I see this working, including picking up on global git excludes and parent
.gitignorefiles too.Also, notice this part of the rationale:
So in the same line of thought, when we support other VCSs, I'd do the equivalent to
.gitignorein those cases if possible.helderco commentedon Jul 26, 2024
A few ideas:
dagger.json's own include/exclude patterns to negate or override a.gitignorepattern.--no-ignoreflag that a lot of CLI's use (e.g., rg).ignore-vcsoption indagger.json(e.g., see hatch).drmikecrowe commentedon Jul 26, 2024
Remember,
dagger initwill not run if there is adagger.jsonpresent -- options 1 and 3 don't seem possible. I think the second option is the only choice of those 3.Alternatively, scope out a
.daggerignore?Also, does dagger respect
.dockerignore?helderco commentedon Jul 26, 2024
Those options aren't targetting
dagger init, it's mostlydagger call. Remember, those options are for disabling the default use of.gitignorefiles, but your use case doesn't call for disabling. If you did want to disable, you could do it afterdagger initas I can't think why adagger initwould fail based on something you have on.gitignore. Even if that's desirable, a CLI flag can be added there as well.No, it doesn't. I don't see a need for it other than possibly on getting a directory for a docker build, which is different use case, however we use a common
Directoryfor that, uncoupled to the docker build.drmikecrowe commentedon Jul 26, 2024
Help me understand please:
dagger initand then exclude them indagger call?dagger callthat you previously excluded indagger init?I'm trying to understand the different use-cases (and to date, my angst has been with excluding and
dagger init, so I haven't had time to experience the need indagger callyet)helderco commentedon Jul 26, 2024
Well, today, if your
dagger inittakes 6m and you don't proceed to adding excludes indagger.json, depending on the changes you make triggering cache invalidation, can take you the same 6m or more in adagger call.dagger initcreates initial files based on a template. That's controlled by the SDK and fixed for each release. You can add any number of stuff afterwards depending on your needs. Add dependencies, add files to the source directory, run local tools that create new stuff that's not generated indagger initbut that needs excluding for subsequentdagger callcommands.A simple
yarn installin your host is a common example of this. It'll create anode_modulesdirectory not generated indagger initthat you don't want to upload when loading the module on adagger call. The engine, by default, adds a<source dir>/**/*include. That’s today.Let's say you already have a
.gitignorein your repo (or even a global git exclude if this is possible for Dagger to use), with the patterns.yarn,node_modules, etc. Then with this proposal,dagger initwould pick up on that automatically, thus solving the problem that you had.The same would be kept for
dagger callwithout having to manually add "exclude" patterns todagger.json. And if you happen to use direnv during development, and add.direnvto.gitignorebecause you don't want to commit that, then there's nothing else you need to do to exclude it in Dagger too.4 remaining items
helderco commentedon Sep 20, 2024
There's a POC here:
.gitignorepatterns on module load by default #8501I still need to update this issue's description with the proposal, add details and examples for design review. It's not forgotten, I'm just backlogged.
fcbry commentedon Sep 26, 2024
@helderco This idea sounds good but I just thought of a potential failure case - how will Github large file support be handled? We have a bunch of repositories which have an included gitversion.exe for devops purposes, it's 160mb, and it's not the only example.. we also have repositories with stub databases and suchlike.
Github encourage this approach (vendor lock in) so it's impossible to prevent developers doing so. How would one handle this? These artifacts won't be git excluded but we definitely don't want that junk sent to docker on every
dagger ...invocation.helderco commentedon Sep 26, 2024
The idea is that the
.gitignorefiles contribute to the final exclude patterns for loading a module. You still havedagger.jsonexclude to ignore more stuff that's not in any.gitignore, or even to override a pattern that was added by.gitignore.For example, let's say you have a
.gitignorewith this:.ideaAnd in your
my-module/dagger.json:{ "name": "my-module", "sdk": "go", "exclude": [ "gitversion.exe" ] }Then the final exclude patterns for loading your module looks like this:
fcbry commentedon Sep 27, 2024
@helderco that's great - thanks for clarifying, still familiarizing myself with dagger.
sipsma commentedon Oct 28, 2024
I'm currently working on some performance improvements to module loading that will result in enough changes/simplifications to the relevant code that I'm just going to rope this in. Re-assigning to me (cc @helderco)
Vanuan commentedon Jun 27, 2025
Stumbled across this issue after constantly hitting no space left on device. Apparently, dagger sends my whole project to the system volume. Apparently including all the unnecessary files such as .git.
Is it a sane default behavior?
Vanuan commentedon Jun 27, 2025
For now, I'm using this:
But surely there must be a better way. The
@argumentdecorator appears to be analyzed statically rather than in runtime, so can't load from.gitignorethere.TomChv commentedon Jul 23, 2025
Following those improvements, #10736 should close that issue by applying .gitignore on contextual arguments.
Module loading already only include module sources so it's not a problem anymore
helderco commentedon Jul 25, 2025
Module loading includes everything inside the source directory, even
node_modulesand.yarn/cache, etc... So it can't be solved with just with the contextual directory argument of a function, this issue is specifically about loading the module itself.TomChv commentedon Aug 8, 2025
Fixed by #10736, please reopen if there's anything missing to solve that issue.