Skip to content

Commit

Permalink
Remove feature flag integration with Docker Desktop for ComposeUI and…
Browse files Browse the repository at this point in the history
… ComposeNav

Signed-off-by: Joana Hrotko <[email protected]>
  • Loading branch information
jhrotko authored and glours committed Oct 7, 2024
1 parent 82b41b9 commit 407d825
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 45 deletions.
2 changes: 1 addition & 1 deletion cmd/compose/compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ func RootCommand(dockerCli command.Cli, backend Backend) *cobra.Command { //noli
}

c.AddCommand(
upCommand(&opts, dockerCli, backend, experiments),
upCommand(&opts, dockerCli, backend),
downCommand(&opts, dockerCli, backend),
startCommand(&opts, dockerCli, backend),
restartCommand(&opts, dockerCli, backend),
Expand Down
15 changes: 10 additions & 5 deletions cmd/compose/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"github.com/compose-spec/compose-go/v2/types"
"github.com/docker/cli/cli/command"
"github.com/docker/compose/v2/cmd/formatter"
"github.com/docker/compose/v2/internal/experimental"
xprogress "github.com/moby/buildkit/util/progress/progressui"
"github.com/spf13/cobra"

Expand Down Expand Up @@ -81,13 +80,19 @@ func (opts upOptions) apply(project *types.Project, services []string) (*types.P
return project, nil
}

func (opts *upOptions) validateNavigationMenu(dockerCli command.Cli, experimentals *experimental.State) {
func (opts *upOptions) validateNavigationMenu(dockerCli command.Cli) {
if !dockerCli.Out().IsTerminal() {
opts.navigationMenu = false
return
}
// If --menu flag was not set
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
}
}

Expand All @@ -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{}
create := createOptions{}
build := buildOptions{ProjectOptions: p}
Expand All @@ -127,7 +132,7 @@ func upCommand(p *ProjectOptions, dockerCli command.Cli, backend api.Service, ex
return errors.New("cannot combine --attach and --attach-dependencies")
}

up.validateNavigationMenu(dockerCli, experiments)
up.validateNavigationMenu(dockerCli)

if !p.All && len(project.Services) == 0 {
return fmt.Errorf("no service selected")
Expand Down
13 changes: 6 additions & 7 deletions cmd/formatter/shortcut.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,14 @@ type LogKeyboard struct {
Watch KeyboardWatch
IsDockerDesktopActive bool
IsWatchConfigured bool
IsDDComposeUIActive bool
logLevel KEYBOARD_LOG_LEVEL
signalChannel chan<- os.Signal
}

var KeyboardManager *LogKeyboard
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,
watchFn func(ctx context.Context,
doneCh chan bool,
Expand All @@ -126,7 +125,6 @@ func NewKeyboardManager(ctx context.Context, isDockerDesktopActive, isWatchConfi
km := LogKeyboard{}
km.IsDockerDesktopActive = isDockerDesktopActive
km.IsWatchConfigured = isWatchConfigured
km.IsDDComposeUIActive = isDockerDesktopConfigActive
km.logLevel = INFO

km.Watch.Watching = false
Expand Down Expand Up @@ -200,9 +198,10 @@ func (lk *LogKeyboard) navigationMenu() string {
if openDDInfo != "" {
openDDUI = navColor(" ")
}
if lk.IsDDComposeUIActive {
if lk.IsDockerDesktopActive {
openDDUI = openDDUI + shortcutKeyColor("o") + navColor(" View Config")
}

var watchInfo string
if openDDInfo != "" || openDDUI != "" {
watchInfo = navColor(" ")
Expand Down Expand Up @@ -246,7 +245,7 @@ func (lk *LogKeyboard) openDockerDesktop(ctx context.Context, project *types.Pro
}

func (lk *LogKeyboard) openDDComposeUI(ctx context.Context, project *types.Project) {
if !lk.IsDDComposeUIActive {
if !lk.IsDockerDesktopActive {
return
}
eg.Go(tracing.EventWrapFuncForErrGroup(ctx, "menu/gui/composeview", tracing.SpanOptions{},
Expand Down Expand Up @@ -319,8 +318,8 @@ func (lk *LogKeyboard) HandleKeyEvents(event keyboard.KeyEvent, ctx context.Cont
lk.openDockerDesktop(ctx, project)
case 'w':
if !lk.IsWatchConfigured {
if lk.IsDDComposeUIActive {
// we try to open watch docs
// we try to open watch docs if DD is installed
if lk.IsDockerDesktopActive {
lk.openDDWatchDocs(ctx, project)
}
// either way we mark menu/watch as an error
Expand Down
17 changes: 0 additions & 17 deletions internal/experimental/experimental.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,3 @@ func (s *State) Load(ctx context.Context, client *desktop.Client) error {
s.desktopValues = desktopValues
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
}
7 changes: 2 additions & 5 deletions internal/tracing/keyboard_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,16 @@ import (
"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{}
if isDockerDesktopActive {
commandAvailable = append(commandAvailable, "gui")
commandAvailable = append(commandAvailable, "gui/composeview")
}
if isWatchConfigured {
commandAvailable = append(commandAvailable, "watch")
}

if isDockerDesktopComposeUI {
commandAvailable = append(commandAvailable, "gui/composeview")
}

AddAttributeToSpan(ctx,
attribute.Bool("navmenu.enabled", enabled),
attribute.StringSlice("navmenu.command_available", commandAvailable))
Expand Down
7 changes: 0 additions & 7 deletions pkg/compose/compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,10 +324,3 @@ func (s *composeService) RuntimeVersion(ctx context.Context) (string, error) {
func (s *composeService) isDesktopIntegrationActive() bool {
return s.desktopCli != nil
}

func (s *composeService) isDesktopUIEnabled() bool {
if !s.isDesktopIntegrationActive() {
return false
}
return s.experiments.ComposeUI()
}
5 changes: 2 additions & 3 deletions pkg/compose/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,9 @@ func (s *composeService) Up(ctx context.Context, project *types.Project, options
defer keyboard.Close() //nolint:errcheck
isWatchConfigured := s.shouldWatch(project)
isDockerDesktopActive := s.isDesktopIntegrationActive()
isDockerDesktopComposeUI := s.isDesktopUIEnabled()
tracing.KeyboardMetrics(ctx, options.Start.NavigationMenu, isDockerDesktopActive, isWatchConfigured, isDockerDesktopComposeUI)
tracing.KeyboardMetrics(ctx, options.Start.NavigationMenu, isDockerDesktopActive, isWatchConfigured)

formatter.NewKeyboardManager(ctx, isDockerDesktopActive, isWatchConfigured, isDockerDesktopComposeUI, signalChan, s.watch)
formatter.NewKeyboardManager(ctx, isDockerDesktopActive, isWatchConfigured, signalChan, s.watch)
if options.Start.Watch {
formatter.KeyboardManager.StartWatch(ctx, doneCh, project, options)
}
Expand Down

0 comments on commit 407d825

Please sign in to comment.