diff --git a/cmd/compose/compose.go b/cmd/compose/compose.go index 7a33d7b7e..7ebaa0cac 100644 --- a/cmd/compose/compose.go +++ b/cmd/compose/compose.go @@ -535,7 +535,7 @@ func RootCommand(dockerCli command.Cli, backendOptions *BackendOptions) *cobra.C ep = ui.NewPlainWriter(dockerCli.Err()) case ui.ModeQuiet, "none": ui.Mode = ui.ModeQuiet - ep = ui.NewQuiedWriter() + ep = ui.NewQuietWriter() case ui.ModeJSON: ui.Mode = ui.ModeJSON logrus.SetFormatter(&logrus.JSONFormatter{}) diff --git a/pkg/compose/compose.go b/pkg/compose/compose.go index 97843051b..d475d9a94 100644 --- a/pkg/compose/compose.go +++ b/pkg/compose/compose.go @@ -96,7 +96,7 @@ func NewComposeService(dockerCli command.Cli, options ...Option) (api.Compose, e } } if s.events == nil { - s.events = progress.NewQuiedWriter() + s.events = progress.NewQuietWriter() } // If custom streams were provided, wrap the Docker CLI to use them diff --git a/pkg/compose/up.go b/pkg/compose/up.go index 2b29a3da2..40d866d8a 100644 --- a/pkg/compose/up.go +++ b/pkg/compose/up.go @@ -128,12 +128,10 @@ func (s *composeService) Up(ctx context.Context, project *types.Project, options first = false fmt.Println("Gracefully Stopping... press Ctrl+C again to force") eg.Go(func() error { - err := progress.RunWithLog(context.WithoutCancel(globalCtx), func(c context.Context) error { - return s.stop(c, project.Name, api.StopOptions{ - Services: options.Create.Services, - Project: project, - }, printer.HandleEvent) - }, "stop", s.events, logConsumer) + err = s.stop(context.WithoutCancel(globalCtx), project.Name, api.StopOptions{ + Services: options.Create.Services, + Project: project, + }, printer.HandleEvent) appendErr(err) return nil }) @@ -209,12 +207,10 @@ func (s *composeService) Up(ctx context.Context, project *types.Project, options exitCode = event.ExitCode _, _ = fmt.Fprintln(s.stdinfo(), progress.ErrorColor("Aborting on container exit...")) eg.Go(func() error { - err := progress.RunWithLog(context.WithoutCancel(globalCtx), func(c context.Context) error { - return s.stop(c, project.Name, api.StopOptions{ - Services: options.Create.Services, - Project: project, - }, printer.HandleEvent) - }, "stop", s.events, logConsumer) + err = s.stop(context.WithoutCancel(globalCtx), project.Name, api.StopOptions{ + Services: options.Create.Services, + Project: project, + }, printer.HandleEvent) appendErr(err) return nil }) diff --git a/pkg/progress/progress.go b/pkg/progress/progress.go index 049ddeec5..e7cc9af5d 100644 --- a/pkg/progress/progress.go +++ b/pkg/progress/progress.go @@ -18,17 +18,10 @@ package progress import ( "context" - - "github.com/docker/compose/v2/pkg/api" ) type progressFunc func(context.Context) error -func RunWithLog(ctx context.Context, pf progressFunc, operation string, bus EventProcessor, logConsumer api.LogConsumer) error { - // FIXME(ndeloof) re-implement support for logs during stop sequence - return pf(ctx) -} - func Run(ctx context.Context, pf progressFunc, operation string, bus EventProcessor) error { bus.Start(ctx, operation) err := pf(ctx) diff --git a/pkg/progress/quiet.go b/pkg/progress/quiet.go index 7db987e78..31d146db9 100644 --- a/pkg/progress/quiet.go +++ b/pkg/progress/quiet.go @@ -18,7 +18,7 @@ package progress import "context" -func NewQuiedWriter() EventProcessor { +func NewQuietWriter() EventProcessor { return &quiet{} } diff --git a/pkg/progress/tty.go b/pkg/progress/tty.go index 16e5b0d7e..382fef7a0 100644 --- a/pkg/progress/tty.go +++ b/pkg/progress/tty.go @@ -54,7 +54,7 @@ type ttyWriter struct { mtx *sync.Mutex dryRun bool // FIXME(ndeloof) (re)implement support for dry-run skipChildEvents bool - title string + operation string ticker *time.Ticker } @@ -83,7 +83,7 @@ func (t *task) hasMore() { func (w *ttyWriter) Start(ctx context.Context, operation string) { w.ticker = time.NewTicker(100 * time.Millisecond) - w.title = operation + w.operation = operation go func() { for { select { @@ -95,7 +95,7 @@ func (w *ttyWriter) Start(ctx context.Context, operation string) { w.print() w.mtx.Lock() w.ticker.Stop() - w.title = "" + w.operation = "" w.mtx.Unlock() return case <-w.ticker.C: @@ -113,6 +113,10 @@ func (w *ttyWriter) On(events ...Event) { w.mtx.Lock() defer w.mtx.Unlock() for _, e := range events { + if w.operation != "start" && (e.StatusText == "Started" || e.StatusText == "Starting") { + // skip those events to avoid mix with container logs + continue + } w.event(e) } } @@ -171,7 +175,7 @@ func (w *ttyWriter) event(e Event) { } func (w *ttyWriter) printEvent(e Event) { - if w.title != "" { + if w.operation != "" { // event will be displayed by progress UI on ticker's ticks return } @@ -213,7 +217,7 @@ func (w *ttyWriter) print() { //nolint:gocyclo _, _ = fmt.Fprint(w.out, aec.Show) }() - firstLine := fmt.Sprintf("[+] %s %d/%d", w.title, numDone(w.tasks), len(w.tasks)) + firstLine := fmt.Sprintf("[+] %s %d/%d", w.operation, numDone(w.tasks), len(w.tasks)) if w.numLines != 0 && numDone(w.tasks) == w.numLines { firstLine = DoneColor(firstLine) }