From 69276fddf8269e6de7bf297d4a7127e0ed977cb7 Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Mon, 7 Nov 2016 17:43:11 -0800 Subject: [PATCH] support settings in docker plugins install Signed-off-by: Victor Vieux --- api/types/client.go | 1 + cli/command/plugin/install.go | 9 +++++++-- cli/command/plugin/set.go | 2 +- client/plugin_install.go | 8 ++++++++ docs/reference/commandline/plugin_install.md | 11 ++++++----- docs/reference/commandline/plugin_set.md | 2 +- integration-cli/docker_cli_plugins_test.go | 9 +++++++++ 7 files changed, 33 insertions(+), 9 deletions(-) diff --git a/api/types/client.go b/api/types/client.go index 8eaecf5c81..769c836446 100644 --- a/api/types/client.go +++ b/api/types/client.go @@ -337,4 +337,5 @@ type PluginInstallOptions struct { RegistryAuth string // RegistryAuth is the base64 encoded credentials for the registry PrivilegeFunc RequestPrivilegeFunc AcceptPermissionsFunc func(PluginPrivileges) (bool, error) + Args []string } diff --git a/cli/command/plugin/install.go b/cli/command/plugin/install.go index 3989a35ce6..eae0183671 100644 --- a/cli/command/plugin/install.go +++ b/cli/command/plugin/install.go @@ -18,16 +18,20 @@ type pluginOptions struct { name string grantPerms bool disable bool + args []string } func newInstallCommand(dockerCli *command.DockerCli) *cobra.Command { var options pluginOptions cmd := &cobra.Command{ - Use: "install [OPTIONS] PLUGIN", + Use: "install [OPTIONS] PLUGIN [KEY=VALUE...]", Short: "Install a plugin", - Args: cli.ExactArgs(1), // TODO: allow for set args + Args: cli.RequiresMinArgs(1), RunE: func(cmd *cobra.Command, args []string) error { options.name = args[0] + if len(args) > 1 { + options.args = args[1:] + } return runInstall(dockerCli, options) }, } @@ -75,6 +79,7 @@ func runInstall(dockerCli *command.DockerCli, opts pluginOptions) error { AcceptPermissionsFunc: acceptPrivileges(dockerCli, opts.name), // TODO: Rename PrivilegeFunc, it has nothing to do with privileges PrivilegeFunc: registryAuthFunc, + Args: opts.args, } if err := dockerCli.Client().PluginInstall(ctx, ref.String(), options); err != nil { return err diff --git a/cli/command/plugin/set.go b/cli/command/plugin/set.go index e58ea63bc0..5660523ed9 100644 --- a/cli/command/plugin/set.go +++ b/cli/command/plugin/set.go @@ -13,7 +13,7 @@ import ( func newSetCommand(dockerCli *command.DockerCli) *cobra.Command { cmd := &cobra.Command{ - Use: "set PLUGIN key1=value1 [key2=value2...]", + Use: "set PLUGIN KEY=VALUE [KEY=VALUE...]", Short: "Change settings for a plugin", Args: cli.RequiresMinArgs(2), RunE: func(cmd *cobra.Command, args []string) error { diff --git a/client/plugin_install.go b/client/plugin_install.go index 636c95364d..d0a3d517fc 100644 --- a/client/plugin_install.go +++ b/client/plugin_install.go @@ -45,9 +45,17 @@ func (cli *Client) PluginInstall(ctx context.Context, name string, options types return pluginPermissionDenied{name} } } + + if len(options.Args) > 0 { + if err := cli.PluginSet(ctx, name, options.Args); err != nil { + return err + } + } + if options.Disabled { return nil } + return cli.PluginEnable(ctx, name) } diff --git a/docs/reference/commandline/plugin_install.md b/docs/reference/commandline/plugin_install.md index 524b4d8d5c..24155a3ea4 100644 --- a/docs/reference/commandline/plugin_install.md +++ b/docs/reference/commandline/plugin_install.md @@ -17,7 +17,7 @@ advisory: "experimental" # plugin install (experimental) ```markdown -Usage: docker plugin install [OPTIONS] PLUGIN +Usage: docker plugin install [OPTIONS] PLUGIN [KEY=VALUE...] Install a plugin @@ -33,12 +33,13 @@ the registry. Note that the minimum required registry version to distribute plugins is 2.3.0 -The following example installs `no-remove` plugin. Install consists of pulling the -plugin from Docker Hub, prompting the user to accept the list of privileges that -the plugin needs and enabling the plugin. +The following example installs `no-remove` plugin and [set](plugin_set.md) it's env variable +`DEBUG` to 1. Install consists of pulling the plugin from Docker Hub, prompting +the user to accept the list of privileges that the plugin needs, settings parameters + and enabling the plugin. ```bash -$ docker plugin install tiborvass/no-remove +$ docker plugin install tiborvass/no-remove DEBUG=1 Plugin "tiborvass/no-remove" is requesting the following privileges: - network: [host] diff --git a/docs/reference/commandline/plugin_set.md b/docs/reference/commandline/plugin_set.md index 8c9eb74e1c..9a07f5d8eb 100644 --- a/docs/reference/commandline/plugin_set.md +++ b/docs/reference/commandline/plugin_set.md @@ -17,7 +17,7 @@ advisory: "experimental" # plugin set (experimental) ```markdown -Usage: docker plugin set PLUGIN key1=value1 [key2=value2...] +Usage: docker plugin set PLUGIN KEY=VALUE [KEY=VALUE...] Change settings for a plugin diff --git a/integration-cli/docker_cli_plugins_test.go b/integration-cli/docker_cli_plugins_test.go index b05cecae68..30b348523a 100644 --- a/integration-cli/docker_cli_plugins_test.go +++ b/integration-cli/docker_cli_plugins_test.go @@ -131,6 +131,15 @@ func (s *DockerSuite) TestPluginSet(c *check.C) { c.Assert(strings.TrimSpace(env), checker.Equals, "[DEBUG=1]") } +func (s *DockerSuite) TestPluginInstallArgs(c *check.C) { + testRequires(c, DaemonIsLinux, ExperimentalDaemon, Network) + out, _ := dockerCmd(c, "plugin", "install", "--grant-all-permissions", "--disable", pName, "DEBUG=1") + c.Assert(strings.TrimSpace(out), checker.Contains, pName) + + env, _ := dockerCmd(c, "plugin", "inspect", "-f", "{{.Config.Env}}", pName) + c.Assert(strings.TrimSpace(env), checker.Equals, "[DEBUG=1]") +} + func (s *DockerSuite) TestPluginInstallImage(c *check.C) { testRequires(c, DaemonIsLinux, ExperimentalDaemon) out, _, err := dockerCmdWithError("plugin", "install", "redis")