Skip to content

POC: Apply .gitignore patterns on module load by default - #8501

Closed
helderco wants to merge 6 commits into
dagger:mainfrom
helderco:helder/dev-3952-use-gitignore-by-default-when-loading-modules
Closed

helderco wants to merge 6 commits into
dagger:mainfrom
helderco:helder/dev-3952-use-gitignore-by-default-when-loading-modules

Conversation

@helderco

@helderco helderco commented Sep 19, 2024 •

Copy link
Copy Markdown
Contributor

This is a proof of concept for:

It reads all the .gitignore files from a git repo root, up to a module being loaded, and adds the patterns inside to the list of "excludes" in dagger.json automatically, to limit the files getting uploaded from the host.

Example

Consider these .gitignore files:

  • .gitignore
    • .venv
    • __pycache__
  • sdk/python/.gitignore
    • .*_cache
    • dist/
    • docs/_ build
  • sdk/python/dev/.gitignore
    • /sdk

Running the following command, which requires loading the module:

dagger functions -m sdk/python/dev

Will add the following patterns, before the module's own excludes in dagger.json:

**/.venv
**/__pycache__
sdk/python/**/.*_cache
sdk/python/**/dist/
sdk/python/docs/_build
sdk/python/dev/sdk

Note

  • The patterns on each .gitignore are prefixed with the path to its directory
  • Like git, patterns that don't have a slash in the beginning or middle of the pattern are recursive, so ** is added
  • In "excludes" in dagger.json, it's possible to negate a pattern from .gitignore if necessary prefixing the pattern with !

The result is that for this module, with no excludes in dagger.json, the following won't be uploaded anymore:

  • sdk/python/dev/.venv (python's virtual environment)
  • sdk/python/dev/sdk (generated SDK library for the module)
  • sdk/python/dev/.../__pycache__ (compiled bytecode)

Today, those directories are added because they match an implicit include of <module source>/**/*.

Before

On first run for this module:

Screenshot 2024-09-19 at 17 20 58

After

On first run for this module:

Screenshot 2024-09-19 at 17 22 58

\cc @TomChv

@github-actions

This comment was marked as resolved.

@github-actions

This comment was marked as resolved.

- Start from the context directory and override with more specific paths
- Fixed semantics from git patterns
- Performance improvements

Signed-off-by: Helder Correia <[email protected]>
Signed-off-by: Helder Correia <[email protected]>
It's premature optimization. Each .gitignore takes approx 1ms to process, so even if the target module is burried in a 6 level deep subdir, with a .gitignore file in each of those parents, it's only 6ms, and only for the same `resolveFromCaller`.

If the target module uses a custom SDK in a sibling directory 6 levels deep, all those .gitignore files will be read twice because the custom SDK will make a separate `resolveFromCaller` call.

Signed-off-by: Helder Correia <[email protected]>
@helderco
helderco force-pushed the helder/dev-3952-use-gitignore-by-default-when-loading-modules branch from 6ac20a1 to a8401b9 Compare October 29, 2024 13:16
@github-actions

This comment was marked as resolved.

@github-actions

github-actions Bot commented Dec 3, 2024

Copy link
Copy Markdown
Contributor

This PR is stale because it has been open 14 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@github-actions

Copy link
Copy Markdown
Contributor

This PR was closed because it has been stalled for 7 days with no activity.

@github-actions github-actions Bot closed this Dec 17, 2024
@helderco
helderco deleted the helder/dev-3952-use-gitignore-by-default-when-loading-modules branch July 28, 2025 17:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant