mirror of
https://github.com/docker/compose.git
synced 2025-07-31 01:24:15 +02:00
Fix bug where we shell out to Moby cli only if context == default. We must shell out to Moby cli for any context of type “Moby”, not only the default context.
This commit is contained in:
parent
fe57e4c159
commit
3981244701
@ -19,12 +19,13 @@ const ComDockerCli = "com.docker.cli"
|
|||||||
// Exec delegates to com.docker.cli if on moby context
|
// Exec delegates to com.docker.cli if on moby context
|
||||||
func Exec(ctx context.Context) {
|
func Exec(ctx context.Context) {
|
||||||
currentContext := apicontext.CurrentContext(ctx)
|
currentContext := apicontext.CurrentContext(ctx)
|
||||||
|
|
||||||
s := store.ContextStore(ctx)
|
s := store.ContextStore(ctx)
|
||||||
|
|
||||||
_, err := s.Get(currentContext)
|
currentCtx, err := s.Get(currentContext)
|
||||||
// Only run original docker command if the current context is not
|
// Only run original docker command if the current context is not
|
||||||
// ours.
|
// ours.
|
||||||
if err != nil {
|
if err != nil || currentCtx.Type() == store.DefaultContextType {
|
||||||
shellOut(ctx)
|
shellOut(ctx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ type DockerContext struct {
|
|||||||
// Type the context type
|
// Type the context type
|
||||||
func (m *DockerContext) Type() string {
|
func (m *DockerContext) Type() string {
|
||||||
if m.Metadata.Type == "" {
|
if m.Metadata.Type == "" {
|
||||||
return defaultContextType
|
return DefaultContextType
|
||||||
}
|
}
|
||||||
return m.Metadata.Type
|
return m.Metadata.Type
|
||||||
}
|
}
|
||||||
|
@ -45,6 +45,17 @@ import (
|
|||||||
const (
|
const (
|
||||||
// DefaultContextName is an automatically generated local context
|
// DefaultContextName is an automatically generated local context
|
||||||
DefaultContextName = "default"
|
DefaultContextName = "default"
|
||||||
|
// DefaultContextType is the type for all moby contexts (not associated with cli backend)
|
||||||
|
DefaultContextType = "moby"
|
||||||
|
// AciContextType is the endpoint key in the context endpoints for an ACI
|
||||||
|
// backend
|
||||||
|
AciContextType = "aci"
|
||||||
|
// LocalContextType is the endpoint key in the context endpoints for a new
|
||||||
|
// local backend
|
||||||
|
LocalContextType = "local"
|
||||||
|
// ExampleContextType is the endpoint key in the context endpoints for an
|
||||||
|
// example backend
|
||||||
|
ExampleContextType = "example"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -92,18 +103,6 @@ type Endpoint struct {
|
|||||||
DefaultNamespace string `json:",omitempty"`
|
DefaultNamespace string `json:",omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
|
||||||
// AciContextType is the endpoint key in the context endpoints for an ACI
|
|
||||||
// backend
|
|
||||||
AciContextType = "aci"
|
|
||||||
// LocalContextType is the endpoint key in the context endpoints for a new
|
|
||||||
// local backend
|
|
||||||
LocalContextType = "local"
|
|
||||||
// ExampleContextType is the endpoint key in the context endpoints for an
|
|
||||||
// example backend
|
|
||||||
ExampleContextType = "example"
|
|
||||||
)
|
|
||||||
|
|
||||||
type store struct {
|
type store struct {
|
||||||
root string
|
root string
|
||||||
}
|
}
|
||||||
|
@ -8,8 +8,6 @@ import (
|
|||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
const defaultContextType = "moby"
|
|
||||||
|
|
||||||
// Represents a context as created by the docker cli
|
// Represents a context as created by the docker cli
|
||||||
type defaultContext struct {
|
type defaultContext struct {
|
||||||
Metadata ContextMetadata
|
Metadata ContextMetadata
|
||||||
@ -67,7 +65,7 @@ func dockerDefaultContext() (*DockerContext, error) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
Metadata: ContextMetadata{
|
Metadata: ContextMetadata{
|
||||||
Type: defaultContextType,
|
Type: DefaultContextType,
|
||||||
Description: "Current DOCKER_HOST based configuration",
|
Description: "Current DOCKER_HOST based configuration",
|
||||||
StackOrchestrator: defaultCtx.Metadata.StackOrchestrator,
|
StackOrchestrator: defaultCtx.Metadata.StackOrchestrator,
|
||||||
},
|
},
|
||||||
|
@ -169,6 +169,13 @@ func (s *E2eSuite) TestLegacy() {
|
|||||||
output := s.NewDockerCommand("run", "--rm", "hello-world").WithTimeout(time.NewTimer(20 * time.Second).C).ExecOrDie()
|
output := s.NewDockerCommand("run", "--rm", "hello-world").WithTimeout(time.NewTimer(20 * time.Second).C).ExecOrDie()
|
||||||
Expect(output).To(ContainSubstring("Hello from Docker!"))
|
Expect(output).To(ContainSubstring("Hello from Docker!"))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("should execute legacy commands in other moby contexts", func() {
|
||||||
|
s.NewDockerCommand("context", "create", "mobyCtx", "--from=default").ExecOrDie()
|
||||||
|
s.NewDockerCommand("context", "use", "mobyCtx").ExecOrDie()
|
||||||
|
output, _ := s.NewDockerCommand("swarm", "join").Exec()
|
||||||
|
Expect(output).To(ContainSubstring("\"docker swarm join\" requires exactly 1 argument."))
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *E2eSuite) TestLeaveLegacyErrorMessagesUnchanged() {
|
func (s *E2eSuite) TestLeaveLegacyErrorMessagesUnchanged() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user