#putting dagger.json in the root of the repo

1 messages · Page 1 of 1 (latest)

hexed whale
#

afaik there's an open question around whether root: should be renamed or rethought but no resolution yet, so this seems good to think about at the same time

#

putting dagger.json in the root of the repo

analog grove
#

I took the liberty of opening an issue

analog grove
#

The root of a module should always be the directory which has a dagger.json . No other good answer IMO.

#

(or maybe I misunderstand what root is supposed to do)

tacit grotto
#

root currently handles inverse cases of source, e.g. you have multiple modules in a monorepo, but they need some files from parent dirs in order to build such as a go.mod in parent dir or a go module pointed to be a go mod replace in go.mod.

I don't really like root either: https://github.com/dagger/dagger/issues/5862#issuecomment-1762507181

But it handles cases source doesn't. But source also handles cases root doesn't 🙂 So there's probably some grand unified theory of path specification to be decided on here

GitHub

We need to handle a local module dependency being outside the directory tree of the depender (i.e. path that uses ../)

#

It's essentially the same problem as the difference between the context dir and the dockerfile itself when using docker build. Except for us:

  1. we point to your module's source code rather than a dockerfile
  2. the context dir is relevant in determining whether your module source code can build in the first place (whereas in dockerfiles it just gives the dockerfile access to more stuff)
analog grove
#

you have multiple modules in a monorepo, but they need some files from parent dirs in order to build such as a go.mod in parent dir or a go module pointed to be a go mod replace in go.mod.

I didn't understand that part. My naive reaction is "why share files across modules in the first place?", seems like a niche requirement not worth over-complicating everything, but I'm probably missing something

EDIT: share

hexed whale
analog grove
#

Right, I used the wrong wording. I guess I meant "share"

hexed whale
#

Ah got it. Yeah that's fair to some extent, you could end up with a needlessly large go.mod containing the union of all dependencies for a wide array of modules, instead of having individual tightly-scoped ones.

#

Which could get tricky at publishing time (imagining you're versioning the modules independently)

analog grove
#

I honestly don't think it's worth it

#

On the one hand: a slight inconvenience at worst
On the other hand: compromising a core principle of how modules work (1 module = 1 directory, always)

hexed whale
#

One other case where it's used is when your module depends on a sibling module in the same repo; afaik you have to do root: .. before you can have ../foo as a dependency

analog grove
#

Slight regexp correction 🙂

hexed whale
analog grove
#

oops

analog grove
#

?

#

Yay we did it

hexed whale
analog grove
#

Hey @fading mortar why do you use root: ".." in your modules?

tacit grotto
#

And also the other case i mentioned where you have a go mod replace that points to parent paths

analog grove
#

There's also a safety issue with allowing root to point to a parent directory. It could be used by a malicious module to access directories it's not supposed to.

tacit grotto
analog grove
#

Sure and maybe that's sufficient, but it's one more moving part to worry about, and one more rule for devs to learn

tacit grotto
#

It’s not something we had to go out of our way to do, it works like that because a git source in buildkit is inherently rooted at the git repository

#

Like I don’t think any of these are common cases but they aren’t rare enough to just say user’s can’t use dagger if they hit these rare situations that call for this

analog grove
#

Doesn't root also control what Host().Directory() will return inside the module?

analog grove
fading mortar
analog grove
#

Personally I have a repo full of Go modules, and it never occured to me once that I may want to share the same go.mod across them...

analog grove
analog grove
fading mortar
tacit grotto
# analog grove Personally I have a repo full of Go modules, and it never occured to me once tha...

Right, but for people with highly opinionated monorepo setups where they control all dependencies across all their go code from one go.mod, telling them to abandon their opinions and setup just to use dagger seems likely to just result in them not using dagger.

Also worth keeping in mind the unknown of how package managers in every language in every SDK we could hypothetically want to support work. Which is to say, who even knows what requirements will come up.

#

I do think there's alternatives to "root" that give the same functionality.

One possibility that would integrate with source is if a single dagger.json could be used to configure multiple modules (in separate source dirs). Then you could have a shared dagger.json and go.mod in the root of your monorepo but still have multiple dagger modules in different source subdirs

#

Or as a slight variation, allow users to use different names besides dagger.json, which would let them put multiple dagger module configuration files in the root of the repo

analog grove
#

maybe a lightweight variation too, where a parent dagger.json can inject an overlay into its sub-modules, without hijacking the filesystem as the authoritative catalog of those sub-modules

analog grove
#

But yeah I like all those options 👆 better than root because it "inverts" the control, outer->inner instead of inner->outer