@@ -29,7 +29,6 @@ import (
2929
3030 "github.com/compose-spec/compose-go/types"
3131 "github.com/docker/cli/cli"
32- "github.com/sirupsen/logrus"
3332 "github.com/spf13/cobra"
3433 "golang.org/x/sync/errgroup"
3534
@@ -275,13 +274,12 @@ func runCreateStart(ctx context.Context, backend compose.Service, opts upOptions
275274 return nil
276275 }
277276
278- queue := make (chan compose.ContainerEvent )
279- printer := printer {
280- queue : queue ,
281- }
277+ consumer := formatter .NewLogConsumer (ctx , os .Stdout , ! opts .noColor , ! opts .noPrefix )
278+ printer := compose .NewLogPrinter (consumer )
282279
283280 signalChan := make (chan os.Signal , 1 )
284281 signal .Notify (signalChan , syscall .SIGINT , syscall .SIGTERM )
282+
285283 stopFunc := func () error {
286284 ctx := context .Background ()
287285 _ , err := progress .Run (ctx , func (ctx context.Context ) (string , error ) {
@@ -296,27 +294,21 @@ func runCreateStart(ctx context.Context, backend compose.Service, opts upOptions
296294 }
297295 go func () {
298296 <- signalChan
299- queue <- compose.ContainerEvent {
300- Type : compose .UserCancel ,
301- }
297+ printer .Cancel ()
302298 fmt .Println ("Gracefully stopping... (press Ctrl+C again to force)" )
303299 stopFunc () // nolint:errcheck
304300 }()
305301
306- consumer := formatter .NewLogConsumer (ctx , os .Stdout , ! opts .noColor , ! opts .noPrefix )
307-
308302 var exitCode int
309303 eg , ctx := errgroup .WithContext (ctx )
310304 eg .Go (func () error {
311- code , err := printer .run (opts .cascadeStop , opts .exitCodeFrom , consumer , stopFunc )
305+ code , err := printer .Run (opts .cascadeStop , opts .exitCodeFrom , stopFunc )
312306 exitCode = code
313307 return err
314308 })
315309
316310 err = backend .Start (ctx , project , compose.StartOptions {
317- Attach : func (event compose.ContainerEvent ) {
318- queue <- event
319- },
311+ Attach : printer .HandleEvent ,
320312 Services : services ,
321313 })
322314 if err != nil {
@@ -341,11 +333,7 @@ func setServiceScale(project *types.Project, name string, replicas int) error {
341333 if err != nil {
342334 return err
343335 }
344- if service .Deploy == nil {
345- service .Deploy = & types.DeployConfig {}
346- }
347- count := uint64 (replicas )
348- service .Deploy .Replicas = & count
336+ service .Scale = replicas
349337 project .Services [i ] = service
350338 return nil
351339 }
@@ -392,49 +380,3 @@ func setup(opts composeOptions, services []string) (*types.Project, error) {
392380
393381 return project , nil
394382}
395-
396- type printer struct {
397- queue chan compose.ContainerEvent
398- }
399-
400- func (p printer ) run (cascadeStop bool , exitCodeFrom string , consumer compose.LogConsumer , stopFn func () error ) (int , error ) {
401- var aborting bool
402- var count int
403- for {
404- event := <- p .queue
405- switch event .Type {
406- case compose .UserCancel :
407- aborting = true
408- case compose .ContainerEventAttach :
409- consumer .Register (event .Container )
410- count ++
411- case compose .ContainerEventExit :
412- if ! aborting {
413- consumer .Status (event .Container , fmt .Sprintf ("exited with code %d" , event .ExitCode ))
414- }
415- if cascadeStop {
416- if ! aborting {
417- aborting = true
418- fmt .Println ("Aborting on container exit..." )
419- err := stopFn ()
420- if err != nil {
421- return 0 , err
422- }
423- }
424- if exitCodeFrom == "" || exitCodeFrom == event .Service {
425- logrus .Error (event .ExitCode )
426- return event .ExitCode , nil
427- }
428- }
429- count --
430- if count == 0 {
431- // Last container terminated, done
432- return 0 , nil
433- }
434- case compose .ContainerEventLog :
435- if ! aborting {
436- consumer .Log (event .Container , event .Service , event .Line )
437- }
438- }
439- }
440- }
0 commit comments