Skip to content

Go SDK: Move to its own go.mod and vanity URL - #3416

Closed
aluzzardi wants to merge 3 commits into
dagger:mainfrom
aluzzardi:go-sdk-gomod
Closed

aluzzardi wants to merge 3 commits into
dagger:mainfrom
aluzzardi:go-sdk-gomod

Conversation

@aluzzardi

@aluzzardi aluzzardi commented Oct 17, 2022 •

Copy link
Copy Markdown
Contributor

Current state of things:

  • We have a single go module
  • The vanity URL go.dagger.io points to the GitHub org (e.g. github.com/dagger)
    • The "root" import path of this repo is go.dagger.io/dagger
    • Therefore the SDK lives in go.dagger.io/dagger/sdk/go/dagger

Proposal:

  • Go SDK has its own, short, vanity URL (for example: go.dagger.io/dagger -- bikeshedding welcome)
  • Rest of the project needs to have a different URL (for example -- revert to github.com/dagger/dagger. Bikeshedding welcome)
  • To make it happen, repo and SDK must have their own go.mod with relative replace

Visual Representation

  • Before:
name Git Path Go import Module
Engine github.com/dagger/dagger go.dagger.io/dagger ✅
Go SDK github.com/dagger/dagger/sdk/go/dagger go.dagger.io/dagger/sdk/go/dagger ⛔
  • This PR:
name Git Path Go import Module
Engine github.com/dagger/dagger github.com/dagger/dagger ✅
Go SDK github.com/dagger/dagger/sdk/go go.dagger.io/dagger ✅

Downsides:

  • I don't know if replace directive works well, especially when tag-released
    • I'm going to work on my fork and try different tagging strategies, report back
  • vscode is not happy to have one workspace for different modules
    • Need to open engine code and SDK separately

@aluzzardi
aluzzardi force-pushed the go-sdk-gomod branch 2 times, most recently from 5efce47 to 728e38d Compare October 17, 2022 21:56
Comment thread .github/dependabot.yml Outdated

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/cc @helderco @samalba

Is this alright? I see there's pip, pipenv, pip-compile and we're using pyproject.toml which I've never seen before

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pyproject.toml is used by pip so it should be good. It's simply a new alternative to setup.py/

@shykes

shykes commented Oct 17, 2022

Copy link
Copy Markdown
Contributor

I think you already explained this to me at least once today, sorry... Why do we need "engine" to be a separate module? Couldn't we just keep all inside the same module, and call that module "the go SDK"?

@dolanor

dolanor commented Oct 17, 2022

Copy link
Copy Markdown
Contributor

Have you tried the Go Workspace system? I don't know the support in VS Code, but I think gopls should support it.
It is supposed to help work with multiple go modules in the same repo.

@shykes

shykes commented Oct 17, 2022

Copy link
Copy Markdown
Contributor
  • Go SDK has its own, short, vanity URL (for example: go.dagger.io/dagger -- bikeshedding welcome)

Definitely bikeshedding: why not just dagger.io/dagger? Having a separate domain seems weird to me. Is this an established best practice in the Go world, or perhaps an implementation constraint (easier to setup the go proxy on a separate domain)?

@vito vito left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting! I like the short and sweet SDK import this adds, but have some concerns:

  • Will dependencies of the Dagger engine (e.g. Bass until the progress API is finished) have to do something tricky to deal with the replace line? This has been a huge pain point for Buildkit->Bass and Buildkit->Dagger.
  • Will this accidentally make it possible to depend on a different version of the SDK + engine, since they're independently versioned modules?
  • Will Dagger contributors and/or SDK authors be confused by this? I don't think I've seen this sort of scheme before. I could easily see someone assuming go.dagger.io/dagger is the same as github.com/dagger/dagger, and normally a repo indicates its "correct" import, but now both are actually valid and mean different things.

Also taking a step back: are there any other motivations for this besides the shorter SDK import?

Comment thread go.mod Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know you mentioned it already, but I'm worried about adding this because dealing with Buildkit's replace has been pretty irritating with Bass. Most things shouldn't be importing Dagger itself, so maybe it's not a big deal, but it'd be good to know how this works/breaks.

Maybe we can apply this change to a throwaway fork that we can tag a fake release for? I've wanted a similar playpen for testing the pkg.go.dev docs + example rendering. Not sure how much work that'd be though with the vanity URL setup.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Part of what I need to test, I was hoping this would work out of the box without importers having to change anything since it's a replace into the same git repository. But I might be day-dreaming?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replace rules are not preserved for consumers, and only work locally.

There's a risk there as well; if you use a replace rule, you'll get a "different view of the world" as others. ideally your tests would run both with replace rule, and without (to verify code works both with code from this repo, and from the actual module that's referenced); see moby/sys#68 (but it's messy).

Comment thread sdk/go/go.mod Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be nice if we used this as an opportunity to get rid of this replace line to address #3391 but I guess we still need it because we embed the engine.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, without this SDK won't run. The problem bubbles down to everything importing buildkit (including the SDK)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vito I haven't given up hope of solving #3391 while still importing buildkit :) I think @aluzzardi is investigating options.

@samalba

samalba commented Oct 17, 2022

Copy link
Copy Markdown
Contributor

LGTM, it's much nicer to use this import path for Go, it took me a while to find the right import when I tried the SDK the first time.

@shykes

shykes commented Oct 17, 2022

Copy link
Copy Markdown
Contributor
  • Will dependencies of the Dagger engine (e.g. Bass until the progress API is finished) have to do something tricky to deal with the replace line? This has been a huge pain point for Buildkit->Bass and Buildkit->Dagger.

Are you referring to this? #3391

  • Will this accidentally make it possible to depend on a different version of the SDK + engine, since they're independently versioned modules?

