Skip to content

Commit 747f674

Browse files
committed
remove unused code to only rely on api.Service
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent 585c4db commit 747f674

File tree

6 files changed

+25
-132
lines changed

6 files changed

+25
-132
lines changed

cmd/compose/compose.go

Lines changed: 1 addition & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ import (
4040
"github.com/docker/cli/cli/command"
4141
"github.com/docker/cli/pkg/kvfile"
4242
"github.com/docker/compose/v2/cmd/formatter"
43-
"github.com/docker/compose/v2/internal/desktop"
44-
"github.com/docker/compose/v2/internal/experimental"
4543
"github.com/docker/compose/v2/internal/tracing"
4644
"github.com/docker/compose/v2/pkg/api"
4745
ui "github.com/docker/compose/v2/pkg/progress"
@@ -91,14 +89,6 @@ func init() {
9189
dotenv.RegisterFormat("raw", rawEnv)
9290
}
9391

94-
type Backend interface {
95-
api.Service
96-
97-
SetDesktopClient(cli *desktop.Client)
98-
99-
SetExperiments(experiments *experimental.State)
100-
}
101-
10292
// Command defines a compose CLI command as a func with args
10393
type Command func(context.Context, []string) error
10494

@@ -426,7 +416,7 @@ func RunningAsStandalone() bool {
426416
}
427417

428418
// RootCommand returns the compose command with its child commands
429-
func RootCommand(dockerCli command.Cli, backend Backend) *cobra.Command { //nolint:gocyclo
419+
func RootCommand(dockerCli command.Cli, backend api.Service) *cobra.Command { //nolint:gocyclo
430420
// filter out useless commandConn.CloseWrite warning message that can occur
431421
// when using a remote context that is unreachable: "commandConn.CloseWrite: commandconn: failed to wait: signal: killed"
432422
// https://github.com/docker/cli/blob/e1f24d3c93df6752d3c27c8d61d18260f141310c/cli/connhelper/commandconn/commandconn.go#L203-L215
@@ -437,7 +427,6 @@ func RootCommand(dockerCli command.Cli, backend Backend) *cobra.Command { //noli
437427
"commandConn.CloseRead:",
438428
))
439429

440-
experiments := experimental.NewState()
441430
opts := ProjectOptions{}
442431
var (
443432
ansi string
@@ -581,27 +570,6 @@ func RootCommand(dockerCli command.Cli, backend Backend) *cobra.Command { //noli
581570
}
582571
cmd.SetContext(ctx)
583572

584-
// (6) Desktop integration
585-
var desktopCli *desktop.Client
586-
if !dryRun {
587-
if desktopCli, err = desktop.NewFromDockerClient(ctx, dockerCli); desktopCli != nil {
588-
logrus.Debugf("Enabled Docker Desktop integration (experimental) @ %s", desktopCli.Endpoint())
589-
backend.SetDesktopClient(desktopCli)
590-
} else if err != nil {
591-
// not fatal, Compose will still work but behave as though
592-
// it's not running as part of Docker Desktop
593-
logrus.Debugf("failed to enable Docker Desktop integration: %v", err)
594-
} else {
595-
logrus.Trace("Docker Desktop integration not enabled")
596-
}
597-
}
598-
599-
// (7) experimental features
600-
if err := experiments.Load(ctx, desktopCli); err != nil {
601-
logrus.Debugf("Failed to query feature flags from Desktop: %v", err)
602-
}
603-
backend.SetExperiments(experiments)
604-
605573
return nil
606574
},
607575
}
@@ -715,15 +683,3 @@ var printerModes = []string{
715683
ui.ModeJSON,
716684
ui.ModeQuiet,
717685
}
718-
719-
func SetUnchangedOption(name string, experimentalFlag bool) bool {
720-
var value bool
721-
// If the var is defined we use that value first
722-
if envVar, ok := os.LookupEnv(name); ok {
723-
value = utils.StringToBool(envVar)
724-
} else {
725-
// if not, we try to get it from experimental feature flag
726-
value = experimentalFlag
727-
}
728-
return value
729-
}

cmd/main.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,7 @@ import (
3636
func pluginMain() {
3737
plugin.Run(
3838
func(dockerCli command.Cli) *cobra.Command {
39-
// TODO(milas): this cast is safe but we should not need to do this,
40-
// we should expose the concrete service type so that we do not need
41-
// to rely on the `api.Service` interface internally
42-
backend := compose.NewComposeService(dockerCli).(commands.Backend)
39+
backend := compose.NewComposeService(dockerCli)
4340
cmd := commands.RootCommand(dockerCli, backend)
4441
originalPreRunE := cmd.PersistentPreRunE
4542
cmd.PersistentPreRunE = func(cmd *cobra.Command, args []string) error {

internal/desktop/discovery.go

Lines changed: 0 additions & 62 deletions
This file was deleted.

pkg/compose/compose.go

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ import (
3838
"github.com/docker/docker/client"
3939
"github.com/jonboulle/clockwork"
4040

41-
"github.com/docker/compose/v2/internal/desktop"
42-
"github.com/docker/compose/v2/internal/experimental"
4341
"github.com/docker/compose/v2/pkg/api"
4442
)
4543

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

6563
type composeService struct {
66-
dockerCli command.Cli
67-
desktopCli *desktop.Client
68-
experiments *experimental.State
69-
64+
dockerCli command.Cli
7065
clock clockwork.Clock
7166
maxConcurrency int
7267
dryRun bool
@@ -81,9 +76,6 @@ func (s *composeService) Close() error {
8176
if s.dockerCli != nil {
8277
errs = append(errs, s.dockerCli.Client().Close())
8378
}
84-
if s.isDesktopIntegrationActive() {
85-
errs = append(errs, s.desktopCli.Close())
86-
}
8779
return errors.Join(errs...)
8880
}
8981

@@ -321,7 +313,3 @@ func (s *composeService) RuntimeVersion(ctx context.Context) (string, error) {
321313
})
322314
return runtimeVersion.val, runtimeVersion.err
323315
}
324-
325-
func (s *composeService) isDesktopIntegrationActive() bool {
326-
return s.desktopCli != nil
327-
}

pkg/compose/desktop.go

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,25 @@
1717
package compose
1818

1919
import (
20-
"github.com/docker/compose/v2/internal/desktop"
21-
"github.com/docker/compose/v2/internal/experimental"
20+
"context"
21+
"strings"
2222
)
2323

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

28-
func (s *composeService) SetExperiments(experiments *experimental.State) {
29-
s.experiments = experiments
29+
func (s *composeService) isDesktopIntegrationActive(ctx context.Context) (bool, error) {
30+
info, err := s.apiClient().Info(ctx)
31+
if err != nil {
32+
return false, err
33+
}
34+
for _, l := range info.Labels {
35+
k, _, ok := strings.Cut(l, "=")
36+
if ok && k == engineLabelDesktopAddress {
37+
return true, nil
38+
}
39+
}
40+
return false, nil
3041
}

pkg/compose/up.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,10 @@ func (s *composeService) Up(ctx context.Context, project *types.Project, options
8383
options.Start.NavigationMenu = false
8484
} else {
8585
defer keyboard.Close() //nolint:errcheck
86-
isDockerDesktopActive := s.isDesktopIntegrationActive()
86+
isDockerDesktopActive, err := s.isDesktopIntegrationActive(ctx)
87+
if err != nil {
88+
return err
89+
}
8790
tracing.KeyboardMetrics(ctx, options.Start.NavigationMenu, isDockerDesktopActive)
8891
navigationMenu = formatter.NewKeyboardManager(isDockerDesktopActive, signalChan)
8992
logConsumer = navigationMenu.Decorate(logConsumer)

0 commit comments

Comments
 (0)