Skip to content

Go SDK: Versioning and Import Path #3424

Closed

Description

@aluzzardi

UPDATE

Here's the conclusion:

  • Go SDK lives in sdk/go like the rest of the SDKs
    • Versioned independently from the rest of the Go code using an sdk/go/vX.X.X tag
    • Uses its own vanity URL (dagger.io/dagger), independent from the rest of the Go code
  • 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:

  1. Are SDKs vendored independently? e.g. Go SDK v0.1.0
  2. Does the Go SDK have its own import path (e.g. dagger.io/dagger or 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 YES to 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:

  1. Merge a PR that touches both the engine and the Go SDK
  2. Now, go get dagger.io/dagger@main is broken -- Go SDK still imports Engine from last release
  3. Tag a new engine version
  4. go get -u engine from the SDK, git commit, open PR, merge
  5. Tag a new Go SDK version
  6. go get -u sdk now 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.mod and its own import path
  • Rest of the dagger codebase lives in the same go.mod
    • I strongly suggest we DO NOT create a go.mod for 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 than pkg/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 someday cmd/dagger-engine, etc). It would be unusual to have engine/cmd and cli/cmd instead.
      • 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: engine package is now the primary proposal, pkg secondary (@dolanor changed my mind)
    • Alternative: pkg
      • Inspired by the pulumi repo which has pulumi/sdk and pulumi/pkg
      • pkg is pretty standard as far as Go repositories go
  • 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>)

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

  1. aluzzardi commented on Oct 18, 2022

    @aluzzardi
    ContributorAuthor

    NOTE: Separate SDK versioning WILL require to ship an engine 0.3.0-alpha.1 alongside (just the tag), since the Go SDK needs to import it.

  2. dolanor commented on Oct 18, 2022

    @dolanor
    Contributor

    go.mod will take that tag into consideration (e.g. <go.mod relative path to repo>/)

    Noice!
    (source: https://go.dev/doc/modules/managing-source)
    That solves my blocking of the multi module idea.

    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.
    The fact that each SDK will have its own system also make the idea of having a dedicated module for SDK makes sense to me.

    On package naming, I'm not a fan of pkg because it doesn't communicate anything. engine/engine would make more sense to me than pkg/engine. Also, maybe the whole engine subdir 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 pkg is that it has been deprecated with internal. It was done in the past because we missed internal, now we have it, so let's get rid of pkg: https://twitter.com/bradfitz/status/1039512487538970624

    Questions

    • Can we have a top level module, with the SDK module under?
      • do we have to split in 2 different subdirs?

    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 pkg subdir.
    If not possible, then, put the code in an engine subdir with its own module.

    Conclusion

    Are SDKs vendored independently? e.g. Go SDK v0.1.0

    Yes

    Does the Go SDK have its own import path (e.g. dagger.io/dagger or is it a relative from the repo (e.g. dagger.io/dagger/sdk/go/dagger)?

    Since it should be the only importable code from dagger in Go, yes, it could.

  3. aluzzardi commented on Oct 18, 2022

    @aluzzardi
    ContributorAuthor

    Can we have a top level module, with the SDK module under?

    do we have to split in 2 different subdirs?

    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.

    On package naming, I'm not a fan of pkg because it doesn't communicate anything. engine/engine would make more sense to me than pkg/engine. Also, maybe the whole engine subdir could have the engine code, with other subdirs having parts of that engine logic handled.

    👍

    You convinced me (it was 50/50 for me), I've updated the proposal

    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 pkg subdir.
    If not possible, then, put the code in an engine subdir with its own module.

    👍

  4. marcosnils commented on Oct 18, 2022

    @marcosnils
    Contributor

    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, etc to use a non top-level path to package the SDK's?

  5. aluzzardi commented on Oct 18, 2022

    @aluzzardi
    ContributorAuthor

    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?

    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.

    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?

    Yes. sdk/<lang>

    Is this compatible with all package managers pip, npm, maven, gradle, etc to use a non top-level path to package the SDK's?

    I assume so, that's how pulumi does it: https://github.com/pulumi/pulumi/tree/master/sdk

  6. shykes commented on Oct 18, 2022

    @shykes
  7. marcosnils commented on Oct 18, 2022

    @marcosnils
    Contributor

    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, that makes sense. I'm also in for this, the trade-offs seem to be the most balanced and beneficial to us!

  8. vito commented on Oct 18, 2022

    @vito
    Contributor

    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 think pkg has taken a meaning of its own as the Go equivalent of src/ 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 having pkg just 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 pkg can let the README show up above-the-fold and make the repo seem less complicated. 😄

    But I'm good with engine if we think 100% of our code will either land under engine/ or sdk/.

    re internal/, I think this is solving a different problem from the point of pkg/ 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 replace gotcha, 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.

  9. shykes commented on Oct 18, 2022

    @shykes
  10. aluzzardi commented on Oct 18, 2022

    @aluzzardi
    Author
  11. vito commented on Oct 18, 2022

    @vito
    Contributor

    At the very least, make it a sub-package of the SDK (so it's clear that it's not meant to exist standalone in the long term. The very existence of a dedicated go module sends the wrong message in that regard.

    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.

  12. shykes commented on Oct 18, 2022

    @shykes
  13. shykes commented on Oct 18, 2022

    @shykes
  14. aluzzardi commented on Oct 18, 2022

    @aluzzardi
    Author
  15. shykes commented on Oct 18, 2022

    @shykes
  16. samalba commented on Oct 18, 2022

    @samalba
    Contributor

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

    • Engine under github.com/dagger/dagger/engine - version 0.3.0-alpha.X
    • SDKs (Go, Python, Node, etc...) under github.com/dagger/dagger/sdk/<lang> - version 0.1.0 (each with its own versionning)
    • Go SDK imported via: "dagger.io/dagger"

    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.

  17. shykes commented on Oct 18, 2022

    @shykes
  18. shykes commented on Oct 19, 2022

    @shykes
  19. aluzzardi commented on Oct 19, 2022

    @aluzzardi
    ContributorAuthor

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

    • They make dependency management horrible. Modules have to vendor each other (e.g. go get each 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)
    • They are permanent
      • Want to rename engine to worker? You're SOL, the tag says engine/v0.3.0, it'll stay engine forever
      • Want to move engine under 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.0 means the path must be ./engine from the git root)
    • They mess with Go tooling
      • 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 code

    In 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't go:embed between modules. Can't go:generate between 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:

    • Official distribution channel (import path) is tied to the repository organization (e.g. import "github.com/dagger/dagger/sdk/go/dagger")
    • Versioning is in lock step with the rest of the module (e.g. there can be only ONE version for everything Go in the repo)

    This is in contrast with all other SDKs since:

    • Official distribution channel (import path) is whatever we want (e.g. @dagger-io/dagger for node)
    • Versioning can happen independently (e.g. 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.mod at the root and we will version it v0.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.

  20. helderco commented on Oct 19, 2022

    @helderco
    Contributor

    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.

  21. gerhard commented on Oct 19, 2022

    @gerhard
    Contributor

    I went over this thread a few times. This is my understanding so far:

    • All code (SDKs, CLI, Engine, docs, etc.) is stored in a single repository, dagger/dagger
    • Go SDK is versioned via the <version> format (special case)
    • All other SDKs are versioned as sdk/<lang>/<version>
    • All SDKs (including Go) are versioned independently
    • CLI is versioned independently, e.g. cli/<version>
      • This is a dependency of all SDKs, except Go
    • Engine is versioned independently, e.g. engine/<version>
      • We need this tag to build & distribute it (binary/OCI)

    If I misunderstood something above, please mention it.

    This is not clear to me just yet:

    • What is the Go SDK source code path be in this repo @aluzzardi?
    • What is the CLI source code path in this repo @aluzzardi?
    • What is the Engine source code path in this repo @aluzzardi?
    • Is there a single top-level go.mod for the Go SDK, CLI & Engine @aluzzardi?
    • Why are we embedding the engine in the Go SDK @shykes?

    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:

    1. Resolve 0.3 CLI design #3347
    2. Resolve Decouple SDK and engine releases and versions #3271
    3. Resolve this issue Go SDK: Versioning and Import Path #3424
    4. Take a checkpoint in Dagger 0.3.0-alpha.1 release #3283 and update with new tasks

    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.

  22. dolanor commented on Oct 20, 2022

    @dolanor
    Contributor

    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.

    * They make dependency management horrible. Modules have to vendor each other (e.g. `go get` each 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)
    

    Did you try with local replace directive in your go.mod?

      * Want to rename `engine` to `worker`? You're SOL, the tag says `engine/v0.3.0`, it'll stay engine forever
    

    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 the engine/v0.3.0 tag, and therefore, if we rename it to worker, the new tag would be worker/v0.4.0. Checking out the repo at engine/v0.3.0 should get us a FS with a module in the engine folder. And if we checkout worker/v0.4.0, the module should be in the worker folder, no?

      * Want to move `engine` under 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.0` means the path must be `./engine` from the git root)
    

    see above

      * `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 code
    

    This has been true since the Go modules and we said goodbye to GOPATH, though. The many modules wouldn't affect that?

    Did I mention ./... doesn't follow sub-modules?

    That is true, and could be a pain…

    CI (and core developers) have to to run a different lint/test/build/generate/dependabot/etc job for each module. Can't go:embed between modules.
    Can't go:generate between modules.

    I would believe that if we're there, we might have some architecture design flaw. But still, it some limitation that could be annoying.

    The LSP doesn't like sub-modules, you've got to open one vscode for each module.

    Normally the module workspace is supposed to fix (or help) that: https://go.dev/doc/tutorial/workspaces. And I believe gopls should handle workspaces as well.

    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.

    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.

    go.dagger.io/dagger v0.2.36 => github.com/dagger/dagger/tags/v0.2.36
    

    But we could make the webpage at go.dagger.io actually 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.

  23. aluzzardi commented on Oct 20, 2022

    @aluzzardi
    ContributorAuthor

    Here's the conclusion:

    • Go SDK lives in sdk/go like the rest of the SDKs
      • Versioned independently from the rest of the Go code using an sdk/go/vX.X.X tag
      • Uses its own vanity URL (dagger.io/dagger), independent from the rest of the Go code
    • 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

    Answering @gerhard's questions to add some clarity:

    • All code (SDKs, CLI, Engine, docs, etc.) is stored in a single repository, dagger/dagger

    Yes

    • Go SDK is versioned via the <version> format (special case)

    No exception. It's going to be sdk/go/v0.1.0 (just like it will be sdk/python/v0.1.0)

    • All other SDKs are versioned as sdk/<lang>/<version>

    Go is the same

    • All SDKs (including Go) are versioned independently

    Yes

    • CLI is versioned independently, e.g. cli/<version>

    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.

    • This is a dependency of all SDKs, except Go
    • Engine is versioned independently, e.g. engine/<version>

    No. Again, aside from SDKs, everything is versioned in lockstep.

    • We need this tag to build & distribute it (binary/OCI)

    Yes, but not until we have a non-Go SDK. Go SDK will use Go distribution (e.g. go get) to grab the "engine".

    This is not clear to me just yet:

    • What is the Go SDK source code path be in this repo @aluzzardi?

    sdk/go

    • What is the CLI source code path in this repo @aluzzardi?

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

    • What is the Engine source code path in this repo @aluzzardi?

    It's in dagger/dagger. Not a concern for users as nobody is supposed to import it directly.

    • Is there a single top-level go.mod for the Go SDK, CLI & Engine @aluzzardi?

    There are 2 go.mod:

    • The go.mod in sdk/go (just like there's a package.json in sdk/nodejs)
    • A top-level go.mod for everything else
    • Why are we embedding the engine in the Go SDK @shykes?

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

  24. shykes commented on Oct 20, 2022

    @shykes
    Contributor
    • What is the CLI source code path in this repo @aluzzardi?

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

    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.

  25. shykes commented on Oct 20, 2022

    @shykes
    Contributor

    @aluzzardi since we have consensus, may I suggest updating the body of this issue for clarity? Before someone changes their mind ;)

  26. gerhard commented on Oct 24, 2022

    @gerhard
    Contributor

    That was all super helpful @aluzzardi, thank you.

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