Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 1 addition & 45 deletions cmd/compose/compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ import (
"github.com/docker/cli/cli/command"
"github.com/docker/cli/pkg/kvfile"
"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"
ui "github.com/docker/compose/v2/pkg/progress"
Expand Down Expand Up @@ -91,14 +89,6 @@ func init() {
dotenv.RegisterFormat("raw", rawEnv)
}

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

Expand Down Expand Up @@ -426,7 +416,7 @@ func RunningAsStandalone() bool {
}

// RootCommand returns the compose command with its child commands
func RootCommand(dockerCli command.Cli, backend Backend) *cobra.Command { //nolint:gocyclo
func RootCommand(dockerCli command.Cli, backend api.Service) *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
Expand All @@ -437,7 +427,6 @@ func RootCommand(dockerCli command.Cli, backend Backend) *cobra.Command { //noli
"commandConn.CloseRead:",
))

experiments := experimental.NewState()
opts := ProjectOptions{}
var (
ansi string
Expand Down Expand Up @@ -581,27 +570,6 @@ func RootCommand(dockerCli command.Cli, backend Backend) *cobra.Command { //noli
}
cmd.SetContext(ctx)

// (6) Desktop integration
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
},
}
Expand Down Expand Up @@ -715,15 +683,3 @@ var printerModes = []string{
ui.ModeJSON,
ui.ModeQuiet,
}

func SetUnchangedOption(name string, experimentalFlag bool) bool {
var value bool
// If the var is defined we use that value first
if envVar, ok := os.LookupEnv(name); ok {
value = utils.StringToBool(envVar)
} else {
// if not, we try to get it from experimental feature flag
value = experimentalFlag
}
return value
}
5 changes: 1 addition & 4 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@ import (
func pluginMain() {
plugin.Run(
func(dockerCli command.Cli) *cobra.Command {
// TODO(milas): this cast is safe but we should not need to do this,
// we should expose the concrete service type so that we do not need
// to rely on the `api.Service` interface internally
backend := compose.NewComposeService(dockerCli).(commands.Backend)
backend := compose.NewComposeService(dockerCli)
cmd := commands.RootCommand(dockerCli, backend)
originalPreRunE := cmd.PersistentPreRunE
cmd.PersistentPreRunE = func(cmd *cobra.Command, args []string) error {
Expand Down
62 changes: 0 additions & 62 deletions internal/desktop/discovery.go

This file was deleted.

14 changes: 1 addition & 13 deletions pkg/compose/compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ import (
"github.com/docker/docker/client"
"github.com/jonboulle/clockwork"

"github.com/docker/compose/v2/internal/desktop"
"github.com/docker/compose/v2/internal/experimental"
"github.com/docker/compose/v2/pkg/api"
)

Expand All @@ -63,10 +61,7 @@ func NewComposeService(dockerCli command.Cli) api.Service {
}

type composeService struct {
dockerCli command.Cli
desktopCli *desktop.Client
experiments *experimental.State

dockerCli command.Cli
clock clockwork.Clock
maxConcurrency int
dryRun bool
Expand All @@ -81,9 +76,6 @@ func (s *composeService) Close() error {
if s.dockerCli != nil {
errs = append(errs, s.dockerCli.Client().Close())
}
if s.isDesktopIntegrationActive() {
errs = append(errs, s.desktopCli.Close())
}
return errors.Join(errs...)
}

Expand Down Expand Up @@ -321,7 +313,3 @@ func (s *composeService) RuntimeVersion(ctx context.Context) (string, error) {
})
return runtimeVersion.val, runtimeVersion.err
}

func (s *composeService) isDesktopIntegrationActive() bool {
return s.desktopCli != nil
}
25 changes: 18 additions & 7 deletions pkg/compose/desktop.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,25 @@
package compose

import (
"github.com/docker/compose/v2/internal/desktop"
"github.com/docker/compose/v2/internal/experimental"
"context"
"strings"
)

func (s *composeService) SetDesktopClient(cli *desktop.Client) {
s.desktopCli = cli
}
// engineLabelDesktopAddress is used to detect that Compose is running with a
// Docker Desktop context. When this label is present, the value is an endpoint
// address for an in-memory socket (AF_UNIX or named pipe).
const engineLabelDesktopAddress = "com.docker.desktop.address"

func (s *composeService) SetExperiments(experiments *experimental.State) {
s.experiments = experiments
func (s *composeService) isDesktopIntegrationActive(ctx context.Context) (bool, error) {
info, err := s.apiClient().Info(ctx)
if err != nil {
return false, err
}
for _, l := range info.Labels {
k, _, ok := strings.Cut(l, "=")
if ok && k == engineLabelDesktopAddress {
return true, nil
}
}
return false, nil
}
5 changes: 4 additions & 1 deletion pkg/compose/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ func (s *composeService) Up(ctx context.Context, project *types.Project, options
options.Start.NavigationMenu = false
} else {
defer keyboard.Close() //nolint:errcheck
isDockerDesktopActive := s.isDesktopIntegrationActive()
isDockerDesktopActive, err := s.isDesktopIntegrationActive(ctx)
if err != nil {
return err
}
tracing.KeyboardMetrics(ctx, options.Start.NavigationMenu, isDockerDesktopActive)
navigationMenu = formatter.NewKeyboardManager(isDockerDesktopActive, signalChan)
logConsumer = navigationMenu.Decorate(logConsumer)
Expand Down