My understanding is that we don't want anybody to have a depending on the "engine" go package. So I'm worried about accidentally depending on "engine" (regardless of version).

  • Will Dagger contributors and/or SDK authors be confused by this? I don't think I've seen this sort of scheme before. I could easily see someone assuming go.dagger.io/dagger is the same as github.com/dagger/dagger, and normally a repo indicates its "correct" import, but now both are actually valid and mean different things.

Same question. I think we should only expose one Go import to the outside world: the SDK. The rest should be a hidden implementation detail.

@aluzzardi

Copy link
Copy Markdown
Contributor Author

Go SDK has its own, short, vanity URL (for example: go.dagger.io/dagger -- bikeshedding welcome)

Definitely bikeshedding: why not just dagger.io/dagger? Having a separate domain seems weird to me. Is this an established best practice in the Go world, or perhaps an implementation constraint (easier to setup the go proxy on a separate domain)?

Just a convention. We could use dagger.io instead, with the caveat that our landing page then becomes part of the distribution infrastructure:

  • Must include the right meta tag forever
  • Migrating to a different CMS might bring down the vanity URL if not done properly
  • Adds infra constraints to the landing page: For instance, go get appends a ?go-get=1 to the URL so that the server can render a smaller page (e.g. avoid sending huge chunks of HTML to every client). If we wanted to do so, then it's up to the landing page (and its provider, e.g. netlify / CF pages / etc) to support that

I definitely prefer the shorter one; the trade-off is it moves the work on the landing page and there's no easy way to undo without breaking clients.

@aluzzardi

Copy link
Copy Markdown
Contributor Author

I think you already explained this to me at least once today, sorry... Why do we need "engine" to be a separate module? Couldn't we just keep all inside the same module, and call that module "the go SDK"?

We could keep it as it is today and then colloquially call that module the "Go SDK", but the import paths would still look like today:

name Git Path Go import Module
Engine github.com/dagger/dagger go.dagger.io/dagger SDK module
Go SDK github.com/dagger/dagger/sdk/go/dagger go.dagger.io/dagger/sdk/go/dagger SDK module

The main advantages of using different go.mods are:

  • Separate dependencies (doesn't really matter with tree shaking, binary size will be the same)
  • Separate name/vanity URL (what this PR attempts to do)
  • (POTENTIALLY) Separate versioning

However, need to double check all the points @vito raised -- it might not even be doable.

@dolanor

dolanor commented Oct 17, 2022 •

Copy link
Copy Markdown
Contributor

For the topic, I would say that I would try to avoid replace as much as possible. They should be used only locally if possible.

Is this an established best practice in the Go world

On the go.dagger.io, outside the reasons from Andrea, I also like without the go. prefix. But it is a pattern I've seen used here and there (notably go.uber.org).

Same question. I think we should only expose one Go import to the outside world: the SDK. The rest should be a hidden implementation detail.

For the non importability of the engine, we should just put everything into internal, so then, the go tool won't allow it.

My favorite in terms of URL style and semantics would be:
dagger.io/sdk/go
or
go.dagger.io/sdk

It could also be:
sdk.dagger.io/go => github.com/dagger/sdk-go

but then, it would make the LSP not work great (finishing by go or sdk, but the actual package name would be dagger, so it would create those annoying import aliases)

The not so great alternative would be to make the package explicit as well:

import "go.dagger.io/daggersdk"

No alias, and the package name is explicit. But then, daggersdk.Connect() is not very cool.

Maybe go.dagger.io/daggerclient, but that's long.

Sorry for the bikeshedding, I just add more to the issue.

@shykes

shykes commented Oct 18, 2022

Copy link
Copy Markdown
Contributor

Just a convention. We could use dagger.io instead, with the caveat that our landing page then becomes part of the distribution infrastructure:

  • Must include the right meta tag forever
  • Migrating to a different CMS might bring down the vanity URL if not done properly
  • Adds infra constraints to the landing page: For instance, go get appends a ?go-get=1 to the URL so that the server can render a smaller page (e.g. avoid sending huge chunks of HTML to every client). If we wanted to do so, then it's up to the landing page (and its provider, e.g. netlify / CF pages / etc) to support that

I definitely prefer the shorter one; the trade-off is it moves the work on the landing page and there's no easy way to undo without breaking clients.

Could this handled at the CDN layer? For example with a cloudflare or fastly worker? That way it would decouple that logic from the landing page, reducing the risk of weird interference or breaking it when we change CMS.

I'm only proposing this since you mention that you also like the shorter option :)

@aluzzardi

Copy link
Copy Markdown
Contributor Author

Could this handled at the CDN layer? For example with a cloudflare or fastly worker? That way it would decouple that logic from the landing page, reducing the risk of weird interference or breaking it when we change CMS.
I'm only proposing this since you mention that you also like the shorter option :)

Short version: Yes, let's do that.
Long version: We can achieve that with Netlify and some redirect rules. The risk here is we're tying landing page and distribution infrastructure, but I'm starting to think that's probably too early of an optimization.

Example: The CDN layer suggestion above illustrates this. SPA providers (e.g. Netlify, Vercel) are NOT meant to run behind a CDN. They already have a CDN (I believe Netlify runs behind AWS CloudFront) and adding another one on top messes up with distribution (e.g. end up with stale pages on deploy because the cache purge logic is handled by their CDN, not ours which ends double caching stale deploys).

Using a different sub-domain completely isolates the scope (e.g. landing on Vercel, distribution on S3 -- doesn't matter).

That being said, I think at our size we can manage.

@aluzzardi

Copy link
Copy Markdown
Contributor Author

Moved this discussion here #3424 and a more gradual implementation here #3425

@aluzzardi aluzzardi closed this Oct 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants