Skip to content

Daggerizing without littering #8123

Closed

Description

@shykes

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 .dagger behavior, 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/workflows works to our advantage
  • Using a dot directory as "annotation" is a familiar pattern. Again, .github works 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

  1. jedevc commented on Aug 8, 2024

    @jedevc
    Contributor

    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, and source keeps 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 init based 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 of git init and co. I'm happy to try it, and get feedback.

    Ignoring that though, we need to work out what "empty" means - I think a .git directory should probably be allowed in an "empty" directory, and in that case, any .gitattributes and .gitignore files should also probably be allowed. Does that extend to all hidden files?

  2. gerhard commented on Aug 8, 2024

    @gerhard
    Contributor
  3. helderco commented on Aug 8, 2024

    @helderco
    Contributor

    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 .dagger though, or more specifically, for it to be a hidden directory. I don't see it as the same as .github because that holds configuration and is not a proper programming language package. I'd love to see some examples of that.

    Some of my cons:

    • My IDE's tree viewer does hide hidden directories by default, even though it's easy to show them with a shortcut
    • I use tools like rg which ignore hidden directories by default, including the Live Grep in my IDE to search code in the project
    • I sometimes use macOS Finder to manage directories that may contain modules like my daggerverse or throwaway repros, which also hides hidden files by default

    I mentioned in #7199 (comment) that I'd prefer dagger.mod over 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-io since we may want to stop referring to the client library as the "sdk").

  4. sagikazarmark commented on Aug 8, 2024

    @sagikazarmark
    Contributor

    Experienced Daggernauts can avoid this littering by explicitly setting --source to a subdirectory.

    If they manage to remember (which gets complicated by the fact that this behavior changed a lot lately)

    Weird to have code in .dagger

    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 dagger as well.

  5. shykes commented on Aug 9, 2024

    @shykes
    ContributorAuthor

    Relevant comment by @matipan : #8042 (comment)

    My major concern with using a dot folder is that they are often referred to as hidden folders/files. Going into a terminal and doing an ls on the project would, by default, not show all the dagger specific codebase. Many fuzzy finders also ignore dot folders and files by default (like fzf, ctrl-p and others). Our point with Dagger is that your CI is an important part of your project that you should treat as regular software. Putting the contents of the top level module that builds, packages and releases our software project into a hidden folder makes it feel less relevant. I understand that this approach is already present, such as .github, but I honestly never liked it and I believe dagger code has more importance than the config files often written into . folders.

  6. jedevc commented on Aug 12, 2024

    @jedevc
    Contributor

    Relevant user comment: #7864 (comment)

    For reference, I did this (and I've been doing ci/cd for a while):

    • Came to dagger.io and perused the docs (guilty for assuming)
    • Went to the quickstart and followed the quickstart in MY repo
    • Churned
  7. jedevc commented on Aug 12, 2024

    @jedevc
    Contributor

    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 source to, and why - something like source 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 dagger vs .dagger - I'm a bit more tempted on dagger, given above points.

  8. drmikecrowe commented on Aug 12, 2024

    @drmikecrowe

    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 Layout at the top level of your documentation, probably between Introduction and Installation. For example, explain this structure and why we need it:

    .
    ├── dagger
    │   ├── package.json
    │   ├── sdk
    │   ├── src
    │   │   └── index.ts
    │   └── tsconfig.json
    ├── your_project/
    ├── LICENSE
    └── dagger.json
    

    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

  9. shykes commented on Aug 12, 2024

    @shykes
    ContributorAuthor

    @drmikecrowe here is the problem statement in this issue:

    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.

    Which part specifically is hyper-focused on dagger internals over user experience? I'll make sure to correct it.

  10. shykes commented on Aug 12, 2024

    @shykes
    ContributorAuthor

    What I realize now is the above structure is required for TS/JS monorepos, but not enforced by dagger init

    Can you explain this further?

  11. shykes commented on Aug 12, 2024

    @shykes
    ContributorAuthor

    @drmikecrowe I'm trying to understand the problems you describe in [this comment] (#7864 (comment)), and whether it's related to this "littering" issue.

    dagger init happily installs alongside my app (and did, leading me to be involved with this PR due to all the issues I was having)

    Reading between the lines, it seems that you typed dagger init --sdk=typescript at the root of your repo, and did not specify the --source=./dagger argument 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=./dagger but 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.

  12. drmikecrowe commented on Aug 12, 2024

    @drmikecrowe

    Which part specifically is hyper-focused on dagger internals over user experience? I'll make sure to correct it.

    None -- sorry. I thought source was referring to dagger/src. My bad

  13. Xiot commented on Aug 12, 2024

    @Xiot

    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.

    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

  14. shykes commented on Aug 12, 2024

    @shykes
    ContributorAuthor

    Which part specifically is hyper-focused on dagger internals over user experience? I'll make sure to correct it.

    None -- sorry. I thought source was referring to dagger/src. My bad

    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.

  15. 6 remaining items

  16. shykes commented on Aug 12, 2024

    @shykes
    ContributorAuthor

    I am concerned by this comment by @drmikecrowe:

    In short, I think dagger's package.json and the project's package.json must be in parallel folders. I don't see how they can be parent/children with any monorepo setup

    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 ?

  17. Xiot commented on Aug 12, 2024

    @Xiot

    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.

    I had similar issue when using dagger in its own repo as well since the sdk and module are installed separately

  18. drmikecrowe commented on Aug 12, 2024

    @drmikecrowe

    The one way to solve this is to not include the dagger module in the list of yarn workspaces and give it its own yarn.lock file. This is far from ideal though.

    @Xiot -- can you confirm this works? I was unable to get this working

  19. Xiot commented on Aug 12, 2024

    @Xiot

    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.

  20. marcosnils commented on Aug 14, 2024

    @marcosnils
    Contributor

    @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

    npm init -y 
    corepack use [email protected]
    dagger init --sdk typescript --source dagger
    dagger call container-echo --string-arg foo
    

    ^ this fails with:

    Error: input: module.withSource.initialize resolve: failed to initialize module: failed to call module "l
    olo" to get functions: call constructor: process "yarn install" did not complete successfully: exit code:
     1
    
    Stderr:
    error This project's package.json defines "packageManager": "yarn@[email protected]". However the current global
     version of Yarn is 1.22.22.
    

    this is my current directory layout:

    .
    ├── dagger
    │   ├── package.json
    │   ├── sdk
    │   ├── src
    │   ├── tsconfig.json
    │   └── yarn.lock
    ├── dagger.json
    ├── LICENSE
    ├── package.json
    └── pnpm-lock.yaml
    
    4 directories, 7 files
    

    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 packageManager defined. Why is dagger call picking up the parent's package.json packageManager config?

    I've tested with the latest version in main and the issue is still not resolved, something even more strange is happening. After doing dagger init , the root application package.jsongets overwritten with this value: "packageManager": "[email protected]+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"

  21. drmikecrowe commented on Aug 14, 2024

    @drmikecrowe

    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 use always sets the upstream packageManager field, so the SDK cannot use it in the dagger/ folder. Otherwise, the host package.json is changed by this process, which shouldn't happen
    • yarn sucks for this use-case. Drop it
    • pnpm seems to solve our problem. Need to install via npm i -g [email protected], don't use corepack

    See below:

    ~/Programming/Personal/dagger-test @ docker run -it -v./test10:/root --rm node bash
    root@de5164ae013f:/# cd /root/hello-dagger/
    root@de5164ae013f:~/hello-dagger# alias l="ls -l --color"
    root@de5164ae013f:~/hello-dagger# npm i --frozen-lockfile
    
    added 643 packages, and audited 644 packages in 26s
    
    139 packages are looking for funding
      run `npm fund` for details
    
    6 vulnerabilities (3 moderate, 3 high)
    
    To address all issues, run:
      npm audit fix
    
    Run `npm audit` for details.
    root@de5164ae013f:~/hello-dagger# npm exec tsc -- --version
    Version 5.4.5
    root@de5164ae013f:~/hello-dagger# git status
    On branch main
    Your branch is up to date with 'origin/main'.
    
    nothing to commit, working tree clean
    root@de5164ae013f:~/hello-dagger# mkdir dagger
    root@de5164ae013f:~/hello-dagger# npm i -g [email protected]
    
    added 1 package in 1s
    
    1 package is looking for funding
      run `npm fund` for details
    root@de5164ae013f:~/hello-dagger# cd dagger
    root@de5164ae013f:~/hello-dagger/dagger# pnpm init
    Wrote to /root/hello-dagger/dagger/package.json
    
    {
      "name": "dagger",
      "version": "1.0.0",
      "description": "",
      "main": "index.js",
      "scripts": {
        "test": "echo \"Error: no test specified\" && exit 1"
      },
      "keywords": [],
      "author": "",
      "license": "ISC"
    }
    root@de5164ae013f:~/hello-dagger/dagger# pnpm i [email protected]
    Packages: +1
    +
    Downloading [email protected]: 7.15 MB/7.15 MB, done
    Progress: resolved 1, reused 0, downloaded 1, added 1, done
    
    dependencies:
    + typescript 5.1.6 (5.5.4 is available)
    
    Done in 1.7s
    root@de5164ae013f:~/hello-dagger/dagger# pnpm exec tsc --version
    Version 5.1.6
    root@de5164ae013f:~/hello-dagger/dagger# cd ..
    root@de5164ae013f:~/hello-dagger# npm exec tsc -- --version
    Version 5.4.5
    root@de5164ae013f:~/hello-dagger# git status
    On branch main
    Your branch is up to date with 'origin/main'.
    
    Untracked files:
      (use "git add <file>..." to include in what will be committed)
            dagger/
    
    nothing added to commit but untracked files present (use "git add" to track)
    root@de5164ae013f:~/hello-dagger#
  22. pjmagee commented on Sep 1, 2024

    @pjmagee
    Contributor

    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. With dagger, 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 .git or the many . prefixed folders found in a ~ home directory (nuget config, dotnet, k8s config, .ssh` etc.

    Any thoughts on private modules being .dagger and modules meant to be published or public for external use, to be in a dagger folder?

  23. helderco commented on Sep 10, 2024

    @helderco
    Contributor

    Any thoughts on private modules being .dagger and modules meant to be published or public for external use, to be in a dagger folder?

    I would say, use .dagger for "contextual" modules and ., dagger or something else for "standalone" modules.

  24. helderco commented on Sep 10, 2024

    @helderco
    Contributor

    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:

    • It gets saved in dagger.json, so it’s not and won’t be a breaking change for existing modules.
    • It can be overwritten with --source= if necessary.
    • It’s a better experience for first-time users, with less friction, than just erroring out.
    • To manage expectations, we can let users know that this (default) layout is experimental and may still change.

    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.

  25. Excoriate commented on Sep 26, 2024

    @Excoriate
    Contributor

    I prefer using dagger instead 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.

    • It can be overwritten with --source= if necessary.

    That's what I usually use, and if this is developed, it'll be my first approach permanently for creating new modules.

    • It’s a better experience for first-time users, with less friction, than just erroring out.

    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).

  26. rajatjindal commented on Oct 1, 2024

    @rajatjindal
    Contributor

    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 dagger if that is what we agree upon as a team. cc @helderco @shykes @marcosnils @jedevc for helping us make a final decision here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions