Skip to content
This repository was archived by the owner on Nov 27, 2023. It is now read-only.

Commit 11950ef

Browse files
committed
DIsplay progress of starting containers when not attaching to logs (compose up, start)
Signed-off-by: Guillaume Tardif <[email protected]>
1 parent 7f3db85 commit 11950ef

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

cli/cmd/compose/start.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
"github.com/spf13/cobra"
2424

2525
"github.com/docker/compose-cli/api/client"
26-
"github.com/docker/compose-cli/api/compose"
26+
"github.com/docker/compose-cli/api/progress"
2727
"github.com/docker/compose-cli/cli/formatter"
2828
)
2929

@@ -54,11 +54,6 @@ func runStart(ctx context.Context, opts startOptions, services []string) error {
5454
return err
5555
}
5656

57-
var consumer compose.LogConsumer
58-
if !opts.Detach {
59-
consumer = formatter.NewLogConsumer(ctx, os.Stdout)
60-
}
61-
6257
project, err := opts.toProject()
6358
if err != nil {
6459
return err
@@ -69,5 +64,12 @@ func runStart(ctx context.Context, opts startOptions, services []string) error {
6964
return err
7065
}
7166

72-
return c.ComposeService().Start(ctx, project, consumer)
67+
if opts.Detach {
68+
_, err = progress.Run(ctx, func(ctx context.Context) (string, error) {
69+
return "", c.ComposeService().Start(ctx, project, nil)
70+
})
71+
return err
72+
}
73+
74+
return c.ComposeService().Start(ctx, project, formatter.NewLogConsumer(ctx, os.Stdout))
7375
}

cli/cmd/compose/up.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,21 +119,27 @@ func runCreateStart(ctx context.Context, opts upOptions, services []string) erro
119119
}
120120

121121
_, err = progress.Run(ctx, func(ctx context.Context) (string, error) {
122-
return "", c.ComposeService().Create(ctx, project, compose.CreateOptions{
122+
err := c.ComposeService().Create(ctx, project, compose.CreateOptions{
123123
RemoveOrphans: opts.removeOrphans,
124124
Recreate: opts.recreateStrategy(),
125125
})
126+
if err != nil {
127+
return "", err
128+
}
129+
if opts.Detach {
130+
err = c.ComposeService().Start(ctx, project, nil)
131+
}
132+
return "", err
126133
})
127134
if err != nil {
128135
return err
129136
}
130137

131-
var consumer compose.LogConsumer
132-
if !opts.Detach {
133-
consumer = formatter.NewLogConsumer(ctx, os.Stdout)
138+
if opts.Detach {
139+
return nil
134140
}
135141

136-
err = c.ComposeService().Start(ctx, project, consumer)
142+
err = c.ComposeService().Start(ctx, project, formatter.NewLogConsumer(ctx, os.Stdout))
137143
if errors.Is(ctx.Err(), context.Canceled) {
138144
fmt.Println("Gracefully stopping...")
139145
ctx = context.Background()

0 commit comments

Comments
 (0)