Repository navigation
Description
What is the issue?
A trailing slash is commonly used in .gitignore files to ignore complete folders. In one of my projects, I have the following lines to ignore all build directories:
# Ignore build directories
build*/
In the same project, I have a file as part of my Dagger module under .dagger/build.go. Recent versions of Dagger appear to have an issue where this file is ignored when running the module as shown below. The problem can be mitigated by renaming the file, but it seems Dagger's gitignore parser misinterprets that line from my gitignore file and also ignores files instead of just directories. This worked fine with v0.18.14, as also shown below.
Dagger version
dagger v0.18.15-250813115555-11d52c2b8d11 (docker-image://localhost/dagger-engine.dev?container=dagger-engine.dev&volume=dagger-engine.dev&cleanup=false) darwin/arm64/v8
Steps to reproduce
Run with v0.18.4:
$ dagger functions
▶ connect 0.2s
▶ load module: . 1.8s
Name Description
build -
test -
Run with latest HEAD:
$ dagger functions
▶ connect 0.5s
▼ load module: . 1.2s ERROR
╰─▼ Container.withExec(args: ["go", "build", "-ldflags", "-s -w", "-o", "/runtime", "."]): Container! 0.2s ERROR
┃ # dagger/my-project-dev
┃ ./main.go:16:33: undefined: Build
┃ ./main.go:17:10: undefined: Build
! process "go build -ldflags -s -w -o /runtime ." did not complete successfully: exit code: 1
Error logs:
▼ Container.withExec(args: ["go", "build", "-ldflags", "-s -w", "-o", "/runtime", "."]): Container! 0.2s ERROR
# dagger/my-project-dev
./main.go:16:33: undefined: Build
./main.go:17:10: undefined: Build
! process "go build -ldflags -s -w -o /runtime ." did not complete successfully: exit code: 1
Error: failed to serve module: input: moduleSource.asModule failed to call module "my-project-dev" to get functions: call constructor: process "go build -ldflags -s -w -o /runtime ." did not complete successfully: exit code: 1
Log output
No response
Activity
TomChv commentedon Aug 13, 2025
I understand what it's failing based on the repro.
Here's a cloud trace URL of the execution: https://dagger.cloud/Quartz/traces/8c10e8fef341f248b7558f8a7017a104?listen=76e16ab072cc9bd5&listen=4d4f187c555bbb54&listen=6b3fd6ab8283dff0&listen=7a5832c3223e6350&listen=3586bf38b6aea2e1&showHidden=76e16ab072cc9bd5&showHidden=6b3fd6ab8283dff0&showHidden=85272bd0e21644f7#884dd8f93d11a97c
And the module loading ignore patterns:
What I do not understand is why buildkit ignore files as well as directories, the patterns
**/build*/should only lead to exclude directoriesTomChv commentedon Aug 13, 2025
Looks like it's a buildkit issue, I did a simple script that download my host directory and apply a filter and it seems buildkit isn't making the difference between files and directories the same way .gitignore is doing:
No exclude:
With
Include: []string{"./**/*, "!build*/"}With
Exclude: []string{"!build*/"}TomChv commentedon Aug 13, 2025
I did a repro with a Dockerfile and a .dockerignore, same behaviour:
.dockerignore
Current dir
skycaptain commentedon Aug 13, 2025
According to .dockerignore file's documentation:
Wild guess: Could the issue be that Dagger is using the same library that Docker uses for its .dockerignore file to read and interpret the .gitignore file, despite there being slight syntax differences between .gitignore and .dockerignore?
TomChv commentedon Aug 13, 2025
We rely on buildkit to execute these patterns correctly, but they do not handle the only dir as expected, the way ignore patterns are express in .gitignore and .dockerignore are slightly different and there's no such "only dir feature" on .dockerignore.
However I think we could add
build*.*tobuild*/so it will exclude directories but include files like that:It would not work for directories that contains
., but it would solve 99% of the case, what do you think @jedevc ?If we detect a only dir exclude, we also add an extra pattern that will reverse and only include files?
jedevc commentedon Aug 13, 2025
😢 we should be aiming for 100% compat here - I think anything else is just gonna be an incredibly frustrating experience for users, and we'll spend ages trying to patch holes like this.
I'm starting to doubt the pattern conversion approach here - this issue proves that there are just gaps between how dockerignore and gitignore work, and there are going to be some patterns that cannot be converted.
I think we need to step back and reconsider the approach - otherwise, we're just gonna be fixing bugs like this over and over and over. IMO, we should update the entire filesync protocol to support
gitignore, as I suggested at some point (quoting a prior private message):If there are patterns that just can't be converted, we need something like this.
There are a couple of options in terms of moving forward:
autoGitIgnoreoption to the filesync protocol, then use the.gitignores using the git cli (or libgit, or go-git, or whatever) to only transfer non-excluded filesThen we won't have to worry about fixing these pattern conversion errors ever again.
skycaptain commentedon Aug 13, 2025
Right, it would not work for file that have no suffix.
Not tested but wondering if just appending a double-glob would do, eg.
IIRC this is what VSCode's devcontainer do.
However I fully agree to @jedevc last comment.
TomChv commentedon Aug 13, 2025
yep it works fine with the double glob at the end! I'll add that fix
EDIT: that still lead to issue for example :
.git/will become.git/**which means everything inside .git will be ignored but not the directory will still be there, empty: https://dagger.cloud/dagger/traces/7796912adc80b7d5412a42ec9e9a12f5?listen=7a9eb441c0732138&listen=1181a1303b1f766b&listen=8359ff9cc1f95790&listen=32a19a1c4fd53fdcchore: fix incorrect behaviour for dir only pattern on .gitignore
chore: fix incorrect behaviour for dir only pattern on .gitignore
jedevc commentedon Aug 18, 2025
"Fixed" by #10890.