mirror of
https://github.com/docker/compose.git
synced 2026-08-31 23:03:55 +00:00
skip Start[ed|ing] events to avpd mix with container logs
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
parent
fd4f2f99cf
commit
7e3993bcac
6 changed files with 20 additions and 27 deletions
|
|
@ -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{})
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
})
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ package progress
|
|||
|
||||
import "context"
|
||||
|
||||
func NewQuiedWriter() EventProcessor {
|
||||
func NewQuietWriter() EventProcessor {
|
||||
return &quiet{}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue