Skip to content

Change order of include/exclude patterns to allow overrides on module load #8548

Closed

Description

@helderco

Context

When loading a module, the engine compiles a list of include/exclude patterns in order to filter the files that need to be uploaded from the host to the engine.

This is how the engine joins include patterns:

  • <module root>/<dagger.json include...>
  • <module root>/dagger.json
  • <module root>/**/*
  • <sdk required paths>

Problem

Notice that a module’s dagger.json patterns are added before anything else so it doesn’t have a chance to override anything that’s more global like the entire root directory, or the SDK’s implicit includes (required paths).

The exclude patterns are simpler and already correctly ordered:

  • .git/**
  • <module root>/<dagger.json exclude>...

Solution

Reorder the patterns in the following way:

  • <sdk required paths>
  • <module root>/**/*
  • <module root>/<dagger.json include...>
  • <module root>/dagger.json

This allows a dagger.json file to override the implicit SDK includes, limit which files are included from the root directory without resorting to a more difficult to manage list of excludes, but also not negate the inclusion of dagger.json itself.

Example

Consider a foo/bar/dagger.json module with:

{
    "name": "foobar",
    "sdk": "go",
    "source": ".dagger",
    "include": [
        "!../../**/vendor/",
        "!**/*",
        "src/"
    ]
}

The following is a diff between how the final include patterns are ordered now, and how I suggest we reorder them to:

-!**/vendor/
-!foo/bar/**/*
-foo/bar/src/
-foo/bar/dagger.json
-foo/bar/**/*
**/go.mod
**/go.sum
**/go.work
**/go.work.sum
**/vendor/
**/*.go
+foo/bar/**/*
+!**/vendor/
+!foo/bar/**/*
+foo/bar/src/
+foo/bar/dagger.json

I’m aware that you can exclude something that was included instead of negating the include, I’m just trying to prove a point on the ability to override.

Activity

  1. helderco commented on Mar 13, 2025

    @helderco
    ContributorAuthor
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions