Skip to content

🐞 Dagger's gitignore parser does not respect tailing slash #10868

Closed

Description

@skycaptain

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

MRE: https://github.com/skycaptain/dagger-issue-build-ignore

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

  1. added
    kind/bug
    on Aug 13, 2025
  2. added this to the v0.18.15 milestone on Aug 13, 2025
  3. TomChv commented on Aug 13, 2025

    @TomChv
    Member

    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:

    Image

    What I do not understand is why buildkit ignore files as well as directories, the patterns **/build*/ should only lead to exclude directories

  4. TomChv commented on Aug 13, 2025

    @TomChv
    Member

    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:

    func main() {
    	ctx := context.Background()
    
    	entries, err := dag.Host().Directory(".", dagger.HostDirectoryOpts{
    		Include: []string{"./**/*"},
    	}).Glob(ctx, "**/*.txt")
    	if err != nil {
    		panic(err)
    	}
    
    	fmt.Println(entries)
    }
    

    No exclude:

    [build/foo.txt/ buildaaa.txt builder.txt]

    With Include: []string{"./**/*, "!build*/"}

    []

    With Exclude: []string{"!build*/"}

    []
  5. TomChv commented on Aug 13, 2025

    @TomChv
    Member

    I did a repro with a Dockerfile and a .dockerignore, same behaviour:

    FROM alpine:latest
    
    WORKDIR /app
    
    COPY . .
    

    .dockerignore

    build*/
    

    Current dir

    ls
    build        buildaaa.txt builder.txt  Dockerfile   go.mod       go.sum       main.go      parser
    
    docker build .
    # ...
     => => writing image sha256:eb543f79820dda5c90cf99ffd1bdce83f3cd085d607587fce5efcb6265671a11  
    
    docker run --rm -it sha256:eb543f79820dda5c90cf99ffd1bdce83f3cd085d607587fce5efcb6265671a11 /bin/sh
    
    /app # ls
    Dockerfile  go.mod      go.sum      main.go     parser # all build* files and directories are ignored
    
  6. skycaptain commented on Aug 13, 2025

    @skycaptain
    ContributorAuthor

    According to .dockerignore file's documentation:

    [...] Leading and trailing slashes in ignore patterns are disregarded. [...]

    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?

  7. TomChv commented on Aug 13, 2025

    @TomChv
    Member

    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*.* to build*/ so it will exclude directories but include files like that:

    Include: []string{"./**/*", "!build*/", "build*.*"},
    

    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?

  8. jedevc commented on Aug 13, 2025

    @jedevc
    Contributor

    😢 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):

    [jedevc] yeah, okay, i'm a little worried that there are going to be patterns that aren't actually translatable 🤔
    [jedevc] might be worth discussing more with helder (guessing that's who you're working on this with?), but the better long term option would be to directly add gitignore support:

    includes []string // the include patterns we're using for this sync
    excludes []string // the exclude patterns we're using for this sync

    [jedevc] I would say that you would probably implement a GitignoredFS, which would be like fsutil.FilterFS

    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:

    • Propagate the autoGitIgnore option to the filesync protocol, then use the .gitignores using the git cli (or libgit, or go-git, or whatever) to only transfer non-excluded files
      • Given the time to do this one, if we pick this route, maybe we revert the previous implementation, so it's not a blocking regression.
    • Patch this one issue with a hack, and just commit to continuing to hack everytime this comes up (fairly convinced we'll keep seeing more of these, unless there's a way to prove we're entirely correct)
    • Or both (probably my preference). Fix this, with a hack, but start work on the more sustainable solution where we're not using buildkit patterns at all for this.

    Then we won't have to worry about fixing these pattern conversion errors ever again.

  9. skycaptain commented on Aug 13, 2025

    @skycaptain
    ContributorAuthor

    It would not work for directories that contains .,

    Right, it would not work for file that have no suffix.

    Not tested but wondering if just appending a double-glob would do, eg.

    Include: []string{"./**/*", "!build*/**"}
    

    IIRC this is what VSCode's devcontainer do.

    However I fully agree to @jedevc last comment.

  10. TomChv commented on Aug 13, 2025

    @TomChv
    Member
    	entries, err := dag.Host().Directory(".", dagger.HostDirectoryOpts{
    		Include: []string{"./**/*", "!build*/**"},
    	}).Glob(ctx, "**/*.txt")
    	if err != nil {
    		panic(err)
    	}
    
    	fmt.Println(entries)
    
    [buildaaa.txt builder.txt]
    

    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=32a19a1c4fd53fdc

  11. jedevc commented on Aug 18, 2025

    @jedevc
    Contributor

    "Fixed" by #10890.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bugkind/regression

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions