mirror of https://github.com/docker/cli.git
Merge pull request #1690 from jcsirot/fix-contextstore-for-plugins
Always initialize context store
This commit is contained in:
commit
86a5a489f7
|
@ -209,24 +209,23 @@ func (cli *DockerCli) Initialize(opts *cliflags.ClientOptions, ops ...Initialize
|
||||||
|
|
||||||
cli.configFile = cliconfig.LoadDefaultConfigFile(cli.err)
|
cli.configFile = cliconfig.LoadDefaultConfigFile(cli.err)
|
||||||
|
|
||||||
if cli.client == nil {
|
|
||||||
cli.contextStore = store.New(cliconfig.ContextStoreDir(), cli.contextStoreConfig)
|
cli.contextStore = store.New(cliconfig.ContextStoreDir(), cli.contextStoreConfig)
|
||||||
cli.currentContext, err = resolveContextName(opts.Common, cli.configFile, cli.contextStore)
|
cli.currentContext, err = resolveContextName(opts.Common, cli.configFile, cli.contextStore)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
endpoint, err := resolveDockerEndpoint(cli.contextStore, cli.currentContext, opts.Common)
|
cli.dockerEndpoint, err = resolveDockerEndpoint(cli.contextStore, cli.currentContext, opts.Common)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "unable to resolve docker endpoint")
|
return errors.Wrap(err, "unable to resolve docker endpoint")
|
||||||
}
|
}
|
||||||
cli.dockerEndpoint = endpoint
|
|
||||||
|
|
||||||
cli.client, err = newAPIClientFromEndpoint(endpoint, cli.configFile)
|
if cli.client == nil {
|
||||||
|
cli.client, err = newAPIClientFromEndpoint(cli.dockerEndpoint, cli.configFile)
|
||||||
if tlsconfig.IsErrEncryptedKey(err) {
|
if tlsconfig.IsErrEncryptedKey(err) {
|
||||||
passRetriever := passphrase.PromptRetrieverWithInOut(cli.In(), cli.Out(), nil)
|
passRetriever := passphrase.PromptRetrieverWithInOut(cli.In(), cli.Out(), nil)
|
||||||
newClient := func(password string) (client.APIClient, error) {
|
newClient := func(password string) (client.APIClient, error) {
|
||||||
endpoint.TLSPassword = password
|
cli.dockerEndpoint.TLSPassword = password
|
||||||
return newAPIClientFromEndpoint(endpoint, cli.configFile)
|
return newAPIClientFromEndpoint(cli.dockerEndpoint, cli.configFile)
|
||||||
}
|
}
|
||||||
cli.client, err = getClientWithPassword(passRetriever, newClient)
|
cli.client, err = getClientWithPassword(passRetriever, newClient)
|
||||||
}
|
}
|
||||||
|
|
|
@ -295,3 +295,12 @@ func TestNewDockerCliAndOperators(t *testing.T) {
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
assert.Equal(t, string(errStream), "error")
|
assert.Equal(t, string(errStream), "error")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestInitializeShouldAlwaysCreateTheContextStore(t *testing.T) {
|
||||||
|
cli, err := NewDockerCli()
|
||||||
|
assert.NilError(t, err)
|
||||||
|
assert.NilError(t, cli.Initialize(flags.NewClientOptions(), WithInitializeClient(func(cli *DockerCli) (client.APIClient, error) {
|
||||||
|
return client.NewClientWithOpts()
|
||||||
|
})))
|
||||||
|
assert.Check(t, cli.ContextStore() != nil)
|
||||||
|
}
|
||||||
|
|
|
@ -18,9 +18,9 @@ func TestDialStdio(t *testing.T) {
|
||||||
// follows. We observe this from the debug level logging from
|
// follows. We observe this from the debug level logging from
|
||||||
// the connhelper stuff.
|
// the connhelper stuff.
|
||||||
helloworld := filepath.Join(os.Getenv("DOCKER_CLI_E2E_PLUGINS_EXTRA_DIRS"), "docker-helloworld")
|
helloworld := filepath.Join(os.Getenv("DOCKER_CLI_E2E_PLUGINS_EXTRA_DIRS"), "docker-helloworld")
|
||||||
cmd := icmd.Command(helloworld, "--config=blah", "--tls", "--log-level", "debug", "helloworld", "--who=foo")
|
cmd := icmd.Command(helloworld, "--config=blah", "--log-level", "debug", "helloworld", "--who=foo")
|
||||||
res := icmd.RunCmd(cmd, icmd.WithEnv(manager.ReexecEnvvar+"=/bin/true"))
|
res := icmd.RunCmd(cmd, icmd.WithEnv(manager.ReexecEnvvar+"=/bin/true"))
|
||||||
res.Assert(t, icmd.Success)
|
res.Assert(t, icmd.Success)
|
||||||
assert.Assert(t, is.Contains(res.Stderr(), `msg="commandconn: starting /bin/true with [--config=blah --tls --log-level debug system dial-stdio]"`))
|
assert.Assert(t, is.Contains(res.Stderr(), `msg="commandconn: starting /bin/true with [--config=blah --log-level debug system dial-stdio]"`))
|
||||||
assert.Assert(t, is.Equal(res.Stdout(), "Hello foo!\n"))
|
assert.Assert(t, is.Equal(res.Stdout(), "Hello foo!\n"))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue