|
@@ -38,6 +38,7 @@ import (
|
|
|
"github.com/docker/cli/cli/command"
|
|
|
"github.com/docker/compose/v2/cmd/formatter"
|
|
|
"github.com/docker/compose/v2/internal/desktop"
|
|
|
+ "github.com/docker/compose/v2/internal/experimental"
|
|
|
"github.com/docker/compose/v2/internal/tracing"
|
|
|
"github.com/docker/compose/v2/pkg/api"
|
|
|
"github.com/docker/compose/v2/pkg/compose"
|
|
@@ -66,6 +67,14 @@ const (
|
|
|
ComposeEnvFiles = "COMPOSE_ENV_FILES"
|
|
|
)
|
|
|
|
|
|
+type Backend interface {
|
|
|
+ api.Service
|
|
|
+
|
|
|
+ SetDesktopClient(cli *desktop.Client)
|
|
|
+
|
|
|
+ SetExperiments(experiments *experimental.State)
|
|
|
+}
|
|
|
+
|
|
|
// Command defines a compose CLI command as a func with args
|
|
|
type Command func(context.Context, []string) error
|
|
|
|
|
@@ -326,7 +335,7 @@ func RunningAsStandalone() bool {
|
|
|
}
|
|
|
|
|
|
// RootCommand returns the compose command with its child commands
|
|
|
-func RootCommand(dockerCli command.Cli, backend api.Service) *cobra.Command { //nolint:gocyclo
|
|
|
+func RootCommand(dockerCli command.Cli, backend Backend) *cobra.Command { //nolint:gocyclo
|
|
|
// filter out useless commandConn.CloseWrite warning message that can occur
|
|
|
// when using a remote context that is unreachable: "commandConn.CloseWrite: commandconn: failed to wait: signal: killed"
|
|
|
// https://github.com/docker/cli/blob/e1f24d3c93df6752d3c27c8d61d18260f141310c/cli/connhelper/commandconn/commandconn.go#L203-L215
|
|
@@ -337,6 +346,7 @@ func RootCommand(dockerCli command.Cli, backend api.Service) *cobra.Command { //
|
|
|
"commandConn.CloseRead:",
|
|
|
))
|
|
|
|
|
|
+ experiments := experimental.NewState()
|
|
|
opts := ProjectOptions{}
|
|
|
var (
|
|
|
ansi string
|
|
@@ -486,20 +496,32 @@ func RootCommand(dockerCli command.Cli, backend api.Service) *cobra.Command { //
|
|
|
cmd.SetContext(ctx)
|
|
|
|
|
|
// (6) Desktop integration
|
|
|
- if db, ok := backend.(desktop.IntegrationService); ok {
|
|
|
- if err := db.MaybeEnableDesktopIntegration(ctx); err != nil {
|
|
|
+ var desktopCli *desktop.Client
|
|
|
+ if !dryRun {
|
|
|
+ if desktopCli, err = desktop.NewFromDockerClient(ctx, dockerCli); desktopCli != nil {
|
|
|
+ logrus.Debugf("Enabled Docker Desktop integration (experimental) @ %s", desktopCli.Endpoint())
|
|
|
+ backend.SetDesktopClient(desktopCli)
|
|
|
+ } else if err != nil {
|
|
|
// not fatal, Compose will still work but behave as though
|
|
|
// it's not running as part of Docker Desktop
|
|
|
logrus.Debugf("failed to enable Docker Desktop integration: %v", err)
|
|
|
+ } else {
|
|
|
+ logrus.Trace("Docker Desktop integration not enabled")
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // (7) experimental features
|
|
|
+ if err := experiments.Load(ctx, desktopCli); err != nil {
|
|
|
+ logrus.Debugf("Failed to query feature flags from Desktop: %v", err)
|
|
|
+ }
|
|
|
+ backend.SetExperiments(experiments)
|
|
|
+
|
|
|
return nil
|
|
|
},
|
|
|
}
|
|
|
|
|
|
c.AddCommand(
|
|
|
- upCommand(&opts, dockerCli, backend),
|
|
|
+ upCommand(&opts, dockerCli, backend, experiments),
|
|
|
downCommand(&opts, dockerCli, backend),
|
|
|
startCommand(&opts, dockerCli, backend),
|
|
|
restartCommand(&opts, dockerCli, backend),
|