Browse Source

Merge pull request #28142 from vieux/plugin_install_args

support settings in docker plugins install
Tibor Vass 8 years ago
parent
commit
c33fb1013d

+ 1 - 0
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
 }

+ 7 - 2
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

+ 1 - 1
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 {

+ 8 - 0
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)
 }
 

+ 6 - 5
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]

+ 1 - 1
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
 

+ 9 - 0
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")