1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

support settings in docker plugins install

Signed-off-by: Victor Vieux <vieux@docker.com>
This commit is contained in:
Victor Vieux 2016-11-07 17:43:11 -08:00
parent 03da822ee9
commit 69276fddf8
7 changed files with 33 additions and 9 deletions

View file

@ -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
}

View file

@ -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

View file

@ -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 {

View file

@ -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)
}

View file

@ -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]

View file

@ -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

View file

@ -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")