Browse code

support settings in docker plugins install

Signed-off-by: Victor Vieux <vieux@docker.com>

Victor Vieux authored on 2016/11/08 10:43:11
Showing 7 changed files
... ...
@@ -337,4 +337,5 @@ type PluginInstallOptions struct {
337 337
 	RegistryAuth          string // RegistryAuth is the base64 encoded credentials for the registry
338 338
 	PrivilegeFunc         RequestPrivilegeFunc
339 339
 	AcceptPermissionsFunc func(PluginPrivileges) (bool, error)
340
+	Args                  []string
340 341
 }
... ...
@@ -18,16 +18,20 @@ type pluginOptions struct {
18 18
 	name       string
19 19
 	grantPerms bool
20 20
 	disable    bool
21
+	args       []string
21 22
 }
22 23
 
23 24
 func newInstallCommand(dockerCli *command.DockerCli) *cobra.Command {
24 25
 	var options pluginOptions
25 26
 	cmd := &cobra.Command{
26
-		Use:   "install [OPTIONS] PLUGIN",
27
+		Use:   "install [OPTIONS] PLUGIN [KEY=VALUE...]",
27 28
 		Short: "Install a plugin",
28
-		Args:  cli.ExactArgs(1), // TODO: allow for set args
29
+		Args:  cli.RequiresMinArgs(1),
29 30
 		RunE: func(cmd *cobra.Command, args []string) error {
30 31
 			options.name = args[0]
32
+			if len(args) > 1 {
33
+				options.args = args[1:]
34
+			}
31 35
 			return runInstall(dockerCli, options)
32 36
 		},
33 37
 	}
... ...
@@ -75,6 +79,7 @@ func runInstall(dockerCli *command.DockerCli, opts pluginOptions) error {
75 75
 		AcceptPermissionsFunc: acceptPrivileges(dockerCli, opts.name),
76 76
 		// TODO: Rename PrivilegeFunc, it has nothing to do with privileges
77 77
 		PrivilegeFunc: registryAuthFunc,
78
+		Args:          opts.args,
78 79
 	}
79 80
 	if err := dockerCli.Client().PluginInstall(ctx, ref.String(), options); err != nil {
80 81
 		return err
... ...
@@ -13,7 +13,7 @@ import (
13 13
 
14 14
 func newSetCommand(dockerCli *command.DockerCli) *cobra.Command {
15 15
 	cmd := &cobra.Command{
16
-		Use:   "set PLUGIN key1=value1 [key2=value2...]",
16
+		Use:   "set PLUGIN KEY=VALUE [KEY=VALUE...]",
17 17
 		Short: "Change settings for a plugin",
18 18
 		Args:  cli.RequiresMinArgs(2),
19 19
 		RunE: func(cmd *cobra.Command, args []string) error {
... ...
@@ -45,9 +45,17 @@ func (cli *Client) PluginInstall(ctx context.Context, name string, options types
45 45
 			return pluginPermissionDenied{name}
46 46
 		}
47 47
 	}
48
+
49
+	if len(options.Args) > 0 {
50
+		if err := cli.PluginSet(ctx, name, options.Args); err != nil {
51
+			return err
52
+		}
53
+	}
54
+
48 55
 	if options.Disabled {
49 56
 		return nil
50 57
 	}
58
+
51 59
 	return cli.PluginEnable(ctx, name)
52 60
 }
53 61
 
... ...
@@ -17,7 +17,7 @@ advisory: "experimental"
17 17
 # plugin install (experimental)
18 18
 
19 19
 ```markdown
20
-Usage:  docker plugin install [OPTIONS] PLUGIN
20
+Usage:  docker plugin install [OPTIONS] PLUGIN [KEY=VALUE...]
21 21
 
22 22
 Install a plugin
23 23
 
... ...
@@ -33,12 +33,13 @@ the registry. Note that the minimum required registry version to distribute
33 33
 plugins is 2.3.0
34 34
 
35 35
 
36
-The following example installs `no-remove` plugin. Install consists of pulling the
37
-plugin from Docker Hub, prompting the user to accept the list of privileges that
38
-the plugin needs and enabling the plugin.
36
+The following example installs `no-remove` plugin and [set](plugin_set.md) it's env variable
37
+`DEBUG` to 1. Install consists of pulling the plugin from Docker Hub, prompting
38
+the user to accept the list of privileges that the plugin needs, settings parameters
39
+ and enabling the plugin.
39 40
 
40 41
 ```bash
41
-$ docker plugin install tiborvass/no-remove
42
+$ docker plugin install tiborvass/no-remove DEBUG=1
42 43
 
43 44
 Plugin "tiborvass/no-remove" is requesting the following privileges:
44 45
  - network: [host]
... ...
@@ -17,7 +17,7 @@ advisory: "experimental"
17 17
 # plugin set (experimental)
18 18
 
19 19
 ```markdown
20
-Usage:  docker plugin set PLUGIN key1=value1 [key2=value2...]
20
+Usage:  docker plugin set PLUGIN KEY=VALUE [KEY=VALUE...]
21 21
 
22 22
 Change settings for a plugin
23 23
 
... ...
@@ -131,6 +131,15 @@ func (s *DockerSuite) TestPluginSet(c *check.C) {
131 131
 	c.Assert(strings.TrimSpace(env), checker.Equals, "[DEBUG=1]")
132 132
 }
133 133
 
134
+func (s *DockerSuite) TestPluginInstallArgs(c *check.C) {
135
+	testRequires(c, DaemonIsLinux, ExperimentalDaemon, Network)
136
+	out, _ := dockerCmd(c, "plugin", "install", "--grant-all-permissions", "--disable", pName, "DEBUG=1")
137
+	c.Assert(strings.TrimSpace(out), checker.Contains, pName)
138
+
139
+	env, _ := dockerCmd(c, "plugin", "inspect", "-f", "{{.Config.Env}}", pName)
140
+	c.Assert(strings.TrimSpace(env), checker.Equals, "[DEBUG=1]")
141
+}
142
+
134 143
 func (s *DockerSuite) TestPluginInstallImage(c *check.C) {
135 144
 	testRequires(c, DaemonIsLinux, ExperimentalDaemon)
136 145
 	out, _, err := dockerCmdWithError("plugin", "install", "redis")