-
Notifications
You must be signed in to change notification settings - Fork 5k
Support a plugin infrastructure #2438
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
Comments
Plugin is a quite big topic... I don't have any idea. 😵 Please give more specific details. |
Some examples that I believe would make sense to implement as "plugins" or "add-ons" rather than being merged into the code base:
and stuff like that. It would make contributions of new non-core features easier as it would not need a merge into the codebase. |
Thanks your info!
I suggest use APIs instead.
The Code Snippets will eventually be implemented, so... any other examples?
How deep the integration would be? Sorry I don't have a clear idea about plugin thing, never done that before and sounds too general to me. |
With regards to #2507 we now have a valid reason for a plugin-system. Since I've written a few of those I'd like to express my take on this from a purely architectural point of view. First of, I'd recommend setting it up as external services that plugin to Gogs REST-APIs, so it would use the regular API for accessing gogs-data, and expose its own API (standardized of course) for injecting data (menus, panes and configuration). This would make them easy to create, install, upgrade, and manage separate from the Gogs-installation, and you could have them on a separate machine/VM/container/whatever so as to keep separation of concerns clean (IIRC this is a huge concern for PCI-validation which larger companies might have to have, though I might be wrong). Another good thing is that you don't have to restart Gogs to (un)install plugins. Second thing is that you'd have to be able to setup authorization on each plugin (authorization as in what the plugin is, and isn't allowed to do; and with what). I'd recommend that each plugin is sent an individual token on initialization, which the plugin uses for talking to the Gogs-API, and that Gogs would use for accessing the service-API. Tokens should be changed on each initialization (tokens could be changed after a fixed time as well, though it's not a necessity, more of a recommendation). Each plugin would tell Gogs what it does (in wide terms), as in Now, the biggest issue with this approach, is that the Gogs-API isn't done (not even close to done unfortunately), so the API would have to mature before this could be implemented. Anyhow, that's my recommendation and should be taken as such. Feel free to comment/bash on anything I've said and I'll try to answer as best as I can 😃 |
I like the idea with plugins over a REST API. This would also allow to implement them in any language. I only have concerns regarding the speed of the communication. Wouldn't there be much overhead if the server is talking to the plugin via REST (eventually on a different server?) and only then sends the resulting webpage to the user? |
Writting a plugin infraestructure is hard and I don't know if it is worth. I am not the best person to propose something, but will try to do some brainstorming 😄. BackendAn alternative to what @bkcsoft proposed would be doing it with Go itself. Since Go doesn't support dinamic libraries ( package plugins
import "github.com/gogits/gogs/plugin"
func init() {
plugin.RegisterPlugin("myPluginName", func(ctx *plugin.context) {
ctx.InjectHTML("anyTemplate.tmpl", "header", func() string { return "<foo>bar</foo>" })
ctx.Route("/foo/bar", func() { ... })
ctx.OnPushRepository(func(repository) { ... })
// etc...
})
} This would be hard work, though. Client sideDoing simple things in the client side would be much simpler. We could have a folder where every Also, we could have an alternative public folder which would override the existing one. Example: I want to change the Injecting templatesAnother folder could exists to inject templates on Gogs. Example: |
@NiklasRosenstein Speed is obviously an issue when talking about micro-services (which is what this is called BTW). On the other hand, REST-APIs should be as light as possible, and should never send entire webpages 😉. Information on where menus and panels should be could easily be send on initialization and stored by Gogs so as to not ask on each page-render "does anyone wanna render here??". And you could most likely send and cache templates as well for rendering panels. So the only data that is sent at run-time is the actual data that changes 😃. Though for some things (like code-comments which might wanna render after any line) this might still be an issue, not sure how to implement such a feature as a pure template-fix. Though overriding templates as @andreynering suggested could work here as well (though not as secure IMO) On a less serious note, neither Amazon or Netflix has any real performance issue with their micro-services, so I'm guessing that even a fairly large plugin for Gogs would not be an issue 😉 |
@andreynering Actually it wouldn't take much to implement this within Gogs (except for the lacking API...). I could probably implement a rough draft over the week. There are X key components that needs implementation:
And since Gogs already has token-based auth, there's no need to put extra thought on security (other than at token-generation) |
@bkcsoft Sorry. Which alternative are you talking about? Doing it in Go or using a REST API? |
@andreynering REST-API. A few thoughts on your ideas:
|
My initial idea seems too big right now... I was thinking to support both code modifications and REST APIs... |
This would require the user to manually download the plugin files, paste in a specific folder (package) and compiling. Not much intuitive, but it is an idea. And it would be very powerful. Maybe there's a better alternative to link Go code?
I didn't get what would be the security issue here. If you could change the HTML, why not the CSS? (and maybe JS, too). It would be necessary to create custom themes (see below).
|
@unknwon well, with a complete REST-API the compiled version wouldn't be necessary, since everything would be exposed over an API. Though most of this could be implemented with webhooks, though you couldn't inject the returned data into Gogs (yet... that could also be possible) |
I am thinking using gRPC or protobuf, might be faster? |
@unknwon well, protobuf is just a packer/unpacker so it wouldn't do that much difference. Websockets is more interesting since it can be used from within the browser as well (live updating of comments etc) WRT auth-plugins (talk from gitter, to mention it here as well), this I wouldn't be comfortable with putting in a REST-plugin and should be implemented like @andreynering mentioned with compiled plugins into Gogs itself... Mostly because it would be a PITA to have multiple authentications, one for plugins and another over a plugin for users and whatnot... |
@andreynering WRT #1956 and #1126. Themeing shouldn't be implemented by changing the templates, but rather by changing (or appending) css-files. (see this ) And for those that wanna change them anyway, you can do that today, though you have to replace the existing one 😩 |
Yep. We have to think whether we want to be possible to replace the entire template or just inject more HTML on the existing templates. See my comment above:
Agree that for theming CSS would be better. |
Well, I'd want to both inject templates into existing templates, and inject entirely new ones 😄. Though never replace, don't think that a plugin should be allowed to TBH... On the topic of "not worth it", since Gists could be implemented thusly, and both Issues and Wikis could be migrated to such, I'd say it's worth it. Reasons:
So I'd say that it's very much "worth it" 😛 |
@NiklasRosenstein @andreynering Feel free to comment on this 😃 |
Just some brainstorming. An alternative to allowing plugins to be written in Go, would be using a scripting language:
Pros:
Cons:
|
Caddy is an example how to integrate plugins, it's compiled into the binary as already suggested, you extend the source similar to caddyext. |
For further reference https://github.com/caddyserver/caddyext |
Hi, I'm not a
I believe it could be some memory leaking on Can you share your thoughts? Thanks in advance! |
The most idiomatic way should be a RPC based plugin system. There are already multiple examples in the wild. Famous examples are terraform and packer from Hashicorp. |
One step closer 😈 https://tip.golang.org/pkg/plugin/ |
I still prefer the RPC based plugins like the plugin system of Hashicorp :) |
Hi, I would like to add some features on my GOGS. I can see on previous comments that it is not yet possible to add plugin. In fact, I have realised a little script to verify the syntax of my code. Then, I have added its on the suitable hook, and this works. However, currently, the return information of my script are written on a log file on my server. It is not convenient. I have to logon on the server to know this information. So, I would like to add a way to display on GOGS this information, for example a button or a popup or whatever. How can I do this ? Thank you so much, |
I would like to sidecar package repos. like, add an option for releases to get published to a built-in repo, e.g. apt, pip, etc |
It would be very cool if we could write plugins for Gogs to add features to the web interface. These should be easy to deploy, too.
The text was updated successfully, but these errors were encountered: