mirror of https://github.com/docker/compose.git
commit
4c3c219518
|
@ -17,9 +17,12 @@
|
||||||
package compose
|
package compose
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
|
"github.com/docker/api/client"
|
||||||
apicontext "github.com/docker/api/context"
|
apicontext "github.com/docker/api/context"
|
||||||
"github.com/docker/api/context/store"
|
"github.com/docker/api/context/store"
|
||||||
"github.com/docker/api/errdefs"
|
"github.com/docker/api/errdefs"
|
||||||
|
@ -31,20 +34,7 @@ func Command() *cobra.Command {
|
||||||
Short: "Docker Compose",
|
Short: "Docker Compose",
|
||||||
Use: "compose",
|
Use: "compose",
|
||||||
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
|
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
|
||||||
currentContext := apicontext.CurrentContext(cmd.Context())
|
return checkComposeSupport(cmd.Context())
|
||||||
s := store.ContextStore(cmd.Context())
|
|
||||||
cc, err := s.Get(currentContext)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
switch cc.Type() {
|
|
||||||
case store.AciContextType:
|
|
||||||
return nil
|
|
||||||
case store.AwsContextType:
|
|
||||||
return errors.New("use 'docker ecs compose' on context type " + cc.Type())
|
|
||||||
default:
|
|
||||||
return errors.Wrapf(errdefs.ErrNotImplemented, "compose command not supported on context type %q", cc.Type())
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,3 +45,26 @@ func Command() *cobra.Command {
|
||||||
|
|
||||||
return command
|
return command
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func checkComposeSupport(ctx context.Context) error {
|
||||||
|
c, err := client.New(ctx)
|
||||||
|
if err == nil {
|
||||||
|
composeService := c.ComposeService()
|
||||||
|
if composeService == nil {
|
||||||
|
return errors.New("compose not implemented in current context")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
currentContext := apicontext.CurrentContext(ctx)
|
||||||
|
s := store.ContextStore(ctx)
|
||||||
|
cc, err := s.Get(currentContext)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
switch cc.Type() {
|
||||||
|
case store.AwsContextType:
|
||||||
|
return errors.New("use 'docker ecs compose' on context type " + cc.Type())
|
||||||
|
default:
|
||||||
|
return errors.Wrapf(errdefs.ErrNotImplemented, "compose command not supported on context type %q", cc.Type())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue