Repository navigation
Description
Currently, by default the engine loads the directory tree at a module's dagger.json and nothing else. However, to support cases where there are files/dirs the module relies on that are outside that directory tree (i.e. a go.mod, package.json, another dependency module that exists relative to the module, etc.) there exists a root field in dagger.json that allows you to specify a parent directory that the engine will load instead.
This technically works but is inherently very confusing, both in behavior and terminology.
We discussed a better approach in this discord thread: https://discord.com/channels/707636530424053791/1182712578154180648
Full details are TBD as part of this issue, but the gist of the idea is to "invert control" such that rather than having a dagger.json that can point to parent dirs to load, dagger.json has the ability to point to module source that is present in child dirs.
There's a many variations on this general idea possible.
For the sake of having a concrete example, here's one possibility. The directory tree in a monorepo containing two go sdk modules that share a go.mod at the root of the repo would look like:
├── dagger.json
├── go.mod
├── go.sum
├── other-subdir
│ └── depmod
└── subdir
└── mymod
In this case, the module at subdir/mymod is a module that depends on the module at other-subdir/depmod.
The contents of dagger.json would look something like this:
[
{
"name": "mymod",
"source": "./subdir/mymod",
"sdk": "go",
"dependencies": ["./other-subdir/depmod"]
},
{
"name": "depmod",
"source": "./other-subdir/depmod",
"sdk": "go",
"dependencies": []
},
]This would be a slightly altered format of dagger.json that allows multiple modules to be specified rather than only one (hence the list of objects on the top level).
The resulting behavior would be that if you ran dagger call (or other module-aware cli commands) in the ./subdir/mymod directory then we'd find the parent dagger.json (or error out if one wasn't found in the current git repo) and use that to know where the source of that mymod module is and also where the source of the depmod module is.
That can all be used to load the module as efficiently as possible (where it's from a local checkout or purely from git), as described in this and subsequent comments on a related issue.
Support for exclude/include on each module should also fit in pretty well with this sort of approach.
Activity
skycaptain commentedon Dec 28, 2023
I think this feature is quite significant, as it would also allow the inclusion of secret files located in the user's home directory, such as
~/.gnupgmentioned in this cookbook example or~/.netrc.One suggestion for the design of this feature: There could be sources that are either mandatory or optional. In the given scenario, I would prefer to permit the use of
~/.netrcfiles but have a fallback to environment variables within the module's code.shykes commentedon Jan 22, 2024
@sipsma continuing the discussion thread we started on #6386 and f2f:
Question 1: how do we keep it simple?
I love the simplicity of this formula:
module = directory + dagger.json. I worry about losing it. It also has cool corollaries, like "my sub-modules = my sub-directories with dagger.json".We don't have to keep the formula, necessarily. But we must keep the simplicity. What new formula would come with your proposed design, and is it simple enough? It now, can we make it simpler?
Question 2: how does introspection work?
Modules often call
host().directory()for introspection. Usually it's to load data packaged with the module source.host().directory()map to? The module's source directory, or the directory holding its dagger.json?host().directory()for this purpose, and encode the answers above into an API?Question 3: can I use dagger.json to configure my home directory?
The title says it all :) I have a dream of configuring Dagger in my home directory, to unlock various goodies. See #6323. Will the
dagger.jsonfrom your design also be used to configure my home directory? Or do we prefer to design a different format for a different config file at the home directory?Random idea
Below are new ideas coming to me as I write this. Disclaimer, I may change my mind at any time :)
Maybe that's the answer? If
dagger.jsonbecomes a complete engine configuration, instead of module configuration, then perhaps that answers my other questions? The formula would become:configuration = dagger.json, context = directory + configuration.My home directory could have a
dagger.json, making it a context directory for running the engine. My configuration would determine what the engine can see and do in that context: what modules to load; from where; with what default arguments 😇 ; etc.In this scenario, an individual module would typically not have its own
dagger.json: rather it would be commonly found at the root of the repo. For example mygithub.com/shykes/daggerversewould have adagger.jsonat its root, listing all my modules. If a module is not listed in that file, it does not exist in the daggerverse, and loading it should fail (even if there is a subdirectory at that name). This goes beyond what your current PR does, I think, by removing the role of the filesystem completely as module addressing. In the end I don't care so much about the module tree living in the filesystem, or in JSON - I just don't want it to straddle both. That's key to the simplicity, I think.Impact on sub-modules
If modules don't have their own config file, but are configured by a parent configuration, then the tree of sub-modules is centralized in the engine config, instead of being decentralized in each module's directory.
Impact on dependencies
This would impact where the dependency tree lives. A module's dependencies would live in the module's entry in the parent configuration.
Hopefully this section makes sense at least partially :) Thanks for reading this far.
sipsma commentedon Jan 22, 2024
@shykes
This is only true today (i.e. before the PR) if you aren't using
root.If you are using
rootthen the formula is more likemodule = directory + dagger.json + some parent directory. Andmy sub-modules = sub-directories of the directory pointed to by root that contain their own dagger.jsonThis is just worth noting because the intention around all this is to simplify that case by replacing
rootwithsource, but while also leaving the very simple default case whererootisn't being used today alone and as simple as it was before.I'd actually say that the formula is just
module = directory tree containing dagger.json + subpath.To explain, it might actually help to make a comparison with how golang modules work.
Say you in your go code import a package like
github.com/dagger/dagger/some/pkg:go.modfor that package may be insome/pkgor any of the parent directories, up to the root of the repo.go module = directory tree containing go.mod + subpathOur behavior is essentially the same, just replace
go.modwithdagger.json.e.g. if you run
dagger functions -m github.com/shykes/daggerverse/mymod, then:dagger.jsonfor that module may be inmymodor any of the parent directories, up to the root of the repo.The workdir of a module starts at the module's source directory; this is unchanged from the previous behavior.
The directory up to dagger.json is available too, just at parent paths (also same behavior as before, except it was instead "the directory up to where
rootpointed to).There's been discussion about this a few times and while it's not 100% clear cut, each time so far we've come to the conclusion that it's probably better to have the workdir set to the source code directory since it allows you to reference paths in your module's source code that are actually relative to the source code file you are authoring.
host().directory("./some/path")then./some/pathis relative to the file you are actually authoring, no mental path arithmetic needed.This is similar to other tools like
go testthat have the same behavior of making the workdir of code being executed set to the dir containing the source file (cc @vito who made that very nice comparison).If I understand the question, it just depends on the layout of your repo and where the files you want to load are located. That is more of a factor of the user's particular use case and the existing structure of their monorepo. The main thing is that you can reference those paths relative to the module's source code file (as described above).
It's certainly possible, but we'd end up essentially just renaming the API, with the behavior otherwise being the same.
I.e. assuming we rename
Host->Local, then calls that introspect would look like:Those look pretty reasonable to me, so I'm not sure if we get much out of changing the API names more than that.
I have been imagining that
dagger.jsonis reserved for "static author-specified" configuration, and that support for "runtime caller-specified" configuration would just be a different file+mechanism.I see the appeal of unifying the two if feasible, trying to imagine how the details would work out though.
If you have a
dagger.jsonin your home directory with some module namedfoospecified and pointing togithub.com/org/daggerverse/foo, then would you run:dagger call -m foo(with configuration to your call in~/dagger.jsonapplied) ?dagger call -m github.com/org/daggerverse/foo(with configuration to your call in~/dagger.jsonapplied)?What happens if you there's configuration in both a
~/dagger.jsonand thedagger.jsonin the root of a git repo for a module you execute? Are both applied? Overlayed? Etc.I don't have a fully formed opinion yet here, just asking more questions to clarify what you were imagining for now.
shykes commentedon Jan 23, 2024
Yes, you're right.
Yes, I do like the "auto-findup" behavior, I agree we should do that.
There is one notable difference though: Go has both module and package, but Dagger only has module, which sort of combines both concepts.
Granted I was in a noisy cafe last time I heard this discussed, and couldn't properly share my thoughts, but for the record I still strongly believe this should be changed before launch.
I propose
module().source().directory("./some/path")which 1) doesn't require mental path arithmetic either, and 2) makes it clear and explicit what you are getting: the module's source directory.I understand the appeal (
makealso comes to mind, its workdir is set to the directory containing the Makefile). But I think our situation is different thango testandmakein one important way: a Dagger module has both a source directory and context directory, and the module may need to introspect both.I think that can be distilled into these two rules:
host().directory(".")dagger.json), openhost().directory(REVERSE_MODULE_PATH), whereREVERSE_MODULE_PATHis something like../../..: the path from the module source up to the enclosing dagger.json.A few problems with this:
host().directory(".")would point to one vs. the other. For example if my app repo has adagger.jsonconfiguring a module at./ci, it would be equally reasonable IMO, to expecthost().directory(".")to return the either the repo root, or./ci.host().directory(".")now mean very different things inside and outside a Dagger function; which adds a pebble in the shoe of devs porting their custom client to functions.To clarify, I am not talking about deprecating
host.directory()(poor choice of words on my part). I'm talking about not using it for the purpose of introspecting module source code. Whether we deprecate or rename that particular host API call, is orthogonal.That was my assumption also, but this thread is pulling me in a different direction at the moment 😁
I think both would work.
~/dagger.jsonandgithub.com/org/daggerverse/dagger.jsonwould be applied, per the usual find-up system.I think they would be overlayed, to allow 1) publishers to configure their modules, and 2) consumers to override them locally.
And it's very appreciated :)
sipsma commentedon Jan 24, 2024
(just getting back on one point to start)
Working through what this (and the related suggestions) would look like concretely so I can be 100% sure we're on the same page (please bear with the pedantic minutia):
In that case the "context dir" is
subdirand the "source dir" issubdir/mymod(relative to the context dir, it is./mymod).When the module executes, the container it runs in mounts the context dir to
/mnt(noting so I can be maximally concrete below)./src, but avoiding that because the name is confusing in this discussion and the name doesn't fundamentally matter, could be/fjfkdlafor all we care.)So in the container it would look like:
In what you're proposing (iiuc), the process's cwd (i.e. ".") would be the context dir, so absolute path
/mnt. And the module source directory would be available at./mymod.Thus
dag.Host()would have the following behaviordag.Host().Directory(".")dag.Host().Directory("./mymod")foo.txtdag.Host().File("./otherdir/foo.txt")bar.txtdag.Host().File("./mymod/modsubdir/bar.txt")You're additionally suggesting that there would also be a
dag.Module().Source()API, such that:dag.Module().Source().Directory(".")foo.txtbar.txtdag.Module().Source().File("./modsubdir/bar.txt")Is this accurate in terms of your suggestion?
If so, my main hesitation is that it just feels asymmetric that for the context dir you use
dag.Hostand the source dir you usedag.Module().Source.What would you think about these tweaks:
dag.CurrentModule().Context().Directory(".")- refer to the context directorydag.CurrentModule().Source().Directory(".")- refer to the source directory(I switched to
CurrentModulebecause that's an api that already exists for a module to refer to itself).In this scenario,
.Context()and.Source()would refer to the "frozen" snapshot of the respective dirs as they were loaded into the engine.Given the above, I'd also be okay with the module process's current working directory changing to be the context directory since it becomes less relevant.
The last wrinkle in all of this is the question around whether
dag.Host().Directoryeven needs to exist at all anymore if we go with the above.The technical difference is that
dag.Host().Directoryby its nature refers not to the frozen snapshot but to the actual live filesystem in the container, including any changes that may have been made to it during module function execution.On one hand, it's extremely appealing to just disregard this and say that a module can never refer to files created/modified during execution. That would actually allow us to potentially just remove
dag.Host()from the API presented to modules entirely and solve a bunch of problems at once.The counter-argument is that there are pretty compelling use cases for being able to create/modify files in function code directly and then use them in the dagger API.
Containerand callWithExec.So my preference would be that:
dag.CurrentModule().Context()anddag.CurrentModule().Source()are the "goto" simple APIs typically needed for any of these use cases.dag.Host().Directory()is still available, but only needed in more advanced cases where function really wants to refer to live changes made in the containerI'd also not strongly object if others have a preference for ignoring the
dag.Host().Directoryuse-case in the short term since this is one thing we can backwards-compatibly add in the future.I'll stop ranting here to checkpoint, let me know what you think.
sipsma commentedon Jan 24, 2024
RE: consolidating runtime+author configuration into
dagger.jsonKnow you have some more ideas here we're gonna sync up on, just working through the idea in detail myself ahead of time.
(I'm gonna be adding details here for the sake of getting the point across, not fully coherent)
Say there's a module at
github.com/org/daggerverse/hugothat has functions for building static hugo-based websites based on a caller-provided directory of the website's source code.The layout of the
github.com/org/daggerverseis:Sketch of that module's code at
./hugo/main.go:dagger.jsonhas contents:{ "modules": [ { "name": "hugo", "sdk": "go", "source": "./hugo" } ] }Now let's say that I'm a caller of that module. On my local machine
~/dagger.jsonhas contents:{ "modules": [ { "name": "hugo", "source": "github.com/org/daggerverse/hugo", "defaultArgs": { "website-source": "/home/me/my-cool-site", "api-key": "file:/home/me/.hugo-api-key" } } ] }Now I can run things like this for example:
dagger call -m hugo -o /tmp/site built/tmp/sitedagger call -m hugo container publish docker.io/me/my-sitedagger call -m hugo container upThe behavior is such that:
-m hugoand am not locally in a module subdirectory, so the CLI defaults to~/dagger.jsonand finds a module namedhugo, uses thesourcethere, etc.defaultArgskey indagger.jsonapplies to module constructorsdefaultArgshas the same semantics as the CLI in terms of conveniences like providing args of typeDirectoryas a local path, secrets asfile:..., etc.I also like that this could probably give us a path to:
defaultArgsis set in the dagger.json of a module in a git module.GOPROXY, various secrets that might be needed, etc. which comes up from enterprise use-cases all the time.Overall I really like many aspects of this, a few places of minor concern/questions:
defaultArgson moduledagger.jsonconfigsI purposely left out
defaultArgsfrom thedagger.jsonofhugoin thegithub.com/org/daggerverserepo.The reason is that modules already have a way of specifying/handling default arg values in the code itself. While it certainly could be logically coherent to have
defaultArgsin thedagger.jsonof thehugomodule, I don't love that it would mean there's now multiple different ways for a module to define defaults.If we did support
defaultArgson thedagger.jsonof modules likehugo, then we'd also need to decide how to handle default values of secrets without compromising security (either don't allow it or go full blown trust model).Ambiguities around
-m <name>and behavior in local module dirsThere's gonna be a bunch of dumb corner cases around e.g.
-m hugoand whetherhugois referring to a module at a local relative pathhugoor a module namedhugothe "find-up"dagger.json.I highly suspect we could deal with those in an intuitive way for 99.9% of cases, just something we'll need to be careful about.
And actually now that I type this out loud, those ambiguities exist to an extent in the also dumb corner case of
github.com/org/repo/modulereferring to a git repo or a local dir that happens to be named that. So not actually a new problem overall.helderco commentedon Jan 24, 2024
That looks golden to me! 👍
Even though you can get source from a subdir of context, you don’t have to rely on a relative path that can change. However, some times you do need to have that information, many times statically (e.g., in a go.mod), but I’d like to have a way for the API to tell me the relative path between them. Could be just
.Source().Path(ctx)(or.Source().Directory().Name(ctx)).I prefer it to be the context dir, thinking of the times I’d want to use
dag.Host()instead of the other ones. It also makes you rely more on.CurrentModule.Source()when that’s what you need.Rather than deprecating it only on modules, I say leave it to documentation. It may ease transition too, especially if the context is the workdir (assuming lots of usage for calling on a subdir like
dagger run go run ./ci/main.go).The worry is that people will leave that part instead of changing, but if the docs overwhelmingly show using
CurrentModule().Context(),CurrentModule().Source()andDirectoryas an arg, I’m hopeful that it’ll catch on.Of course there’s the renaming to
.Local()idea that deprecates.Host()(still allowing smoother transition), but letting the user know this should be changed, so now you make a choice.🙌
Can also be used for global excludes, since everyone uses different tools that leave all sorts of files around.
The global config file could also be used for engine wide configs, like passing on proxy env vars to the engine itself. They could be two different files though.
Can be managed with
dagger config. There’s lots of tools that do this. Git comes to mind (global and local configs). Hatch, which is the project manager we use on the Python SDK, also has this kind of project specific defaults in the global configuration.Yeah, whenever I talk about a config file to make the CLI calls simpler, it’s always a runtime thing, not authoring.
However, for project specific configs I usually think about a file placed where the user most likely makes the
daggercalls from (the “app", not the module), that can be committed to git for sharing, and it includes all args and flags (using viper for this). But both can work, so the CLI can use global defaults (e.g., excludes, secrets, env vars to pass to the runtime container), project specific defaults in git (e.g., default args) and still be able to override with CLI args (again, viper makes this easy, including accessing nested keys matching the call chain).shykes commentedon Jan 25, 2024
We discussed this live with @sipsma today, and made some good progress. Here is a summary below:
dag.Host().Directory(".")should stay, but map to a scratch directory./and.would both return the scratch. This avoids leaking internal details about the runtime container, which feels "dirty" to me. From there, maybe it becomesdag.Workdir().Directory(")", just saying :)dag.CurrentModule().Source().Directory("."): works great. SH note: I want to bikeshed the exact API here, to make it shorter :) But that can waitdag.CurrentModule().Context(): not a thing, we cut it. Rationale: there is no clear use case for a module author to introspect that directory. And it opens a backdoor to a "shadow API", if the module is loaded from a monorepo that also contains app source code, and the module relies on that as a default value, for example. No strong benefit + clear strong downsides = cut it.sourcefield etc. But only exposed to SDKs, not to functions for introspection (see previous point)dagger installmodules without having to write code? This would add pinned dependencies indagger.jsonthe usual way, but thesdkandsourcefields would not be set.dagger callwould support looking up dependencies by short name. Sodagger install github.com/shykes/daggerverse/tailscalewould install a pinned version of that module to the currentdagger.json(which could be in my home directory or app repo), thendagger call -m tailscalewould call the exact pinned version I installed. Later, if I want to add code to my module, I add thesdkfield (command TBD here), and my same dependencies are codegened the usual way. This makes for a smoother learning curve.dependencies+modulescreates confusion: there are sub-modules, and there are dependencies, they are similar but different. But maybe I am overthinking it - we ran out of time and couldn't resolve that. It feels like we're really close though@sipsma let me know if I missed anything
sipsma commentedon Jan 25, 2024
Yeah I'm very happy with where we landed in terms of Context dir not being a thing except to SDKs, considering that whole side of things to be closed 🙂
Been wracking my brain over this for a while trying to get the pieces to fit together... trying out something:
User runs
dagger mod init(no args). Adagger.jsonis created that is empty, i.e.{}.User runs
dagger mod install github.com/foo/bar/[email protected].dagger.jsonis updated to:{ "dependencies": [ { "name": "tailscale", "source": "github.com/foo/bar/[email protected]" } ] }User can now run
dagger call -m tailscale ....User now wants to write module code using the current
dependenciesin thedagger.json. They rundagger mod update --name mymod --sdk go,dagger.jsonnow looks like:{ "name": "mymod", "sdk": "go", "source": ".", "dependencies": [ { "name": "tailscale", "source": "github.com/foo/bar/[email protected]" } ] }And the module source code (i.e.
main.goand codegen) is placed in the same dir as thedagger.json.Now you can do
dagger call -m mymod ...to call your own functions.dagger call -m tailscale ...still works too though.Now to get to a more complicated but totally valid use case, say you want to add another local module that's in a subdir and used by
mymod.dagger.jsonis in your home dir but you want to add a new module just on your machine and use it, etc.This would be done via
dagger mod init -m ./some/subdir --sdk go --name othermod.dagger.jsonis updated to look like:{ "name": "mymod", "sdk": "go", "source": ".", "dependencies": [ { "name": "tailscale", "source": "github.com/foo/bar/[email protected]" }, { "name": "othermod", "sdk": "go", "source": "./some/subdir" } ] }Now say
othermodneeds some other dependency, you could rundagger mod install -m othermod github.com/foo/bar/[email protected].-m othermodindicates you are adding a dep specifically toothermod.dagger.jsonnow looks like:{ "name": "mymod", "sdk": "go", "source": ".", "dependencies": [ { "name": "tailscale", "source": "github.com/foo/bar/[email protected]" }, { "name": "othermod", "sdk": "go", "source": "./some/subdir", "dependencies": [ { "name": "hugo", "source": "github.com/foo/bar/[email protected]" } ] } ] }Basically, the idea is that
dependenciesis the same struct "all the way down", if that makes any sense.The important property that's retained with this sort of approach is that each module can have its own list of dependencies. In the "monorepo of many modules" use case, I think this is important. You don't necessarily want each module to have the same set of dependencies just because they are in the same
dagger.json. They might not need the same deps or may even need some overlapping set of deps but at different versions.There are warts remaining in this, namely:
dagger call -m hugo .... Basically,dagger call -mwould be limited to "top-level" modules in thedagger.json(i.e.mymod,tailscaleandothermodin the example above)dependenciescould go. I can imagine how it would be implemented to arbitrary depth, but it would allow our users to get into situations that are so confusing it might be safer to just stop it early.Here's one alternative that I'm considering that trades the "recursive
dependencieskey" for separatedagger.jsonfiles.The idea is that you'd have local modules like
othermodalways get their owndagger.jsonseparate from the "parent" one, with the parent one just pointing to the child one and relying on "find-up" behavior from there.So in that case, the "top-level"
dagger.jsonwould look like:{ "name": "mymod", "sdk": "go", "source": ".", "dependencies": [ { "name": "tailscale", "source": "github.com/foo/bar/[email protected]" }, { "name": "othermod", "source": "./some/subdir" } ] }And there would also be a
dagger.jsonin./some/subdirthat looks like:{ "name": "othermod", "sdk": "go", "source": ".", "dependencies": [ { "name": "hugo", "source": "github.com/foo/bar/[email protected]" } ] }The CLI+engine would handle all the complication around the "find-up" behavior, so I believe it could be hidden from users for the most part, but the tradeoff being more
dagger.jsons.Honestly, now that I type this out, I might like this one a little bit better surprisingly? It feels a little more cohesive. The recursivedependenciesis kind of a scary wart in the other approach, though the extent to which it actually complicates things in practice is not entirely clear to me yet.EDIT: I just remembered that this greatly complicates the case where the module in a subdir has deps on other modules in the repo... 🤦♂️ Essentially brings us back to
rootor close equivalents. So maybe not....shykes commentedon Jan 26, 2024
Yes I agree.
:( Can you elaborate on how it complicates it?
shykes commentedon Jan 26, 2024
Throwing this at the wall: an example of a repo with many modules, that need to share the same go.mod for policy reasons.
{ "dependencies": [ { "source": "./go" "context": "." }, { "source": "./tailscale", "context": "." }, ] }The point is that the parent can specify an optional
contextdirectory to be passed to each dependency's SDK, in the manner that we already discussed. This way, no path ever needs to include... And, we no longer need a distinctmoduleskey: everything can be underdependencies, and every module can have its owndagger.jsonwithout breaking the model.sipsma commentedon Jan 26, 2024
I'll run through concrete examples again to try to explain (and maybe see if there's a way to make it work):
Use case here is say you are daggerizing an existing monorepo and will be adding multiple modules to it and those modules have deps
User runs
dagger mod init(no args) in the root of a repo (as checked out to their local machine). Adagger.jsonis created that is empty, i.e.{}.User runs
dagger mod init -m ./somedir/modA --name=mod-a --sdk=go.The top-level
dagger.jsonis updated to be:{ "dependencies": [ { "name": "mod-a", "source": "./somedir/modA" } ] }And another
dagger.jsonis created in./somedir/modAwith:{ "name": "mod-a", "sdk": "go", "source": "." }Now they do the same thing but for
modB, so they rundagger mod init -m ./otherdir/modB --name=mod-b --sdk=python.The top-level
dagger.jsonis updated to be:{ "dependencies": [ { "name": "mod-a", "source": "./somedir/modA" }, { "name": "mod-b", "source": "./otherdir/modB" } ] }And another
dagger.jsonis created in./otherdir/modBwith:{ "name": "mod-b", "sdk": "python", "source": "." }Now let's say that the user wants
modAto depend onmodB. The syntax could bedagger install -m modA modB(idea being that-m modAsays you are operating onmodAand you specifically are installingmodB).What caused me to hesitate is what the
dagger.jsonupdates would be. I specifically don't like the idea of./somedir/modA/dagger.jsonnow looking like:{ "name": "mod-a", "sdk": "go", "source": ".", "dependencies": [ { "name": "mod-b", "source": "../../otherdir/modB" } ] }But... I suppose it's not quite as bad as
rootbecause the path arithmetic can be entirely hidden from the end user at least 🤷♂️ It'd all be automated in the CLI and engine. And we can continue enforce that any paths never escape a.gitroot to avoid security problems of an e.g. maliciously crafted dagger.json.And I suppose another option would be that
./somedir/modA/dagger.jsoncould be unchanged, and insteaddagger.jsonin the root of the repo is instead updates like this:{ "dependencies": [ { "name": "mod-a", "source": "./somedir/modA", "dependencies": [ { "name": "mod-b", "source": "./otherdir/modB" } ] }, { "name": "mod-b", "source": "./otherdir/modB" } ] }That would avoid a need for any paths to ever have
../elements.The implementation and behavior of that approach in particular is a bit hard to fully piece together though. My instinct would be that in order to fully determine the configuration of a given module, you need to "find-up" not just once but through multiple
dagger.jsons.That's not awful, though there would still be corner cases, like what if I had
dagger.jsonin my home directory and the local checkout of the repo happened to be a subdir of my homedir? I wantdagger install -m modA modBto specifically update thedagger.jsonof the git repo checkout root, not my homedir (at least in this case)..gitdirdagger install --config-dir . -m modA modBsipsma commentedon Jan 26, 2024
Discussed more with @shykes, landed here (gonna use the same example as my last comment to save time):
Use case here is say you are daggerizing an existing monorepo and will be adding multiple modules to it and those modules have deps
User runs
dagger mod init(no args) in the root of a repo (as checked out to their local machine). Adagger.jsonis created that is empty, i.e.{}.User runs
dagger mod init -m ./somedir/modA --name=mod-a --sdk=go.The top-level
dagger.jsonis updated to be:{ "root-for": ["./somedir/modA"] }And another
dagger.jsonis created in./somedir/modAwith:{ "name": "mod-a", "sdk": "go", }Now they do the same thing but for
modB, so they rundagger mod init -m ./otherdir/modB --name=mod-b --sdk=python.The top-level
dagger.jsonis updated to be:{ "root-for": ["./somedir/modA", "./otherdir/modB"] }And another
dagger.jsonis created in./otherdir/modBwith:{ "name": "mod-b", "sdk": "python", }Now the user runs
dagger install -m modA modB. Top-leveldagger.jsonis unchanged../somedir/modA/dagger.jsonis updated to:{ "name": "mod-a", "sdk": "go", "dependencies": [ { "name": "mod-b", "source": "../../otherdir/modB" } ] }Find-up logic in the engine is implemented such that the context dir of a module is the
dagger.jsonthat contains theroot-forkey for the module (or, if there is no suchdagger.json, then the context dir is implicitly just the module's source dir). It also handles making sure any..paths don't escape the context dir.For completeness, say you wanted the top-level module to be an actual sdk-full mod. You could do
dagger mod config --sdk=go --name=top-level. Top-leveldagger.jsonnow looks like:{ "name": "top-level", "sdk": "go", "root-for": ["./somedir/modA", "./otherdir/modB"] }And then if you wanted to add a dep on one of the submodules, you'd run
dagger mod install -m top-level ./somedir/modAand it would be updated to look like:{ "name": "top-level", "sdk": "go", "dependencies": [ { "name": "mod-a", "source": "./somedir/modA" } ] "root-for": ["./somedir/modA", "./otherdir/modB"] }EDIT: fixed accidental inclusion of redundant
"source": "."field in each dagger.json, which isn't needed since source is always inherently..shykes commentedon Jan 26, 2024
Thanks for the writeup! I really like this design.
Adding some polish bikeshedding as promised:
dagger init: Initialize a moduledagger install: Install a moduledagger doc: Print a module's API documentationdagger call: Call one or more functionsdagger run: Run a script that can call functionsdagger sdk [go|python|ts]: install an SDK, or print the installed SDKdagger develop: prepare a dev environment for developing functions. Requires installing an SDK.dagger update: Update installed modules and SDKdagger test: Test a moduledagger serve: Serve a module's HTTP APIdagger logindagger logout