mirror of
https://github.com/docker/compose.git
synced 2025-07-16 02:04:27 +02:00
handle compose on all context types
Signed-off-by: aiordache <anca.iordache@docker.com>
This commit is contained in:
parent
cfd6d2f5d1
commit
5a26b25709
@ -17,6 +17,11 @@
|
|||||||
package compose
|
package compose
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
apicontext "github.com/docker/api/context"
|
||||||
|
"github.com/docker/api/context/store"
|
||||||
|
"github.com/docker/api/errdefs"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -25,6 +30,22 @@ func Command() *cobra.Command {
|
|||||||
command := &cobra.Command{
|
command := &cobra.Command{
|
||||||
Short: "Docker Compose",
|
Short: "Docker Compose",
|
||||||
Use: "compose",
|
Use: "compose",
|
||||||
|
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
currentContext := apicontext.CurrentContext(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())
|
||||||
|
}
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
command.AddCommand(
|
command.AddCommand(
|
||||||
|
@ -59,6 +59,7 @@ var (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
ownCommands = map[string]struct{}{
|
ownCommands = map[string]struct{}{
|
||||||
|
"compose": {},
|
||||||
"context": {},
|
"context": {},
|
||||||
"login": {},
|
"login": {},
|
||||||
"logout": {},
|
"logout": {},
|
||||||
@ -181,7 +182,6 @@ func main() {
|
|||||||
if errors.Is(ctx.Err(), context.Canceled) {
|
if errors.Is(ctx.Err(), context.Canceled) {
|
||||||
os.Exit(130)
|
os.Exit(130)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Context should always be handled by new CLI
|
// Context should always be handled by new CLI
|
||||||
requiredCmd, _, _ := root.Find(os.Args[1:])
|
requiredCmd, _, _ := root.Find(os.Args[1:])
|
||||||
if requiredCmd != nil && isOwnCommand(requiredCmd) {
|
if requiredCmd != nil && isOwnCommand(requiredCmd) {
|
||||||
@ -196,7 +196,7 @@ func main() {
|
|||||||
|
|
||||||
func exit(err error) {
|
func exit(err error) {
|
||||||
if errors.Is(err, errdefs.ErrLoginRequired) {
|
if errors.Is(err, errdefs.ErrLoginRequired) {
|
||||||
fmt.Fprintln(os.Stderr, fmt.Errorf("%v", err))
|
fmt.Fprintln(os.Stderr, err)
|
||||||
os.Exit(errdefs.ExitCodeLoginRequired)
|
os.Exit(errdefs.ExitCodeLoginRequired)
|
||||||
}
|
}
|
||||||
fatal(err)
|
fatal(err)
|
||||||
@ -242,6 +242,6 @@ func determineCurrentContext(flag string, configDir string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func fatal(err error) {
|
func fatal(err error) {
|
||||||
fmt.Fprint(os.Stderr, err)
|
fmt.Fprintln(os.Stderr, err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,6 @@ package mobycli
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
@ -52,12 +51,6 @@ func mustDelegateToMoby(ctxType string) bool {
|
|||||||
|
|
||||||
// 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) {
|
||||||
if os.Args[1] == "compose" {
|
|
||||||
// command is not implemented for moby or aws context
|
|
||||||
fmt.Fprintln(os.Stderr, errors.New("'compose' command is not implemented for the context in use"))
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
cmd := exec.CommandContext(ctx, ComDockerCli, os.Args[1:]...)
|
cmd := exec.CommandContext(ctx, ComDockerCli, os.Args[1:]...)
|
||||||
cmd.Stdin = os.Stdin
|
cmd.Stdin = os.Stdin
|
||||||
cmd.Stdout = os.Stdout
|
cmd.Stdout = os.Stdout
|
||||||
|
@ -140,6 +140,9 @@ func New(opts ...Opt) (Store, error) {
|
|||||||
|
|
||||||
// Get returns the context with the given name
|
// Get returns the context with the given name
|
||||||
func (s *store) Get(name string) (*DockerContext, error) {
|
func (s *store) Get(name string) (*DockerContext, error) {
|
||||||
|
if name == "default" {
|
||||||
|
return dockerDefaultContext()
|
||||||
|
}
|
||||||
meta := filepath.Join(s.root, contextsDir, metadataDir, contextDirOf(name), metaFile)
|
meta := filepath.Join(s.root, contextsDir, metadataDir, contextDirOf(name), metaFile)
|
||||||
m, err := read(meta)
|
m, err := read(meta)
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user