You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
SDKs should generate files in current working directory by default, not ./dagger #6963
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 😅
Reacted by Nipuna Perera, Manuel Leonhardt and conor-bond
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
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.
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.
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)
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.
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:
the module's root directory, which contains dagger.json
the module's "source directory" which is where the module's SDK reads and writes files.
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:
the module's root directory, which contains dagger.json
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.
Activity
shykes commentedon Mar 28, 2024
FYI @sipsma @samalba @jpadams
nipuna-perera commentedon Mar 28, 2024
I wish I had more emojis to express how much I like this :)
helderco commentedon Mar 28, 2024
It's actually worse for me because I never init on the current dir, I always do it in a new subdir:
Small bikeshedding... due to the above, default should be
""rather than".", falling back to the value ofPATHbecause:helderco commentedon Apr 15, 2024
Reposting:
- Originally posted by @marcosnils in DEV-3707, 3 days ago
jedevc commentedon Apr 15, 2024
IMO, I think we should error out if
--sourcepoints 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.
helderco commentedon Apr 15, 2024
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) anddagger develop --sdkafterwards.Additionally, Python and TypeScript allow for configuring the runtime container via
pyproject.tomlandpackage.json. So you can bootstrap your files using your own template (e.g.,rye init), anddagger develop --sdk=should work with those files.However, in Python for example, if there's a
requirements.lockfile it'll be updated. It's the same that happens withgo.mod.helderco commentedon Apr 15, 2024
Maybe a prompt to ask for confirmation? With a
-for-yflag to force?sagikazarmark commentedon Apr 19, 2024
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 defaultdaggerthese 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 initdoesn't generate a separate go.mod anymore, but messes with the root go.mod which actively drives me mad)marcosnils commentedon Apr 19, 2024
is that so? 🤔
If I do:
it doesn't seem to messing with my main go.mod file. It creates a new one under the
daggerfolder.helderco commentedon Apr 19, 2024
I've pinned it down to Go's codegen binary, when you have a .go package in the context dir (directory with either
.gitordagger.json).miend commentedon Apr 23, 2024
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 Igo mod init, it works on the current directory, turning this directory into a go module. If Idagger 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, thendagger initinside that subdirectory.shykes commentedon Apr 23, 2024
To be clear, that is what
dagger init does. There are two different directories:dagger.jsonmiend commentedon Apr 23, 2024
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.
9 remaining items
shykes commentedon Jul 18, 2024
OK friends, it's finally happening! #7981
fix: init in current directory instead of `dagger` (dagger#7824)