mirror of https://github.com/docker/compose.git
DIsplay progress of starting containers when not attaching to logs (compose up, start)
Signed-off-by: Guillaume Tardif <guillaume.tardif@gmail.com>
This commit is contained in:
parent
7f3db85b11
commit
11950efa77
|
@ -23,7 +23,7 @@ import (
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
"github.com/docker/compose-cli/api/client"
|
"github.com/docker/compose-cli/api/client"
|
||||||
"github.com/docker/compose-cli/api/compose"
|
"github.com/docker/compose-cli/api/progress"
|
||||||
"github.com/docker/compose-cli/cli/formatter"
|
"github.com/docker/compose-cli/cli/formatter"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -54,11 +54,6 @@ func runStart(ctx context.Context, opts startOptions, services []string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
var consumer compose.LogConsumer
|
|
||||||
if !opts.Detach {
|
|
||||||
consumer = formatter.NewLogConsumer(ctx, os.Stdout)
|
|
||||||
}
|
|
||||||
|
|
||||||
project, err := opts.toProject()
|
project, err := opts.toProject()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -69,5 +64,12 @@ func runStart(ctx context.Context, opts startOptions, services []string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.ComposeService().Start(ctx, project, consumer)
|
if opts.Detach {
|
||||||
|
_, err = progress.Run(ctx, func(ctx context.Context) (string, error) {
|
||||||
|
return "", c.ComposeService().Start(ctx, project, nil)
|
||||||
|
})
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.ComposeService().Start(ctx, project, formatter.NewLogConsumer(ctx, os.Stdout))
|
||||||
}
|
}
|
||||||
|
|
|
@ -119,21 +119,27 @@ func runCreateStart(ctx context.Context, opts upOptions, services []string) erro
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = progress.Run(ctx, func(ctx context.Context) (string, error) {
|
_, err = progress.Run(ctx, func(ctx context.Context) (string, error) {
|
||||||
return "", c.ComposeService().Create(ctx, project, compose.CreateOptions{
|
err := c.ComposeService().Create(ctx, project, compose.CreateOptions{
|
||||||
RemoveOrphans: opts.removeOrphans,
|
RemoveOrphans: opts.removeOrphans,
|
||||||
Recreate: opts.recreateStrategy(),
|
Recreate: opts.recreateStrategy(),
|
||||||
})
|
})
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
if opts.Detach {
|
||||||
|
err = c.ComposeService().Start(ctx, project, nil)
|
||||||
|
}
|
||||||
|
return "", err
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
var consumer compose.LogConsumer
|
if opts.Detach {
|
||||||
if !opts.Detach {
|
return nil
|
||||||
consumer = formatter.NewLogConsumer(ctx, os.Stdout)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
err = c.ComposeService().Start(ctx, project, consumer)
|
err = c.ComposeService().Start(ctx, project, formatter.NewLogConsumer(ctx, os.Stdout))
|
||||||
if errors.Is(ctx.Err(), context.Canceled) {
|
if errors.Is(ctx.Err(), context.Canceled) {
|
||||||
fmt.Println("Gracefully stopping...")
|
fmt.Println("Gracefully stopping...")
|
||||||
ctx = context.Background()
|
ctx = context.Background()
|
||||||
|
|
Loading…
Reference in New Issue