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:
parent
03da822ee9
commit
69276fddf8
7 changed files with 33 additions and 9 deletions
|
@ -337,4 +337,5 @@ type PluginInstallOptions struct {
|
||||||
RegistryAuth string // RegistryAuth is the base64 encoded credentials for the registry
|
RegistryAuth string // RegistryAuth is the base64 encoded credentials for the registry
|
||||||
PrivilegeFunc RequestPrivilegeFunc
|
PrivilegeFunc RequestPrivilegeFunc
|
||||||
AcceptPermissionsFunc func(PluginPrivileges) (bool, error)
|
AcceptPermissionsFunc func(PluginPrivileges) (bool, error)
|
||||||
|
Args []string
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,16 +18,20 @@ type pluginOptions struct {
|
||||||
name string
|
name string
|
||||||
grantPerms bool
|
grantPerms bool
|
||||||
disable bool
|
disable bool
|
||||||
|
args []string
|
||||||
}
|
}
|
||||||
|
|
||||||
func newInstallCommand(dockerCli *command.DockerCli) *cobra.Command {
|
func newInstallCommand(dockerCli *command.DockerCli) *cobra.Command {
|
||||||
var options pluginOptions
|
var options pluginOptions
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "install [OPTIONS] PLUGIN",
|
Use: "install [OPTIONS] PLUGIN [KEY=VALUE...]",
|
||||||
Short: "Install a plugin",
|
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 {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
options.name = args[0]
|
options.name = args[0]
|
||||||
|
if len(args) > 1 {
|
||||||
|
options.args = args[1:]
|
||||||
|
}
|
||||||
return runInstall(dockerCli, options)
|
return runInstall(dockerCli, options)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -75,6 +79,7 @@ func runInstall(dockerCli *command.DockerCli, opts pluginOptions) error {
|
||||||
AcceptPermissionsFunc: acceptPrivileges(dockerCli, opts.name),
|
AcceptPermissionsFunc: acceptPrivileges(dockerCli, opts.name),
|
||||||
// TODO: Rename PrivilegeFunc, it has nothing to do with privileges
|
// TODO: Rename PrivilegeFunc, it has nothing to do with privileges
|
||||||
PrivilegeFunc: registryAuthFunc,
|
PrivilegeFunc: registryAuthFunc,
|
||||||
|
Args: opts.args,
|
||||||
}
|
}
|
||||||
if err := dockerCli.Client().PluginInstall(ctx, ref.String(), options); err != nil {
|
if err := dockerCli.Client().PluginInstall(ctx, ref.String(), options); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -13,7 +13,7 @@ import (
|
||||||
|
|
||||||
func newSetCommand(dockerCli *command.DockerCli) *cobra.Command {
|
func newSetCommand(dockerCli *command.DockerCli) *cobra.Command {
|
||||||
cmd := &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",
|
Short: "Change settings for a plugin",
|
||||||
Args: cli.RequiresMinArgs(2),
|
Args: cli.RequiresMinArgs(2),
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
|
|
@ -45,9 +45,17 @@ func (cli *Client) PluginInstall(ctx context.Context, name string, options types
|
||||||
return pluginPermissionDenied{name}
|
return pluginPermissionDenied{name}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(options.Args) > 0 {
|
||||||
|
if err := cli.PluginSet(ctx, name, options.Args); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if options.Disabled {
|
if options.Disabled {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return cli.PluginEnable(ctx, name)
|
return cli.PluginEnable(ctx, name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ advisory: "experimental"
|
||||||
# plugin install (experimental)
|
# plugin install (experimental)
|
||||||
|
|
||||||
```markdown
|
```markdown
|
||||||
Usage: docker plugin install [OPTIONS] PLUGIN
|
Usage: docker plugin install [OPTIONS] PLUGIN [KEY=VALUE...]
|
||||||
|
|
||||||
Install a plugin
|
Install a plugin
|
||||||
|
|
||||||
|
@ -33,12 +33,13 @@ the registry. Note that the minimum required registry version to distribute
|
||||||
plugins is 2.3.0
|
plugins is 2.3.0
|
||||||
|
|
||||||
|
|
||||||
The following example installs `no-remove` plugin. Install consists of pulling the
|
The following example installs `no-remove` plugin and [set](plugin_set.md) it's env variable
|
||||||
plugin from Docker Hub, prompting the user to accept the list of privileges that
|
`DEBUG` to 1. Install consists of pulling the plugin from Docker Hub, prompting
|
||||||
the plugin needs and enabling the plugin.
|
the user to accept the list of privileges that the plugin needs, settings parameters
|
||||||
|
and enabling the plugin.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ docker plugin install tiborvass/no-remove
|
$ docker plugin install tiborvass/no-remove DEBUG=1
|
||||||
|
|
||||||
Plugin "tiborvass/no-remove" is requesting the following privileges:
|
Plugin "tiborvass/no-remove" is requesting the following privileges:
|
||||||
- network: [host]
|
- network: [host]
|
||||||
|
|
|
@ -17,7 +17,7 @@ advisory: "experimental"
|
||||||
# plugin set (experimental)
|
# plugin set (experimental)
|
||||||
|
|
||||||
```markdown
|
```markdown
|
||||||
Usage: docker plugin set PLUGIN key1=value1 [key2=value2...]
|
Usage: docker plugin set PLUGIN KEY=VALUE [KEY=VALUE...]
|
||||||
|
|
||||||
Change settings for a plugin
|
Change settings for a plugin
|
||||||
|
|
||||||
|
|
|
@ -131,6 +131,15 @@ func (s *DockerSuite) TestPluginSet(c *check.C) {
|
||||||
c.Assert(strings.TrimSpace(env), checker.Equals, "[DEBUG=1]")
|
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) {
|
func (s *DockerSuite) TestPluginInstallImage(c *check.C) {
|
||||||
testRequires(c, DaemonIsLinux, ExperimentalDaemon)
|
testRequires(c, DaemonIsLinux, ExperimentalDaemon)
|
||||||
out, _, err := dockerCmdWithError("plugin", "install", "redis")
|
out, _, err := dockerCmdWithError("plugin", "install", "redis")
|
||||||
|
|
Loading…
Reference in a new issue