Repository navigation
Description
UPDATE
Here's the conclusion:
- Go SDK lives in
sdk/golike the rest of the SDKs- Versioned independently from the rest of the Go code using an
sdk/go/vX.X.Xtag - Uses its own vanity URL (
dagger.io/dagger), independent from the rest of the Go code
- Versioned independently from the rest of the Go code using an
- The root of this repository is a single go module (aside from the SDK sub-directory)
- Contains the engine (and whatever else we want -- nobody is supposed to import it)
- Will be versioned as
v0.3.0-alpha.1 - No binaries will be released at this point
Background
This aims to cover these 2 questions:
- Are SDKs vendored independently? e.g. Go SDK v0.1.0
- Does the Go SDK have its own import path (e.g.
dagger.io/daggeror is it a relative from the repo (e.g.dagger.io/dagger/sdk/go/dagger)?
Topics are connected yet we can decide individually. Note however that:
- We can use the SAME version with different import paths
- However we can't use DIFFERENT versions for the same import path
- A
YESto either requires for the SDK to be its own module.
Risk
The main drawback of having a different module is it makes it much harder to do cross-module changes. Effectively, it's just as hard as with multi-repository and we lose a lot of the monorepo advantages.
Example:
- Merge a PR that touches both the engine and the Go SDK
- Now,
go get dagger.io/dagger@mainis broken -- Go SDK still imports Engine from last release - Tag a new engine version
go get -u enginefrom the SDK, git commit, open PR, merge- Tag a new Go SDK version
go get -u sdknow incorporates both changes
Because of this, if we go this route, I strongly suggest for the SDK to be the only other module. If we generalize this pattern to all sub-components we'll be living in a world of pain.
That being said, I don't find it weird to special-case the Go SDK since all SDKs are special in their own way: they each have a separate import/publish/dependency mechanism (e.g. python, node) and this effectively makes the Go SDK behave exactly like the others.
For instance, in the example above, making a change to the Engine and all SDKs will require a similar process (e.g. tag a new engine, and for each SDK update the engine dependency one way or another).
Versioning Trade-Offs
- Using the same version everywhere simplifies the process (one release workflow, channel, schedule)
- Separate versioning provides flexibility (e.g. don't release SDKs weekly if there are no changes, etc)
Proposal
- Go SDK gets its own
go.modand its own import path- Consistent with the other SDKs that have their own "module" (
package.json) and import name (@dagger-io/dagger), independent from the rest of the repository - Import path will be
dagger.io/dagger-- see Go SDK: Move to its own go.mod and vanity URL #3416 (comment)
- Consistent with the other SDKs that have their own "module" (
- Rest of the dagger codebase lives in the same
go.mod- I strongly suggest we DO NOT create a
go.modfor every sub-component (e.g. engine). That would be a huge pain to maintain (see above) - However we shift everything under a sub-directory to avoid polluting the top-level repo
- Proposal:
engine- However it'll be weird to have
engine/engine(rather thanpkg/engine) and I don't think we can make that package top-level because of cyclics - And CLIs in Go by convention live in
cmd(e.g.cmd/dagger, maybe somedaycmd/dagger-engine, etc). It would be unusual to haveengine/cmdandcli/cmdinstead. - So long as it's the same go.mod, and no-one is supposed to use the module directly, it can be easily changed
- Edit:
enginepackage is now the primary proposal,pkgsecondary (@dolanor changed my mind)
- However it'll be weird to have
- Alternative:
pkg- Inspired by the pulumi repo which has
pulumi/sdkandpulumi/pkg pkgis pretty standard as far as Go repositories go
- Inspired by the pulumi repo which has
- I strongly suggest we DO NOT create a
- SDKs are versioned independently
- Git tag will be
sdk/<lang>/<version>, e.g.sdk/go/v0.1.0 - go.mod will take that tag into consideration (e.g.
<go.mod relative path to repo>/<tag>)
- Git tag will be
Visual Proposal
| Name | Git Path | Go Module | Go import | Tag |
|---|---|---|---|---|
| Engine | github.com/dagger/dagger/engine | github.com/dagger/dagger | github.com/dagger/dagger/engine | v0.3.0-alpha.1 |
| Go SDK | github.com/dagger/dagger/sdk/go | github.com/dagger/dagger/sdk/go | dagger.io/dagger | sdk/go/v0.1.0 |
Activity
aluzzardi commentedon Oct 18, 2022
NOTE: Separate SDK versioning WILL require to ship an engine
0.3.0-alpha.1alongside (just the tag), since the Go SDK needs to import it.dolanor commentedon Oct 18, 2022
Noice!
(source: https://go.dev/doc/modules/managing-source)
That solves my blocking of the multi module idea.
On package naming, I'm not a fan of
pkgbecause it doesn't communicate anything.engine/enginewould make more sense to me thanpkg/engine. Also, maybe the wholeenginesubdir could have the engine code, with other subdirs having parts of that engine logic handled.Also, engine would be supposed to be used outside of dagger codebase, I guess it should live in
internal/engine, so nobody can import it anyway.2nd argument against
pkgis that it has been deprecated withinternal. It was done in the past because we missedinternal, now we have it, so let's get rid ofpkg: https://twitter.com/bradfitz/status/1039512487538970624Questions
For me
I'm for a SDK module with its own tags.
I'm for keeping the codebase as is otherwise (with a top level module if possible). No
pkgsubdir.If not possible, then, put the code in an engine subdir with its own module.
Conclusion
Yes
Since it should be the only importable code from dagger in Go, yes, it could.
aluzzardi commentedon Oct 18, 2022
Yes, we can have a top-level module with a SDK sub-module and no we don't have to have 2 different subdirs.
However, that part of the proposal was in response to @shykes's comment about the top-level repository becoming confusing, hence the suggestion to move everything into a sub-package so the repo will look like "engine", "sdk", "examples", "docs", etc.
👍
You convinced me (it was 50/50 for me), I've updated the proposal
👍
marcosnils commentedon Oct 18, 2022
What's the "advantage" of keeping the Go SDK in the same repo vs split it to a new one if we're still going to be handling different releases and versioning?
Is the plan for all SDK's to live in the same
dagger/dagger? or this is a special decision for the Go SDK and all the other SDK's will live in different repos?Is this compatible with all package managers
pip, npm, maven, gradle, etcto use a non top-level path to package the SDK's?aluzzardi commentedon Oct 18, 2022
Monorepo.
For instance, today, every change to the API requires a change to the SDK for codegen. Managing that across a bunch of repositories is very painful.
References issues, PRs, release automation, etc is easier on a monorepo.
Yes.
sdk/<lang>I assume so, that's how pulumi does it: https://github.com/pulumi/pulumi/tree/master/sdk
shykes commentedon Oct 18, 2022
marcosnils commentedon Oct 18, 2022
Yes, that makes sense. I'm also in for this, the trade-offs seem to be the most balanced and beneficial to us!
vito commentedon Oct 18, 2022
re
pkg: I like it, but I'm biased. It's true that Go itself dropped it, but I wouldn't take that as a sign that it's deprecated in the entire ecosystem. I thinkpkghas taken a meaning of its own as the Go equivalent ofsrc/for organizing the Go application code in a monorepo that also contains a lot of other non-Go things. Bass for example has a ton of toplevel directories for various project-level-but-not-Go-package things. I like havingpkgjust for keeping tabs on the actual application code, as opposed to demos, docs, scripts, protobuf definitions, etc. etc.As a minor point, I also like that tucking things under
pkgcan let the README show up above-the-fold and make the repo seem less complicated. 😄But I'm good with
engineif we think 100% of our code will either land underengine/orsdk/.re
internal/, I think this is solving a different problem from the point ofpkg/described above. I don't think we need to put everything under an internal package and hide it away. I'm not a fan of overly defensive project/code organization. Let people hack if they want. I'd like to import Dagger's engine for Bass's Dagger runtime until we figure out the progress API, for example. Pretty please? 😛re multiple modules: assuming the ultimate goal here is to have a smaller dependency footprint for SDK users and eventually dodge the Buildkit
replacegotcha, I think this makes sense. I would only ask that we have clearly documented/automated paths for day-to-day things contributors may run into, since it's a little unusual.shykes commentedon Oct 18, 2022
aluzzardi commentedon Oct 18, 2022
vito commentedon Oct 18, 2022
Maybe I'm misunderstanding, but it seems to me that making it a sub-package of the SDK (e.g.
dagger.io/sdk/engine) would make it more within reach/accidentally discoverable as opposed to living in a separate module without a vanity URL. Assuming that separate module never appears in our docs and has scary godoc warnings guiding folks to the right place.shykes commentedon Oct 18, 2022
shykes commentedon Oct 18, 2022
aluzzardi commentedon Oct 18, 2022
shykes commentedon Oct 18, 2022
samalba commentedon Oct 18, 2022
Moving the engine under the Go SDK would be confusing (thinking especially about Python / Node who only need the engine as a dependency).
Here is what I would do (more or less what I saw in a previous proposal):
github.com/dagger/dagger/engine- version 0.3.0-alpha.Xgithub.com/dagger/dagger/sdk/<lang>- version 0.1.0 (each with its own versionning)To take a real example, if we bump the strawberry version of Python, we don't want to re-release the engine or the Go SDK.
shykes commentedon Oct 18, 2022
shykes commentedon Oct 19, 2022
aluzzardi commentedon Oct 19, 2022
UPDATE: Decision Tree Constraints
So here's the basics:
We should avoid go sub modules AT ALL COST unless there is ABSOLUTE NO other way (and even then ...)
go geteach other via public commits, even when the code is local), releasing has to be done in a very specific way (see the 6 step process in the description of this issue)enginetoworker? You're SOL, the tag saysengine/v0.3.0, it'll stay engine foreverengineunder a sub directory? Nope again. Relative module path is part of the tag. It'll stay where it is, or you break it all (engine/v0.3.0means the path must be./enginefrom the git root)cd github.com/dagger/dagger && go test ./integration--> gives one outcome (use local modules)go test gittub.com/dagger/dagger/integration--> DIFFERENT behavior. Will use vendored modules from git tags, not local codeIn short, they're a PITA we'll have to deal with daily. And that's only the tip of the iceberg. Did I mention
./...doesn't follow sub-modules? CI (and core developers) have to to run a different lint/test/build/generate/dependabot/etc job for each module. Can'tgo:embedbetween modules. Can'tgo:generatebetween modules. The LSP doesn't like sub-modules, you've got to open one vscode for each module. And those are just the problems I run into yesterday, imagine all the ones I didn't hit just yet.I don't see us NOT regretting using sub-modules. Using the same module all around works pretty well -- that's how (virtually) everyone does it.
And yet, it raises ONE issue for ONE component:
Whereas we're completely free to ship every component in any way we want (e.g. brew, tarballs, docker image, ...), the Go SDK is an exception: it can only be shipped using the Go module distribution.
Therefore, how we organize modules is directly visible to the user and becomes part of the API. That means:
import "github.com/dagger/dagger/sdk/go/dagger")This is in contrast with all other SDKs since:
@dagger-io/daggerfor node)npmjs.com)If that's not a problem, then we're good like it is today, no action required.
HOWEVER, remember -- modules are permanent. Their path is cemented in the tag name. So it must not be a problem neither today, nor in the future.
If we ever decide the Go SDK isn't special anymore (there's an engine and the Go SDK talks to it, like the others), and we want to organize it just like the other SDKs (e.g. custom distribution channel, custom versioning), then that decision must be taken TODAY.
There's no going back. Well, there is -- but it requires renaming all tags, changing the import path, doing weird hacks with the vanity URL and praying the Google proxy server doesn't hate you too much. I'd give it a 50/50 at best whether it can be done without breaking every single Go SDK installation out there.
Speaking of permanent, one last bit of background: The root directory of this git repository is a Go module. And its current version is
v0.2.36. That's a done deal.Whatever we do next, this fact cannot change -- we will have a
go.modat the root and we will version itv0.3.*or above. Its import path will be public facing, and sub-folders in this repository will be imported relative to that path. The exception is creating permanent sub-modules -- see rant above on why this is a last resort not to be toyed with.helderco commentedon Oct 19, 2022
I'll defer to the gophers but I'm ok with making the Go SDK a special case to avoid these headaches. Not worth it.
gerhard commentedon Oct 19, 2022
I went over this thread a few times. This is my understanding so far:
dagger/dagger<version>format (special case)sdk/<lang>/<version>cli/<version>engine/<version>If I misunderstood something above, please mention it.
This is not clear to me just yet:
go.modfor the Go SDK, CLI & Engine @aluzzardi?I have a related question which doesn't belong with those above: should we conclude #3347 before we finalise #3424? This thread reads to me as if we have already decided on the CLI & Engine separation which implies that #3347 is resolved. If that's the case, we should update #3347 accordingly. I suspect that many of us are paying a heavy context switching tax - I would welcome fewer big threads in flight.
#3271 is still in flight and closely related to this issue. There could be others, but this is my WIP limit.
These are the logical next steps which I am seeing:
In the meantime, I will check if there are any in-flight PRs which I can help move along. Given the state of this thread, I don't see any other actionable task for the upcoming release that I could take on.
dolanor commentedon Oct 20, 2022
NB: I don't actually have experience with multi modules except for playing with Go module workspace for a very little bit. So take any of my reaction with a grain of salt.
Did you try with local
replacedirective in yourgo.mod?if the engine at v0.3.0 was tagged
engine/v0.3.0, I don't see why we would want to rename it. If we rename it, it would be after theengine/v0.3.0tag, and therefore, if we rename it toworker, the new tag would beworker/v0.4.0. Checking out the repo atengine/v0.3.0should get us a FS with a module in theenginefolder. And if we checkoutworker/v0.4.0, the module should be in theworkerfolder, no?see above
This has been true since the Go modules and we said goodbye to GOPATH, though. The many modules wouldn't affect that?
That is true, and could be a pain…
I would believe that if we're there, we might have some architecture design flaw. But still, it some limitation that could be annoying.
Normally the module workspace is supposed to fix (or help) that: https://go.dev/doc/tutorial/workspaces. And I believe
goplsshould handle workspaces as well.I guess, if it was a terrible issue in the future, we could always create our own vanity module server that would modify the tags the way it want to get the result we want.
e.g.
But we could make the webpage at
go.dagger.ioactually change where it points to.Seems like PITA, but if it's what's needed to not break clients, I guess it would be one way to do it.
aluzzardi commentedon Oct 20, 2022
Here's the conclusion:
sdk/golike the rest of the SDKssdk/go/vX.X.Xtagdagger.io/dagger), independent from the rest of the Go codev0.3.0-alpha.1Answering @gerhard's questions to add some clarity:
Yes
No exception. It's going to be
sdk/go/v0.1.0(just like it will besdk/python/v0.1.0)Go is the same
Yes
No. There are only 2 go modules: root (
<version>) and Go SDK (sdk/go/<version>).CLI is going to one or another. Decision needs to happen by first non-Go-SDK, which gives us a couple of weeks to figure that out.
No. Again, aside from SDKs, everything is versioned in lockstep.
Yes, but not until we have a non-Go SDK. Go SDK will use Go distribution (e.g.
go get) to grab the "engine".sdk/goTBD. Currently it's
cmd/dagger.@shykes suggested to put it in the Go SDK, but haven't decided on that yet (again, it's a few weeks out)
It's in
dagger/dagger. Not a concern for users as nobody is supposed to import it directly.There are 2 go.mod:
go.modinsdk/go(just like there's apackage.jsoninsdk/nodejs)go.modfor everything elseThe Go SDK imports the engine instead of spawning it as a binary (because it can). This is an internal detail and subject to change -- the fact that it's being imported is invisible to the user, they use the SDK and it works. How it works is a concern of the SDK.
shykes commentedon Oct 20, 2022
I will start a separate thread to discuss CLI packaging and release. There are various constraints to consider.
Like @aluzzardi said, this is why it's important to not release a CLI this week, or make any change that reduces our option in CLI packaging. This way we have a little more time to decide on CLI.
shykes commentedon Oct 20, 2022
@aluzzardi since we have consensus, may I suggest updating the body of this issue for clarity? Before someone changes their mind ;)
gerhard commentedon Oct 24, 2022
That was all super helpful @aluzzardi, thank you.