Skip to content

Commit generated dagger files in our repo #11467

Closed

Description

@shykes

Problem

Our repository is full of Dagger modules, mostly written in Go. The code for these modules cannot be built or linted by the standard Go toolchain from a clean git checkout. Now that we are trying to use reusable Dagger toolchains as much as possible, this has become a problem.

We have implemented a stopgap: ship a reusable toolchain that can generate dagger modules on the fly before attempting to build/lint them. This works but makes the toolchain more complex and VERY SLOW.

Solution

Everything would be simpler if we conformed to the prevailing convention for generated code: check them into git. This way, native toolchains can do their work without hooking or wrapping their execution.

Task list:

  1. Remove relevant .gitignore entries in all our dagger modules
  2. Add a generate function that is like 'develop -r'
  3. Run it once, commit in the repo

Activity

  1. shykes commented on Nov 21, 2025

    @shykes
    ContributorAuthor

    @dagger/maintainers any objections to this?

  2. changed the title [-]Commit generate dagger files in our repo[/-] [+]Commit generated dagger files in our repo[/+] on Nov 21, 2025
  3. marcosnils commented on Nov 24, 2025

    @marcosnils
    Contributor

    Task list:

    1. Remove relevant .gitignore entries in all our dagger modules
    2. Add a generate function that is like 'develop -r'
    3. Run it once, commit in the repo

    I guess we should also add a check on each commit that verifies generated files are up-to-date.

  4. vito commented on Nov 24, 2025

    @vito
    Contributor

    Still a bit hesitant to do this, but not blocking, considering we've already tried the status quo for long enough.

    The failure mode to me would be if the pain of constantly re-generating and re-committing and permanently inflating the repo size is higher than the pain of a slower linting phase. Slow checkouts and fetches can be brutal for a large org.

    If we're going to commit generated files, but then also imply a pattern of checking that the generated files are up-to-date like @marcosnils questioned (and I suspect some people feel compelled to do, right or wrong), then it doesn't feel like we would have escaped the slow lint anyway, we would have just moved it from the lint check to the check-generated check (granted, it would be in parallel).

    What about Python/TypeScript/other codegen'd SDKs? Do they not have these issues? Or, if they do, would we reach the same decision there, to commit all their generated code? My recollection is those generate even more code which might be less palatable.

  5. shykes commented on Nov 25, 2025

    @shykes
    ContributorAuthor

    Curious what you all think @chrisjpalmer @nipuna-perera ?

    To be clear this issue is about changing our own repo only. But it's also an experiment in changing the best practice for all users in the future.

  6. shykes commented on Nov 25, 2025

    @shykes
    ContributorAuthor

    The failure mode to me would be if the pain of constantly re-generating and re-committing and permanently inflating the repo size is higher than the pain of a slower linting phase. Slow checkouts and fetches can be brutal for a large org.

    That's true, we should watch for that. I'm hopeful that it won't make a significant difference in repo size, since it's mostly text files, and with the new toolchain pattern (+ dang 😁 ), the number of total modules will probably trend down?

    If we're going to commit generated files, but then also imply a pattern of checking that the generated files are up-to-date like @marcosnils questioned (and I suspect some people feel compelled to do, right or wrong), then it doesn't feel like we would have escaped the slow lint anyway, we would have just moved it from the lint check to the check-generated check (granted, it would be in parallel).

    That's true, but because the lifecycle of "lint" and "generate" are typically decoupled, users expect it to be that way, and are unpleasantly surprised when "lint" takes way too long. Even if the time budget is the same globally, it will still "feel" wrong.

    Also there's the inconvenience of linters breaking on a fresh git checkout, which would go away.

    What about Python/TypeScript/other codegen'd SDKs? Do they not have these issues? Or, if they do, would we reach the same decision there, to commit all their generated code? My recollection is those generate even more code which might be less palatable.

    I guess yes, we would reach the same decision. With the same tradeoffs that you mentioned.

    One last point: if the downsides turn out to be OK, and we enshrined this best practice as the "correct" one in the platform, we could harvest one more optimization: dropping codegen at runtime :) Which could speed up module loading time.

  7. chrisjpalmer commented on Nov 25, 2025

    @chrisjpalmer
    Contributor

    I cannot speak for the dagger repo, but regarding our own repos at Nine, I believe there would be many benefits to checking in the code. We have a large monorepo which houses all our dagger modules.

    • newcomers to our monorepo don't need to run dagger develop --recursive
    • tools like renovate would start working on our dagger modules

    In order to ensure the generated code was always up-to-date, you would need a check-generated step. Seems like the kind of thing that could be built into dagger itself ?

  8. shykes commented on Nov 25, 2025

    @shykes
    ContributorAuthor

    @chrisjpalmer yes we plan on adding the following to Dagger:

    • A built-in dagger generate command which would rollup all functions marked by +generate, similar to dagger check and +check
    • A built-in generate function which would re-generate Dagger's own module code. So dagger generate would always re-generate modules out of the box
    • A built-in check function that checks that generated files are up-to-date. So dagger check would always check that all generated files (including for dagger modules) are up-to-date
  9. chrisjpalmer commented on Nov 25, 2025

    @chrisjpalmer
    Contributor

    This sounds really good. Great way of solving the problem. Like the sound of the // +generate pragma. Would this be some thing we could use for running code formatters perhaps ? I.e. you format the code and it wants to push a bunch of updates to files.. ?

  10. shykes commented on Nov 25, 2025

    @shykes
    ContributorAuthor

    This sounds really good. Great way of solving the problem. Like the sound of the // +generate pragma. Would this be some thing we could use for running code formatters perhaps ? I.e. you format the code and it wants to push a bunch of updates to files.. ?

    Yes that would work just fine. Do you think end-users would find it weird to have to type dagger generate to format-fix their code? We could also consider adding a dagger fix + +fix, that would work exactly the same as generate, but with a different intent for end-users. wdyt? too much? @kpenfound @vito @marcosnils ?

  11. chrisjpalmer commented on Nov 25, 2025

    @chrisjpalmer
    Contributor

    That does feel more on par yes. But still if it had to be dagger generate for a while I don't think users would mind.

  12. nipuna-perera commented on Nov 26, 2025

    @nipuna-perera
    Contributor

    The failure mode to me would be if the pain of constantly re-generating and re-committing and permanently inflating the repo size is higher than the pain of a slower linting phase. Slow checkouts and fetches can be brutal for a large org.

    I'm hopeful that it won't make a significant difference in repo size, since it's mostly text files

    The other thing to consider is, adding a ton more generated files to a code review and re-adding every time there's a change to a module will quickly become really tedious to code review. It will also look overwhelming to a reviewer and put them of doing a quick review. I'm not looking forward to chasing after reviewers telling them that this is a change that looks smaller than it really is. I am not too concerned about the repo size itself. But I am concerned about the DX/UX.

    tools like renovate would start working on our dagger modules

    We still don't want Renovate to touch dagger deps right? Not without more intelligence built into Renovate to understand Dagger.

    A built-in dagger generate command which would rollup all functions marked by +generate, similar to dagger check and +check

    I may have missed some recent development (I am on vacation 🙂) but why is there a need for a pragma? Or even a generate function? Isn't that the same as develop? Or are we looking for something more specific as develop isn't?

    Do you think end-users would find it weird to have to type dagger generate to format-fix their code? We could also consider adding a dagger fix + +fix, that would work exactly the same as generate, but with a different intent for end-users. wdyt? too much?

    As long as it's not something ambiguous it should be ok. But I fail to understand why the generate function would behave differently for an end user.

    since it's mostly text files, and with the new toolchain pattern (+ dang 😁 ), the number of total modules will probably trend down?

    Again sorry for my ignorance. It's all text isn't it? Not, mostly?

    Also, how does toolchain pattern reduce the total number of modules?

  13. shykes commented on Apr 8, 2026

    @shykes
    ContributorAuthor

    I want to try this again now.

  14. shykes commented on Apr 9, 2026

    @shykes
    ContributorAuthor

    Implementation plan:

    Use checked-in Go module runtime files as the source of truth. Generation becomes a repo-level maintenance step; go:lint and go:check-tidy stop patching modules on the fly.

    PR 1

    1. Add one root generator under .dagger/main.go.
    2. Scope it to the same modules dagger check go:* touches now.
    3. For each target module:
      • find the module root
      • require sdk.source == "go"
      • run GeneratedContextChangeset()
      • merge all changesets into one repo-wide changeset
    4. Do a one-time repo cleanup for each targeted Go SDK module:
      • add "codegen": { "automaticGitignore": false } to dagger.json
      • remove only generated-runtime entries from local .gitignore
      • keep .gitattributes
      • keep any real local ignore rules
    5. Run the new generator once and commit:
      • updated dagger.json
      • cleaned .gitignore
      • committed dagger.gen.go
      • committed internal/dagger, internal/querybuilder, internal/telemetry

    PR 2

    1. Delete GenerateDaggerRuntime() from toolchains/go/main.go.
    2. Remove the calls to it from TidyModule and LintModule.
    3. Leave check generated as the only authority on stale runtime files.

    Verification

    • Run the new generator twice; the second run must be empty.
    • dagger check generated must pass on a clean tree.
    • Delete one committed generated file; dagger check generated must fail.
    • From a clean checkout, dagger check go:check-tidy and dagger check go:lint must pass without regenerating anything.

    Important implementation detail: develop -r is not enough for this repo because it walks dependencies, not toolchains. The new root generator should cover the same module set the current Go toolchain lints today, including toolchain modules.

    This should let us remove the just-in-time overlay path from toolchains/go entirely while keeping stale generated files enforced by the existing generated-files check.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions