Repository navigation
Description
Problem
By default, daggerizing an existing project (either with dagger init --sdk=NAME, or dagger develop --sdk=NAME) will cause littering, by mixing Dagger-managed files with pre-existing files. This can cause frustration and confusion just as a user is familiarizing themselves with Dagger.
Experienced Daggernauts can avoid this littering by explicitly setting --source to a subdirectory. But 1) this is cumbersome 2) it prevents a shared convention on default source directory 3) it doesn't help beginners.
Solution
Change how the default source directory is selected, so that littering never happens by default.
| Before | After | |
|---|---|---|
| Source directory, if module root is empty | . ✅ |
. ✅ |
| Source directory, if module root is not empty | . ❌ |
.dagger✅ |
Design considerations
Custom boilerplate
@helderco asks:
What if I want to customize my language-specific boilerplate, for example with my own Python config files? This requires creating files before
dagger init, which would trigger the.daggerbehavior, but I don't want that.
In this case, you actually want to override the anti-littering protection: you're OK with the Dagger SDK mixing files into your directory, because you know what you're doing. It's reasonable to express that with an explicit --source ..
Weird to have code in .dagger
One concern with .dagger is that it feels weird to have source code in a dot directory, and may possibly confuse some IDEs.
I acknowledge the concern, but I think it's the best tradeoff:
- In spite of thorough bikeshedding, we have not found an alternative that got stronger consensus
- IDEs don't seem to be actually confused. Github actions using
.github/workflowsworks to our advantage - Using a dot directory as "annotation" is a familiar pattern. Again,
.githubworks in our favor. - The "weird" feeling is proportional to the size of the module source code. If it grows too large, we actually want you to spin it out into standalone modules. So the gradual "weirdness" factor works in our favor, because it acts a nudge towards desired best practices.
Activity
jedevc commentedon Aug 8, 2024
I significantly prefer this option to trying to mix dagger code into the project root in an SDK-specific way (like
internal/dagger). For one, this option as suggested is actually relatively easy to implement - no significant SDK changes are required, andsourcekeeps it's meaning. This also means backwards compatibility at a module level is very easy.One question - do any languages struggle with importing code at hidden folders, like
.dagger? I'm not sure how that might be done in python for example (go isn't an issue). I don't think this use case is super common, but may be an issue.I do have one little feeling that changing the behavior of
dagger initbased on the contents of the current directory is confusing - I can imagine users getting confused why this would be different - that's a hunch though, since it's breaking from tradition ofgit initand co. I'm happy to try it, and get feedback.Ignoring that though, we need to work out what "empty" means - I think a
.gitdirectory should probably be allowed in an "empty" directory, and in that case, any.gitattributesand.gitignorefiles should also probably be allowed. Does that extend to all hidden files?gerhard commentedon Aug 8, 2024
Yes.
.daggerfeels natural 🎬 https://www.youtube.com/watch?v=g2E86Ke_RME&t=445shelderco commentedon Aug 8, 2024
I agree with @jedevc. I remember suggesting a while back switching the default for source based on existing contents when discussing #6963 (comment) with someone, and we scoffed it up due to it being possibly confusing. But I do still like that idea, so also happy to try it.
I dislike
.daggerthough, or more specifically, for it to be a hidden directory. I don't see it as the same as.githubbecause that holds configuration and is not a proper programming language package. I'd love to see some examples of that.Some of my cons:
rgwhich ignore hidden directories by default, including the Live Grep in my IDE to search code in the projectI mentioned in #7199 (comment) that I'd prefer
dagger.modover that, or anything else that's not a hidden dir actually.On the other hand, the above makes me think that the vendored library (now dropped in
./sdk), would benefit from being in an hidden directory like.sdk(or.dagger-iosince we may want to stop referring to the client library as the "sdk").sagikazarmark commentedon Aug 8, 2024
If they manage to remember (which gets complicated by the fact that this behavior changed a lot lately)
I don't mind it at all! It may get hidden by IDEs, but same is true for
.github. I can live with that.That being said, I'm kinda used to
daggeras well.shykes commentedon Aug 9, 2024
Relevant comment by @matipan : #8042 (comment)
jedevc commentedon Aug 12, 2024
Relevant user comment: #7864 (comment)
jedevc commentedon Aug 12, 2024
Mmm, the comment above kind of convinces me that we should at least try the switching behavior based on the contents of the target directory. I still think it's confusing for users who do this a lot, but I think we've actually trained muscle memory for a lot of people to manually specify
--source=in the past. I don't really like it, but if we don't want to update the quickstart instructions for different paths for initializing in an existing project vs a new project, then I think it's the only real option.I do think we should make sure to have a neat message about where we initialized
sourceto, and why - something likesource directory initialized in dagger/ (because current directory was not empty)- that would hopefully stem confusion from more advanced users.I think there's enough here for someone to pick this up (will give it a try when I get a moment, and have cleared up my current work) - we still would need to decide about
daggervs.dagger- I'm a bit more tempted ondagger, given above points.drmikecrowe commentedon Aug 12, 2024
In my opinion, you're still hyper-focused on the dagger internals instead of giving new users a better intuitive understanding of what you know. For example, you should have
Project Layoutat the top level of your documentation, probably between Introduction and Installation. For example, explain this structure and why we need it:What I realize now is the above structure is required for TS/JS monorepos, but not enforced by
dagger init. I assume similar problems would surface with other languages, but I don't know that for certain.Additionally, consider this module layout says nothing about where my source code should reside. That's what bit me
shykes commentedon Aug 12, 2024
@drmikecrowe here is the problem statement in this issue:
Which part specifically is hyper-focused on dagger internals over user experience? I'll make sure to correct it.
shykes commentedon Aug 12, 2024
Can you explain this further?
shykes commentedon Aug 12, 2024
@drmikecrowe I'm trying to understand the problems you describe in [this comment] (#7864 (comment)), and whether it's related to this "littering" issue.
Reading between the lines, it seems that you typed
dagger init --sdk=typescriptat the root of your repo, and did not specify the--source=./daggerargument specified in the quickstart. As a result your repo was littered with files, causing conflicts between your existing app and the new app dagger tried to drop at the source.The quickstart avoids this problem by explicitly specifying
--source=./daggerbut you skipped it, thinking "if this were absolutely necessary, it would be the default behavior, and wouldn't require an explicit flag". Which as it turns out is not the case, causing frustration.Is this ☝️ correct? If so, then you are indeed experiencing the "littering" problem which we aim to solve with this issue. And you are correct that as a result, we should be able to document the standard project layout better than we do today.
drmikecrowe commentedon Aug 12, 2024
None -- sorry. I thought
sourcewas referring todagger/src. My badXiot commentedon Aug 12, 2024
I've found this mentality as well. I can't remember the exact specifics (so take this as anecdotal), but it was around things like enums and scalars. The reasoning that I got was centered around the fact that 'thats not the way that GraphQL does things', which came across as odd since, at least from my perspective as a user, the fact that GraphQL is being used seems like an implementation detail
shykes commentedon Aug 12, 2024
That's good feedback, the term "source" is ambiguous since there are two "layers" to it - from engine to SDK, then within the SDK layout itself.
All this stems from the fact that your Dagger configuration is real code; but still is expected to retains some properties of a configuration, specifically: being attached to an existing codebase without messing with it. A lot of the usability issues you're seeing are linked to this "square the circle" problem.
6 remaining items
shykes commentedon Aug 12, 2024
I am concerned by this comment by @drmikecrowe:
If this is true, then the solution we are discussing here might not work for the Typescript SDK. In other words, we may not have a good solution for a Dagger module co-existing in a host repo, when both are written in Typescript/Javascript.
Thoughts @TomChv @jedevc @marcosnils @sipsma @vito ?
Xiot commentedon Aug 12, 2024
I had similar issue when using dagger in its own repo as well since the sdk and module are installed separately
drmikecrowe commentedon Aug 12, 2024
@Xiot -- can you confirm this works? I was unable to get this working
Xiot commentedon Aug 12, 2024
I don't have dagger in my monorepo so its a little more involved for me to test.
I do have packages in my monorepo though that are excluded from the list of workspaces and have their own lock file, so I was mainly going off of that.
marcosnils commentedon Aug 14, 2024
@drmikecrowe @Xiot think I was able to reproduce your issue and even after #7864 seems like it's still not fully resolved. Copying my message from discord (https://discord.com/channels/707636530424053791/1271408553848209491/1273133304849371199) here:
I was able to reproduce what the user was experiencing in v0.12.4
^ this fails with:
this is my current directory layout:
why is this failing? it doesn't seem right that the runtime container is trying to use pnpm when the module's package.json doesn't have a
packageManagerdefined. Why isdagger callpicking up the parent's package.jsonpackageManagerconfig?I've tested with the latest version in
mainand the issue is still not resolved, something even more strange is happening. After doingdagger init, the root applicationpackage.jsongets overwritten with this value:"packageManager": "[email protected]+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"drmikecrowe commentedon Aug 14, 2024
yeah, @shykes / @TomChv -- this is just a big PITA (not on our side, but on Node's side). @marcosnils above shows how to very simply test this. Unfortunately, after quite a bit of time this morning, here's what I found:
corepack usealways sets the upstreampackageManagerfield, so the SDK cannot use it in thedagger/folder. Otherwise, the hostpackage.jsonis changed by this process, which shouldn't happennpm i -g [email protected], don't use corepackSee below:
pjmagee commentedon Sep 1, 2024
I like
.dagger, this to me feels like an external process will be using this, which is how it feels and will be, i.e a CI Pipeline,will be using it or the local dagger cli. Withdagger, it could be assumed as a normal compiled set of code which isn't the case. however, The.is commonly known to be a hidden directory but then we have cases where for the average developer, it shouldn't be an issue, i.e.gitor the many.prefixed folders found in a~home directory (nuget config, dotnet, k8s config, .ssh` etc.Any thoughts on private modules being
.daggerand modules meant to be published or public for external use, to be in adaggerfolder?helderco commentedon Sep 10, 2024
I would say, use
.daggerfor "contextual" modules and.,daggeror something else for "standalone" modules.helderco commentedon Sep 10, 2024
It’s important to avoid overwriting the user's files, so I want to move forward with this as described. Even though my arguments against using a hidden folder haven’t been addressed, I’m interested in trying it out in practice (even without this feature, i.e.,
--source=.dagger).My biggest concern is that we figure out something better and change the default again later, possibly frustrating users. However:
dagger.json, so it’s not and won’t be a breaking change for existing modules.--source=if necessary.As for the TypeScript-related comments, they don’t seem to be blockers here and would benefit from separate issues to facilitate discussion if needed.
Excoriate commentedon Sep 26, 2024
I prefer using
daggerinstead of.dagger. Many reasons have been presented in this issue, and I agree with most of them (specially @helderco 's). It has an impact on the experience, IDE(s) will hide it, and more importantly, it's not just a decorative aspect of my repositories, it's fundamental, it's the codebase that powers my Continuous Integration. Having it hidden makes readability difficult, especially for those less experienced with Dagger.That's what I usually use, and if this is developed, it'll be my first approach permanently for creating new modules.
It's difficult to evaluate that. I believe it's a trade-off; it may solve one problem but introduce another (hidden folders will create an additional obstacle).
rajatjindal commentedon Oct 1, 2024
Hi @Excoriate
Many thanks you for your feedback on this issue (and other contributions, thanks to one of your daggerverse module, we were able to identify some backward imcompatible changes in one of the other PR 🎉).
FWIW, I prefer to have anything except my app code to be shown less prominently on the IDE. Mostly because I would be spending the cycles to set up that once, and then focus on my app changes. but this is my personal preference and I appreciate the fact that it could be different for other folks.
having said that, I am happy to change the default to
daggerif that is what we agree upon as a team. cc @helderco @shykes @marcosnils @jedevc for helping us make a final decision here.