mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
f37117045c
This patch introduces a new experimental engine-level plugin management with a new API and command line. Plugins can be distributed via a Docker registry, and their lifecycle is managed by the engine. This makes plugins a first-class construct. For more background, have a look at issue #20363. Documentation is in a separate commit. If you want to understand how the new plugin system works, you can start by reading the documentation. Note: backwards compatibility with existing plugins is maintained, albeit they won't benefit from the advantages of the new system. Signed-off-by: Tibor Vass <tibor@docker.com> Signed-off-by: Anusha Ragunathan <anusha@docker.com>
51 lines
1.3 KiB
Go
51 lines
1.3 KiB
Go
// +build experimental
|
|
|
|
package plugin
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/docker/docker/api/client"
|
|
"github.com/docker/docker/cli"
|
|
"github.com/docker/docker/reference"
|
|
"github.com/docker/docker/registry"
|
|
"github.com/spf13/cobra"
|
|
"golang.org/x/net/context"
|
|
)
|
|
|
|
func newInstallCommand(dockerCli *client.DockerCli) *cobra.Command {
|
|
cmd := &cobra.Command{
|
|
Use: "install",
|
|
Short: "Install a plugin",
|
|
Args: cli.RequiresMinArgs(1), // TODO: allow for set args
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
return runInstall(dockerCli, args[0], args[1:])
|
|
},
|
|
}
|
|
|
|
return cmd
|
|
}
|
|
|
|
func runInstall(dockerCli *client.DockerCli, name string, args []string) error {
|
|
named, err := reference.ParseNamed(name) // FIXME: validate
|
|
if err != nil {
|
|
return err
|
|
}
|
|
named = reference.WithDefaultTag(named)
|
|
ref, ok := named.(reference.NamedTagged)
|
|
if !ok {
|
|
return fmt.Errorf("invalid name: %s", named.String())
|
|
}
|
|
|
|
ctx := context.Background()
|
|
|
|
repoInfo, err := registry.ParseRepositoryInfo(named)
|
|
authConfig := dockerCli.ResolveAuthConfig(ctx, repoInfo.Index)
|
|
|
|
encodedAuth, err := client.EncodeAuthToBase64(authConfig)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
// TODO: pass acceptAllPermissions and noEnable flag
|
|
return dockerCli.Client().PluginInstall(ctx, ref.String(), encodedAuth, false, false, dockerCli.In(), dockerCli.Out())
|
|
}
|