Skip to content

SDKs should generate files in current working directory by default, not ./dagger #6963

Closed

Description

@shykes

Problem

When initializing an SDK with dagger develop or dagger init --sdk, source files are generated in a subdirectory called ./dagger by default. It seems that most users are either confused by that default, or actively dislike it. I personally always use --source .. I would prefer for . to be the default, and I think most users will agree.

Solution

Change the default for dagger develop --source and dagger init --source to . instead of ./dagger.

Context

There is actually a reason for the current behavior:

  • We encourage users to create a Dagger module at the root of their application repo.
  • We also encourage users to (eventually) develop their CI logic as functions in that top-level repo. For this, they use dagger develop or dagger init --sdk.
  • In this situation, it is often preferable to tuck away the generated source code in a subdirectory, instead of polluting the repo root. Thus, the choice of ./dagger
  • However, in all other cases, . makes more sense

Nnote: I initially advocated for ./dagger as the default, so I'll take the L 😅

Activity

  1. shykes commented on Mar 28, 2024

    @shykes
    ContributorAuthor
  2. added this to the v0.10.x milestone on Mar 28, 2024
  3. nipuna-perera commented on Mar 28, 2024

    @nipuna-perera
    Contributor

    I wish I had more emojis to express how much I like this :)

  4. helderco commented on Mar 28, 2024

    @helderco
    Contributor

    It's actually worse for me because I never init on the current dir, I always do it in a new subdir:

    ❯ dagger init --sdk python --source foo foo
    

    Small bikeshedding... due to the above, default should be "" rather than ".", falling back to the value of PATH because:

    ❯ dagger init --sdk python --source . foo
    Error: [...]: source subdir path ".." escapes context
    
  5. added
    area/cli
    on Apr 11, 2024
  6. helderco commented on Apr 15, 2024

    @helderco
    Contributor

    Reposting:

    I'd like to raise one aspect that might be important to consider also. When you initialize a dagger module in a project with the same language as the SDK, it'll overwrite some files and potentially break the project in some ways.

    For example in the case of go, if I have a main.go and a go.sum file and I do dagger init --sdk go --source . to create a module for this project, I'll completely overwrite the go.mod file and it'll also break my project since it'll create a new main function within my main package. Similar thing happens for the other SDK's in some particular cases.

    I guess we need to decide what to do in case this happens.

    - Originally posted by @marcosnils in DEV-3707, 3 days ago

  7. jedevc commented on Apr 15, 2024

    @jedevc
    Contributor

    IMO, I think we should error out if --source points to a non-empty directory. If we change the default to --source=. (or ""), then if the current directory is non-empty, then this would error out as well.

    I think this behavior "feels" expected - lots of other tools with scaffolding functionality like this use a similar mechanism.

  8. helderco commented on Apr 15, 2024

    @helderco
    Contributor

    IMO, I think we should error out if --source points to a non-empty directory. If we change the default to --source=. (or ""), then if the current directory is non-empty, then this would error out as well.

    This seems like a good idea at first glance but it breaks a few use cases. The more obvious one is when you dagger init (without sources) and dagger develop --sdk afterwards.

    Additionally, Python and TypeScript allow for configuring the runtime container via pyproject.toml and package.json. So you can bootstrap your files using your own template (e.g., rye init), and dagger develop --sdk= should work with those files.

    However, in Python for example, if there's a requirements.lock file it'll be updated. It's the same that happens with go.mod.

  9. helderco commented on Apr 15, 2024

    @helderco
    Contributor

    Maybe a prompt to ask for confirmation? With a -f or -y flag to force?

  10. sagikazarmark commented on Apr 19, 2024

    @sagikazarmark
    Contributor

    I think it would make sense to distinguish between different use cases.

    I definitely don't want to see dagger files in the root of my software projects. I often call these directories ci, but I started to use the default dagger these days.

    Another use case I have is my daggerverse repo: I usually create a new directory for a new module and then run dagger init --source ..

    Maybe it would make sense to have a layout option (Dagger module, project, etc) that sets different defaults. Or even an interactive wizard. It would probably help newcomers decide what to do.

    (Update: BTW it seems to me that dagger init doesn't generate a separate go.mod anymore, but messes with the root go.mod which actively drives me mad)

  11. marcosnils commented on Apr 19, 2024

    @marcosnils
    Contributor

    (Update: BTW it seems to me that dagger init doesn't generate a separate go.mod anymore, but messes with the root go.mod which actively drives me mad)

    is that so? 🤔

    If I do:

    1|marcos:tmp/test (⎈ |kind-kind)$ go mod init test
    go: creating new go.mod: module test
    marcos:tmp/test (⎈ |kind-kind)$ dagger i^C
    130|marcos:tmp/test (⎈ |kind-kind)$ ls
    go.mod
    marcos:tmp/test (⎈ |kind-kind)$ ce^C
    130|marcos:tmp/test (⎈ |kind-kind)$ dagger init --sdk go
    17:10:02 WRN no LICENSE file found; generating one for you, feel free to change or remove license=Apache-2.0
    Initialized module test in .
    marcos:tmp/test (⎈ |kind-kind)$ tree .
    .
    ├── dagger
    │   ├── dagger.gen.go
    │   ├── go.mod
    │   ├── go.sum
    │   ├── internal
    │   │   ├── dagger
    │   │   │   └── dagger.gen.go
    │   │   ├── querybuilder
    │   │   │   ├── marshal.go
    │   │   │   └── querybuilder.go
    │   │   └── telemetry
    │   │       ├── attrs.go
    │   │       ├── batch_processor.go
    │   │       ├── init.go
    │   │       ├── processor.go
    │   │       ├── proxy.go
    │   │       └── span.go
    │   └── main.go
    ├── dagger.json
    ├── go.mod
    └── LICENSE

    it doesn't seem to messing with my main go.mod file. It creates a new one under the dagger folder.

  12. helderco commented on Apr 19, 2024

    @helderco
    Contributor

    I've pinned it down to Go's codegen binary, when you have a .go package in the context dir (directory with either .git or dagger.json).

  13. miend commented on Apr 23, 2024

    @miend

    I don't have a solution suggestion, but throwing my opinion in along with OP -- if I git init, it works on the current directory, making this directory a git repo. If I go mod init, it works on the current directory, turning this directory into a go module. If I dagger init --sdk=go, I expect it to work on the current directory, turning this directory into a dagger module. 🤔 If I want the module to be in a subdirectory, I'll naturally think to make the subdirectory first, then dagger init inside that subdirectory.

  14. shykes commented on Apr 23, 2024

    @shykes
    ContributorAuthor

    I don't have a solution suggestion, but throwing my opinion in along with OP -- if I git init, it works on the current directory, making this directory a git repo. If I go mod init, it works on the current directory, turning this directory into a go module. If I dagger init --sdk=go, I expect it to work on the current directory, turning this directory into a dagger module.

    To be clear, that is what dagger init does. There are two different directories:

    1. the module's root directory, which contains dagger.json
    2. the module's "source directory" which is where the module's SDK reads and writes files.
  15. miend commented on Apr 23, 2024

    @miend

    I don't have a solution suggestion, but throwing my opinion in along with OP -- if I git init, it works on the current directory, making this directory a git repo. If I go mod init, it works on the current directory, turning this directory into a go module. If I dagger init --sdk=go, I expect it to work on the current directory, turning this directory into a dagger module.

    To be clear, that is what dagger init does. There are two different directories:

    1. the module's root directory, which contains dagger.json
    2. the module's "source directory" which is where the module's SDK reads and writes files.

    I suppose I could have been clearer -- I expected the source directory to be the current one I'm in. I don't have a hard reason why it should be that way, but that's what I naturally expect when not explicitly specifying a directory name to use.

  16. 9 remaining items

  17. self-assigned this
    on Jul 1, 2024
  18. shykes commented on Jul 18, 2024

    @shykes
    ContributorAuthor

    OK friends, it's finally happening! #7981

  19. assigned and unassigned on Jul 18, 2024
  20. added a commit that references this issue on Jul 19, 2024
    b34e886
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions