-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Basic framework for writing and running CLI plugins #1564
Conversation
I was expecting e2e to fail but looks like I forgot to shellcheck and lint too, will sort those out. |
Codecov Report
@@ Coverage Diff @@
## master #1564 +/- ##
==========================================
- Coverage 56.1% 56.04% -0.07%
==========================================
Files 300 306 +6
Lines 20601 20848 +247
==========================================
+ Hits 11559 11685 +126
- Misses 8209 8324 +115
- Partials 833 839 +6 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple of comment/questions:
- why not
github.com/docker/cli/plugins
as a package name ? - could additionnal lookup path be available through the user configuration (aka
$HOME/.docker/config.json
) ?
Just a comment related to the Docker Desktop integration: |
To avoid confusion with
Sure. @guillaumerose WRT that setting and Desktop, we should try hard to avoid needing Desktop to set anything like this (whether in a file or the env) by making sure the default set of paths is sensible for the Desktop OSes such that desktop can install the base set of plugins in the right place without any special overrides. |
@ijc the |
3aeb78c
to
8858366
Compare
docker/cli#1564 Since this pushes the actual command down to `docker-app app`, adjust the e2e tests with: $ sed -Eie 's/icmd\.RunCommand\(dockerApp,/icmd.RunCommand(dockerApp, "app",/g' e2e/*.go $ sed -Eie 's/exec.Command\(dockerApp,/exec.Command(dockerApp, "app",/g' e2e/*.go $ sed -Eie 's/\[\]string\{dockerApp,/\[\]string\{dockerApp, "app",/g' e2e/*.go (which might be precisely equivalent to `sed -Eie 's/dockerApp,/dockerApp, "app",/g' e2e/*.go`) Finally, the idiom in docker/cli (for better or worse) is to include an "Error: " prefix in the error string itself, rather than injecting it when printing. Since CLI plugins follow the behaviour of the CLI here it is necessary to prepend "Error: " to some messages. I've only done exactly those necessary to pass the e2e tests, a fuller audit is very likely required. Signed-off-by: Ian Campbell <ijc@docker.com>
docker/cli#1564 Since this pushes the actual command down to `docker-app app`, adjust the e2e tests with: $ sed -Eie 's/icmd\.RunCommand\(dockerApp,/icmd.RunCommand(dockerApp, "app",/g' e2e/*.go $ sed -Eie 's/exec.Command\(dockerApp,/exec.Command(dockerApp, "app",/g' e2e/*.go $ sed -Eie 's/\[\]string\{dockerApp,/\[\]string\{dockerApp, "app",/g' e2e/*.go (which might be precisely equivalent to `sed -Eie 's/dockerApp,/dockerApp, "app",/g' e2e/*.go`) Finally, the idiom in docker/cli (for better or worse) is to include an "Error: " prefix in the error string itself, rather than injecting it when printing. Since CLI plugins follow the behaviour of the CLI here it is necessary to prepend "Error: " to some messages. I've only done exactly those necessary to pass the e2e tests, a fuller audit is very likely required. Signed-off-by: Ian Campbell <ijc@docker.com>
I did a quick port of |
5a7f245
to
bebdb71
Compare
I've force pushed quite a big update, rebasing on the latest code (so #1558 is no longer included since it is merged), sorted out the issues around I'm going to update the todo in the first comment to reflect what's done and add some new entries people requested. |
docker/cli#1564 Since this pushes the actual command down to `docker-app app`, adjust the e2e tests with: $ sed -Eie 's/icmd\.RunCommand\(dockerApp,/icmd.RunCommand(dockerApp, "app",/g' e2e/*.go $ sed -Eie 's/exec.Command\(dockerApp,/exec.Command(dockerApp, "app",/g' e2e/*.go $ sed -Eie 's/\[\]string\{dockerApp,/\[\]string\{dockerApp, "app",/g' e2e/*.go (which might be precisely equivalent to `sed -Eie 's/dockerApp,/dockerApp, "app",/g' e2e/*.go`) Finally, the idiom in docker/cli (for better or worse) is to include an "Error: " prefix in the error string itself, rather than injecting it when printing. Since CLI plugins follow the behaviour of the CLI here it is necessary to prepend "Error: " to some messages. I've only done exactly those necessary to pass the e2e tests, a fuller audit is very likely required. Signed-off-by: Ian Campbell <ijc@docker.com>
docker/cli#1564 Since this pushes the actual command down to `docker-app app`, adjust the e2e tests with: $ sed -Eie 's/icmd\.RunCommand\(dockerApp,/icmd.RunCommand(dockerApp, "app",/g' e2e/*.go $ sed -Eie 's/exec.Command\(dockerApp,/exec.Command(dockerApp, "app",/g' e2e/*.go $ sed -Eie 's/\[\]string\{dockerApp,/\[\]string\{dockerApp, "app",/g' e2e/*.go (which might be precisely equivalent to `sed -Eie 's/dockerApp,/dockerApp, "app",/g' e2e/*.go`) Finally, the idiom in docker/cli (for better or worse) is to include an "Error: " prefix in the error string itself, rather than injecting it when printing. Since CLI plugins follow the behaviour of the CLI here it is necessary to prepend "Error: " to some messages. I've only done exactly those necessary to pass the e2e tests, a fuller audit is very likely required. Signed-off-by: Ian Campbell <ijc@docker.com>
docker/cli#1564 Since this pushes the actual command down to `docker-app app`, adjust the e2e tests with: $ sed -Eie 's/icmd\.RunCommand\(dockerApp,/icmd.RunCommand(dockerApp, "app",/g' e2e/*.go $ sed -Eie 's/exec.Command\(dockerApp,/exec.Command(dockerApp, "app",/g' e2e/*.go $ sed -Eie 's/\[\]string\{dockerApp,/\[\]string\{dockerApp, "app",/g' e2e/*.go (which might be precisely equivalent to `sed -Eie 's/dockerApp,/dockerApp, "app",/g' e2e/*.go`) Finally, the idiom in docker/cli (for better or worse) is to include an "Error: " prefix in the error string itself, rather than injecting it when printing. Since CLI plugins follow the behaviour of the CLI here it is necessary to prepend "Error: " to some messages. I've only done exactly those necessary to pass the e2e tests, a fuller audit is very likely required. Signed-off-by: Ian Campbell <ijc@docker.com>
Signed-off-by: Ian Campbell <ijc@docker.com>
On Windows `foo.exe`, `foo.eXe` and `foo.EXE` are equally executable. Signed-off-by: Ian Campbell <ijc@docker.com>
This allows passing argument to plugins, otherwise they are caught by the parse loop, since cobra does not know about each plugin at this stage (to avoid having to always scan for all plugins) this means that e.g. `docker plugin --foo` would accumulate `plugin` as an arg to the `docker` command, then choke on the unknown `--foo`. This allows unknown global args only, unknown arguments on subcommands (e.g. `docker ps --foo`) are still correctly caught. Add an e2e test covering this case. Signed-off-by: Ian Campbell <ijc@docker.com>
A static global initialiser happens before the arguments are parsed, so we need to calculate the path later. Signed-off-by: Ian Campbell <ijc@docker.com>
They were listed twice in `docker --help` (but not `docker help`), since the stubs were added in both `tryRunPluginHelp` and the `setHelpFunc` closure. Calling `AddPluginStubCommands` earlier in `setHelpFunc` before the call to `tryRunPluginHelp` is sufficient. Also it is no longer necessary to add just valid plugins (`tryRunPluginHelp` handles invalid plugins correctly) so remove that logic (which was in any case broken for e.g. `docker --help`). Update the e2e test to check for duplicate entries and also to test `docker --help` which was previously missed. Signed-off-by: Ian Campbell <ijc@docker.com>
Summarizing things that I think can be handled in follow-ups (but some of these should be done before GA);
Future follow-ups (not discussed here);
|
@docker/core-cli-maintainers looking at the list above, I'm inclined to move this forward, and take care of the listed issues separate; WDYT? |
@thaJeztah I'm ok with merging this first plugin base and iterate with follow-ups on the issues you listed 👍 |
Same as @silvin-lubecki given we do those follow-up before next release 👼 |
This WFM (of course) and I will commit to addressing the bullets in #1564 next (my first act would be to transliterate that comment into an issue I think). @thaJeztah I've looked over the outstanding comments and I think your list covers them all. Have I missed anything which you don't want to defer? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!!! Thank you @ijc for this awesome work!
@albers do you have any advice on how we might go about integrating completion for plugins? I was wondering perhaps if WDYT? |
@ijc I think this is possible in the way you outlined. |
Awesome, thanks @albers! Please give a shout if there is any way I can help |
- What I did
This is a small part of #1534, I wanted to get the basic framework out so that potential consumers could start to play with it and give feedback on how it works for them as well as getting some early feedback on the code.
NB this also includes the changes for #1558 since I was working on top of that.
There is still lots to do:
I've left off theNot doing this any more, at least not in this round (CLI Plugins Design #1534 (comment)).docker cli-plugin *
stuff since it is still being discussed (although some bits of the internal scaffolding here for listing and finding plugins are more related to that than the actual functionality added here, but I didn't tease those apart).docker help
.docker someplugin --help
produces the top-level help instead of calling the plugin for some reason (this means one of the new e2e tests currently fails), looks likedocker someplugin --version
has the same problem, I'm investigating.docker info
~/.docker/config.json
dial-stdio
etc isn't here (Some of those are nops in practice and just need checking that they are usable externally, otherwise I plan to do these bits in one or more followups, somewhat based on/prioritise by the experiences of folks trying to use this). edit: to clarify, I don't intend on doing this bit here but rather in a followup.- How to verify it
The unit and e2e tests cover some of it.
Plugin path can be configured with the "cliPluginsExtraDirs" key in
~/.docker/config.json
so for having a play (using a local config dir for isolation) you can alsomake -f docker.Makefile build plugins
then things like:to have a play.
- Description for the changelog