Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: cmd/ipfs: Make it possible to depend on cmd/ipfs #10219

Merged
merged 7 commits into from
Dec 22, 2023

Conversation

Stebalien
Copy link
Member

Today there are two ways to run kubo with plugins, one on non-linux systems:

  • Preload - which requires the plugin to be in the kubo repo, or at least requires manual build of kubo
  • Use a Go plugin, which don't work on most systems, and won't work if any build dependency isn't perfectly aligned - which in practice makes them almost completely unusable for anything non-trivial

This PR adds a third way - by depending on cmd/ipfs/kubo it's now possible to depend on this repo to create kubo-derived nodes with user-specified plugins.

I needed this for RIBS, which is a highly-advanced blockstore, that couldn't justifiably "just be integrated" into upstream kubo.

Review probably easiest commit-by-commit.

// - run the command invocation
// - output the response
// - if anything fails, print error, maybe with help.
func Start(buildEnv func(ctx context.Context, req *cmds.Request) (cmds.Environment, error)) (exitCode int) {
Copy link
Member Author

Choose a reason for hiding this comment

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

To be honest, this feels like the wrong thing to export. We should just be exporting a way to start the daemon that's entirely independent of the commandline tool.

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe, although I think for what @magik6k was looking for he wanted both the CLI and daemon and so this seems natural.

IIUC it's basically a way to do preloaded plugins with a fairly small and Go versioned codebase that uses imports rather than what effectively operates like a kubo fork.

For example, instead of:

  • git pull the latest version, add your plugins as a dependency, compile
  • update kubo dependency in your repo, compile

It's got some tradeoffs with regards to a standard preloaded plugin build, but they seem like reasonable ones for someone to make.

Were you thinking to expose two different things, one for starting the daemon and another for the CLI?

Copy link
Member

Choose a reason for hiding this comment

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

In my case I want to have the whole CLI with the plugin, doing it with start meant the least amount of code needed to get the cli + plugin

Copy link
Contributor

@aschmahmann aschmahmann left a comment

Choose a reason for hiding this comment

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

Thanks @magik6k and @Stebalien. Sorry it's taken so long to get to this 😬.

Generally LGTM, but had a few questions on some changes I made to make sure everything still works as the original PR intended. Thanks 🙏

return err
}

func getRepoPath(req *cmds.Request) (string, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

@magik6k you previously exported this function, but I didn't see it used https://github.com/FILCAT/ribs/blob/main/integrations/kuri/cmd/kuri/main.go and wasn't sure it was useful otherwise. Did I miss something?

Copy link
Member

Choose a reason for hiding this comment

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

I believe I ended up using a separate path, private is good.


type PluginPreloader func(*loader.PluginLoader) error

func loadPlugins(repoPath string, preload PluginPreloader) (*loader.PluginLoader, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

@magik6k you previously exported this function, but I didn't see it used https://github.com/FILCAT/ribs/blob/main/integrations/kuri/cmd/kuri/main.go and wasn't sure it was useful otherwise. Did I miss something?

Copy link
Member

Choose a reason for hiding this comment

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

Probably made it exported for tinkering, so private makes sense

Comment on lines +106 to +108
// BuildEnv creates an environment to be used with the kubo CLI. Note: the plugin preloader should only call functions
// associated with preloaded plugins (i.e. Load).
func BuildEnv(pl PluginPreloader) func(ctx context.Context, req *cmds.Request) (cmds.Environment, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Added some comments here, but wondering if this should be something more restrictive (e.g. instead of taking *loader.PluginLoader pass something that really only operates on Load(plugin.Plugin) error like an interface or a function).

Thoughts?

No particularly strong feelings here, this seems like something easy to change later so documenting the edges doesn't seem so bad.

Copy link
Member

Choose a reason for hiding this comment

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

Not sure how much value there is in restricting more, for me I only really care about being able to load my plugin

Copy link
Contributor

Choose a reason for hiding this comment

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

Cool, fine leaving it for now can always change later and it shouldn't be a burden downstream

@@ -36,6 +36,12 @@ For more information about the different types of Kubo plugins, see [plugins.md]

Kubo plugins can also be injected at runtime using Go plugins (see below), but these are hard to use and not well supported by Go, so we don't recommend them.

### Kubo binary imports
Copy link
Contributor

Choose a reason for hiding this comment

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

Thoughts on a better name here (please don't say kubo-as-a-library, we already have some things there which are in need of deleting)?

Copy link
Member

Choose a reason for hiding this comment

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

Kubo+Plugins bundle builds?

// - run the command invocation
// - output the response
// - if anything fails, print error, maybe with help.
func Start(buildEnv func(ctx context.Context, req *cmds.Request) (cmds.Environment, error)) (exitCode int) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe, although I think for what @magik6k was looking for he wanted both the CLI and daemon and so this seems natural.

IIUC it's basically a way to do preloaded plugins with a fairly small and Go versioned codebase that uses imports rather than what effectively operates like a kubo fork.

For example, instead of:

  • git pull the latest version, add your plugins as a dependency, compile
  • update kubo dependency in your repo, compile

It's got some tradeoffs with regards to a standard preloaded plugin build, but they seem like reasonable ones for someone to make.

Were you thinking to expose two different things, one for starting the daemon and another for the CLI?

Copy link
Contributor

@aschmahmann aschmahmann left a comment

Choose a reason for hiding this comment

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

Thanks all for the help. Merging and if there are any objections/changes people want to make we can handle them in a follow-up PR.

@aschmahmann aschmahmann merged commit 58ebfd2 into master Dec 22, 2023
23 checks passed
@aschmahmann aschmahmann deleted the magiks-ribs-hacks branch December 22, 2023 21:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants