Skip to content

🐞 Parent directory is uploaded when working in a module subdir #8395

Closed

Description

@gerhard

What is the issue?

When running a module from a subdirectory, the parent directory gets uploaded to the Engine:

# ...
cache request: upload /var/folders/z5/n5y08g4j073_ld2d9019j3_80000gn/T/tmp.s1fViQInu2/dagger from 45fhofmgv7lscg6ac23c50pz3
upload /var/folders/z5/n5y08g4j073_ld2d9019j3_80000gn/T/tmp.s1fViQInu2/dagger from 45fhofmgv7lscg6ac23c50pz3
copy upload /var/folders/z5/n5y08g4j073_ld2d9019j3_80000gn/T/tmp.s1fViQInu2/dagger from 45fhofmgv7lscg6ac23c50pz3
# ...

As discovered with @aluzzardi earlier today.

See the steps on how to reproduce & the Dagger Cloud Trace link. FWIW:

image

Dagger version

dagger v0.12.7 (registry.dagger.io/engine:v0.12.7) darwin/amd64

Steps to reproduce

cd $(mktemp -d)

git clone https://github.com/dagger/dagger
cd dagger

mkdir foo
cd foo
dagger init --sdk=go --name=foo -vvv

Log output

https://dagger.cloud/dagger/traces/5d85d7b1d5483304f37b6c8dfc3db8e2

Activity

  1. added
    kind/bug
    on Sep 10, 2024
  2. helderco commented on Sep 10, 2024

    @helderco
    Contributor

    Uhh.. this explains a lot actually!

  3. helderco commented on Sep 10, 2024

    @helderco
    Contributor

    Wait, taking a closer look. It seems that it's loading the context directory, not necessarily the parent directory right? That's expected.

  4. gerhard commented on Sep 10, 2024

    @gerhard
    ContributorAuthor

    I'm running the command in dagger/foo. That makes me think that the context directory is foo. There is no reason for it to go up a level - there is no configuration in the default init module that would make it behave this way.

    Did you try to follow the steps to reproduce?

  5. helderco commented on Sep 10, 2024

    @helderco
    Contributor

    A module has 3 directories (ignore the new "context directories" feature as that's something different):

    • context directory: git root (where .git is) or the root directory if not in a git repo
    • root directory: the directory where dagger.json is
    • source directory: the directory referenced in "source" in dagger.json

    So in effect, if you're in the root of the dagger/dagger repo and dagger init --sdk=go foo, that'll load all the Go code in the repo along with that foo module. Even in other sibling directories.

  6. helderco commented on Sep 10, 2024

    @helderco
    Contributor

    I followed your steps to reproduce and this is what I see that is being uploaded in resolveFromCaller: https://app.warp.dev/block/8wnHMlOFRKJWTysCpr696N

    Notice the size: 4493546. It's ≈40MiB, but perhaps it's the sheer quantity of files that's at fault more than the size (5448 items).

  7. helderco commented on Sep 10, 2024

    @helderco
    Contributor

    Note that this depends on what you have locally. For example I have sdk/php/vendor and that's the biggest contributor. If you have other modules in the repo with generated code, that should be loaded as well.

  8. helderco commented on Sep 10, 2024

    @helderco
    Contributor
  9. gerhard commented on Sep 12, 2024

    @gerhard
    ContributorAuthor

    Why is the directory where .git is getting uploaded?

    This is the unexpected part for me, even though it seems that it's working as expected.

  10. helderco commented on Sep 12, 2024

    @helderco
    Contributor

    I don't think .git is being uploaded (as it's excluded by default), it's the directory where .git is, i.e., the repo root.

  11. gerhard commented on Sep 12, 2024

    @gerhard
    ContributorAuthor

    Yes: why is the context directory (where .git is) getting uploaded?

  12. jedevc commented on Sep 12, 2024

    @jedevc
    Contributor

    I think this is a somewhat known issue? dagger init uploads parent directories - up to the root, this was so it could detect parent go.mods and similar. I'm sure we've discussed this before (I seem to remember with @jpadams, there was a conversation around daggerizing existing repos with this), but I cannot find a corresponding issue for it.

    It's not fully necessary to do this in most cases, and we could probably do much better with the context dir primitives we now have.


    For running a module, I'm not sure. Can you share the module that's in the subdir that you're hitting the issue with?

  13. gerhard commented on Sep 12, 2024

    @gerhard
    ContributorAuthor

    Yes, this definitely doesn't seem right.

    The module is: dagger init --sdk=go --name=foo -vvv

  14. helderco commented on Sep 20, 2024

    @helderco
    Contributor

    Yes, this definitely doesn't seem right.

    It's working by design because we wanted to support in-depth integration with an existing project, but we’re now converging on getting consensus to sandbox by default. See:

    Today, when a module is loaded within a repo, the upload starts from the repo root. Let's put your module example deeper in the tree: foo/bar. The engine, by default, adds these include patterns:

    # includes from your dagger.json, prefixed with `foo/bar/`
    foo/bar/dagger.json
    foo/bar/**/*

    The engine will apply those includes first, and then these excludes:

    .git/**
    # excludes from your dagger.json, prefixed with `foo/bar/`

    However, the Go SDK adds a few more includes for Go modules:

    dagger/core/schema/sdk.go

    Lines 485 to 498 in fa9d3c7

    func (sdk *goSDK) RequiredPaths(_ context.Context) ([]string, error) {
    return []string{
    "**/go.mod",
    "**/go.sum",
    "**/go.work",
    "**/go.work.sum",
    // TODO: the below could be optimized by scoping only to go modules that actually
    // end up being needed for the dagger module.
    // including vendor/ is potentially expensive, but required
    "**/vendor/",
    // needed in order to re-use go.mod from any parent dir (otherwise it's an invalid go module)
    "**/*.go",
    }, nil
    }

    So if you have a Go module, these are the include patterns you end up with:

    # includes from your dagger.json, prefixed with `foo/bar/`
    foo/bar/dagger.json
    foo/bar/**/*
    **/go.mod
    **/go.sum
    **/go.work
    **/go.work.sum
    **/vendor/
    **/*.go

    I created the following issue to stop doing this by default:

  15. jedevc commented on Apr 11, 2025

    @jedevc
    Contributor

    @sipsma I think with the refactorings to the module loading system these issues should be resolved now right? We should only be uploading the files needed for the module.

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/bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions