Remove feature flag integration with Docker Desktop for ComposeUI and ComposeNav

Signed-off-by: Joana Hrotko <joana.hrotko@docker.com>
This commit is contained in:
Joana Hrotko 2024-10-07 15:37:22 +01:00 committed by Guillaume Lours
parent 82b41b9ebd
commit 407d825705
7 changed files with 21 additions and 45 deletions

View File

@ -580,7 +580,7 @@ func RootCommand(dockerCli command.Cli, backend Backend) *cobra.Command { //noli
} }
c.AddCommand( c.AddCommand(
upCommand(&opts, dockerCli, backend, experiments), upCommand(&opts, dockerCli, backend),
downCommand(&opts, dockerCli, backend), downCommand(&opts, dockerCli, backend),
startCommand(&opts, dockerCli, backend), startCommand(&opts, dockerCli, backend),
restartCommand(&opts, dockerCli, backend), restartCommand(&opts, dockerCli, backend),

View File

@ -27,7 +27,6 @@ import (
"github.com/compose-spec/compose-go/v2/types" "github.com/compose-spec/compose-go/v2/types"
"github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command"
"github.com/docker/compose/v2/cmd/formatter" "github.com/docker/compose/v2/cmd/formatter"
"github.com/docker/compose/v2/internal/experimental"
xprogress "github.com/moby/buildkit/util/progress/progressui" xprogress "github.com/moby/buildkit/util/progress/progressui"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@ -81,13 +80,19 @@ func (opts upOptions) apply(project *types.Project, services []string) (*types.P
return project, nil return project, nil
} }
func (opts *upOptions) validateNavigationMenu(dockerCli command.Cli, experimentals *experimental.State) { func (opts *upOptions) validateNavigationMenu(dockerCli command.Cli) {
if !dockerCli.Out().IsTerminal() { if !dockerCli.Out().IsTerminal() {
opts.navigationMenu = false opts.navigationMenu = false
return return
} }
// If --menu flag was not set
if !opts.navigationMenuChanged { if !opts.navigationMenuChanged {
opts.navigationMenu = SetUnchangedOption(ComposeMenu, experimentals.NavBar()) if envVar, ok := os.LookupEnv(ComposeMenu); ok {
opts.navigationMenu = utils.StringToBool(envVar)
return
}
// ...and COMPOSE_MENU env var is not defined we want the default value to be true
opts.navigationMenu = true
} }
} }
@ -102,7 +107,7 @@ func (opts upOptions) OnExit() api.Cascade {
} }
} }
func upCommand(p *ProjectOptions, dockerCli command.Cli, backend api.Service, experiments *experimental.State) *cobra.Command { func upCommand(p *ProjectOptions, dockerCli command.Cli, backend api.Service) *cobra.Command {
up := upOptions{} up := upOptions{}
create := createOptions{} create := createOptions{}
build := buildOptions{ProjectOptions: p} build := buildOptions{ProjectOptions: p}
@ -127,7 +132,7 @@ func upCommand(p *ProjectOptions, dockerCli command.Cli, backend api.Service, ex
return errors.New("cannot combine --attach and --attach-dependencies") return errors.New("cannot combine --attach and --attach-dependencies")
} }
up.validateNavigationMenu(dockerCli, experiments) up.validateNavigationMenu(dockerCli)
if !p.All && len(project.Services) == 0 { if !p.All && len(project.Services) == 0 {
return fmt.Errorf("no service selected") return fmt.Errorf("no service selected")

View File

@ -106,7 +106,6 @@ type LogKeyboard struct {
Watch KeyboardWatch Watch KeyboardWatch
IsDockerDesktopActive bool IsDockerDesktopActive bool
IsWatchConfigured bool IsWatchConfigured bool
IsDDComposeUIActive bool
logLevel KEYBOARD_LOG_LEVEL logLevel KEYBOARD_LOG_LEVEL
signalChannel chan<- os.Signal signalChannel chan<- os.Signal
} }
@ -114,7 +113,7 @@ type LogKeyboard struct {
var KeyboardManager *LogKeyboard var KeyboardManager *LogKeyboard
var eg multierror.Group var eg multierror.Group
func NewKeyboardManager(ctx context.Context, isDockerDesktopActive, isWatchConfigured, isDockerDesktopConfigActive bool, func NewKeyboardManager(ctx context.Context, isDockerDesktopActive, isWatchConfigured bool,
sc chan<- os.Signal, sc chan<- os.Signal,
watchFn func(ctx context.Context, watchFn func(ctx context.Context,
doneCh chan bool, doneCh chan bool,
@ -126,7 +125,6 @@ func NewKeyboardManager(ctx context.Context, isDockerDesktopActive, isWatchConfi
km := LogKeyboard{} km := LogKeyboard{}
km.IsDockerDesktopActive = isDockerDesktopActive km.IsDockerDesktopActive = isDockerDesktopActive
km.IsWatchConfigured = isWatchConfigured km.IsWatchConfigured = isWatchConfigured
km.IsDDComposeUIActive = isDockerDesktopConfigActive
km.logLevel = INFO km.logLevel = INFO
km.Watch.Watching = false km.Watch.Watching = false
@ -200,9 +198,10 @@ func (lk *LogKeyboard) navigationMenu() string {
if openDDInfo != "" { if openDDInfo != "" {
openDDUI = navColor(" ") openDDUI = navColor(" ")
} }
if lk.IsDDComposeUIActive { if lk.IsDockerDesktopActive {
openDDUI = openDDUI + shortcutKeyColor("o") + navColor(" View Config") openDDUI = openDDUI + shortcutKeyColor("o") + navColor(" View Config")
} }
var watchInfo string var watchInfo string
if openDDInfo != "" || openDDUI != "" { if openDDInfo != "" || openDDUI != "" {
watchInfo = navColor(" ") watchInfo = navColor(" ")
@ -246,7 +245,7 @@ func (lk *LogKeyboard) openDockerDesktop(ctx context.Context, project *types.Pro
} }
func (lk *LogKeyboard) openDDComposeUI(ctx context.Context, project *types.Project) { func (lk *LogKeyboard) openDDComposeUI(ctx context.Context, project *types.Project) {
if !lk.IsDDComposeUIActive { if !lk.IsDockerDesktopActive {
return return
} }
eg.Go(tracing.EventWrapFuncForErrGroup(ctx, "menu/gui/composeview", tracing.SpanOptions{}, eg.Go(tracing.EventWrapFuncForErrGroup(ctx, "menu/gui/composeview", tracing.SpanOptions{},
@ -319,8 +318,8 @@ func (lk *LogKeyboard) HandleKeyEvents(event keyboard.KeyEvent, ctx context.Cont
lk.openDockerDesktop(ctx, project) lk.openDockerDesktop(ctx, project)
case 'w': case 'w':
if !lk.IsWatchConfigured { if !lk.IsWatchConfigured {
if lk.IsDDComposeUIActive { // we try to open watch docs if DD is installed
// we try to open watch docs if lk.IsDockerDesktopActive {
lk.openDDWatchDocs(ctx, project) lk.openDDWatchDocs(ctx, project)
} }
// either way we mark menu/watch as an error // either way we mark menu/watch as an error

View File

@ -66,20 +66,3 @@ func (s *State) Load(ctx context.Context, client *desktop.Client) error {
s.desktopValues = desktopValues s.desktopValues = desktopValues
return nil return nil
} }
func (s *State) NavBar() bool {
return s.determineFeatureState("ComposeNav")
}
func (s *State) ComposeUI() bool {
return s.determineFeatureState("ComposeUIView")
}
func (s *State) determineFeatureState(name string) bool {
if s == nil || !s.active || s.desktopValues == nil {
return false
}
// TODO(milas): we should add individual environment variable overrides
// per-experiment in a generic way here
return s.desktopValues[name].Enabled
}

View File

@ -22,19 +22,16 @@ import (
"go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/attribute"
) )
func KeyboardMetrics(ctx context.Context, enabled, isDockerDesktopActive, isWatchConfigured, isDockerDesktopComposeUI bool) { func KeyboardMetrics(ctx context.Context, enabled, isDockerDesktopActive, isWatchConfigured bool) {
commandAvailable := []string{} commandAvailable := []string{}
if isDockerDesktopActive { if isDockerDesktopActive {
commandAvailable = append(commandAvailable, "gui") commandAvailable = append(commandAvailable, "gui")
commandAvailable = append(commandAvailable, "gui/composeview")
} }
if isWatchConfigured { if isWatchConfigured {
commandAvailable = append(commandAvailable, "watch") commandAvailable = append(commandAvailable, "watch")
} }
if isDockerDesktopComposeUI {
commandAvailable = append(commandAvailable, "gui/composeview")
}
AddAttributeToSpan(ctx, AddAttributeToSpan(ctx,
attribute.Bool("navmenu.enabled", enabled), attribute.Bool("navmenu.enabled", enabled),
attribute.StringSlice("navmenu.command_available", commandAvailable)) attribute.StringSlice("navmenu.command_available", commandAvailable))

View File

@ -324,10 +324,3 @@ func (s *composeService) RuntimeVersion(ctx context.Context) (string, error) {
func (s *composeService) isDesktopIntegrationActive() bool { func (s *composeService) isDesktopIntegrationActive() bool {
return s.desktopCli != nil return s.desktopCli != nil
} }
func (s *composeService) isDesktopUIEnabled() bool {
if !s.isDesktopIntegrationActive() {
return false
}
return s.experiments.ComposeUI()
}

View File

@ -98,10 +98,9 @@ func (s *composeService) Up(ctx context.Context, project *types.Project, options
defer keyboard.Close() //nolint:errcheck defer keyboard.Close() //nolint:errcheck
isWatchConfigured := s.shouldWatch(project) isWatchConfigured := s.shouldWatch(project)
isDockerDesktopActive := s.isDesktopIntegrationActive() isDockerDesktopActive := s.isDesktopIntegrationActive()
isDockerDesktopComposeUI := s.isDesktopUIEnabled() tracing.KeyboardMetrics(ctx, options.Start.NavigationMenu, isDockerDesktopActive, isWatchConfigured)
tracing.KeyboardMetrics(ctx, options.Start.NavigationMenu, isDockerDesktopActive, isWatchConfigured, isDockerDesktopComposeUI)
formatter.NewKeyboardManager(ctx, isDockerDesktopActive, isWatchConfigured, isDockerDesktopComposeUI, signalChan, s.watch) formatter.NewKeyboardManager(ctx, isDockerDesktopActive, isWatchConfigured, signalChan, s.watch)
if options.Start.Watch { if options.Start.Watch {
formatter.KeyboardManager.StartWatch(ctx, doneCh, project, options) formatter.KeyboardManager.StartWatch(ctx, doneCh, project, options)
} }