@@ -49,6 +49,7 @@ type upOptions struct {
4949 forceRecreate bool
5050 noRecreate bool
5151 noStart bool
52+ cascadeStop bool
5253}
5354
5455func (o upOptions ) recreateStrategy () string {
@@ -73,6 +74,9 @@ func upCommand(p *projectOptions, contextType string) *cobra.Command {
7374 RunE : func (cmd * cobra.Command , args []string ) error {
7475 switch contextType {
7576 case store .LocalContextType , store .DefaultContextType , store .EcsLocalSimulationContextType :
77+ if opts .cascadeStop && opts .Detach {
78+ return fmt .Errorf ("--abort-on-container-exit and --detach are incompatible" )
79+ }
7680 if opts .forceRecreate && opts .noRecreate {
7781 return fmt .Errorf ("--force-recreate and --no-recreate are incompatible" )
7882 }
@@ -95,6 +99,7 @@ func upCommand(p *projectOptions, contextType string) *cobra.Command {
9599 flags .BoolVar (& opts .forceRecreate , "force-recreate" , false , "Recreate containers even if their configuration and image haven't changed." )
96100 flags .BoolVar (& opts .noRecreate , "no-recreate" , false , "If containers already exist, don't recreate them. Incompatible with --force-recreate." )
97101 flags .BoolVar (& opts .noStart , "no-start" , false , "Don't start the services after creating them." )
102+ flags .BoolVar (& opts .cascadeStop , "abort-on-container-exit" , false , "Stops all containers if any container was stopped. Incompatible with -d" )
98103 }
99104
100105 return upCmd
@@ -145,9 +150,25 @@ func runCreateStart(ctx context.Context, opts upOptions, services []string) erro
145150 return nil
146151 }
147152
153+ ctx , cancel := context .WithCancel (ctx )
154+ listener := make (chan compose.Event )
155+ go func () {
156+ var aborting bool
157+ for {
158+ <- listener
159+ if opts .cascadeStop && ! aborting {
160+ aborting = true
161+ fmt .Println ("Aborting on container exit..." )
162+ cancel ()
163+ }
164+ }
165+ }()
166+
148167 err = c .ComposeService ().Start (ctx , project , compose.StartOptions {
149- Attach : formatter .NewLogConsumer (ctx , os .Stdout ),
168+ Attach : formatter .NewLogConsumer (ctx , os .Stdout ),
169+ Listener : listener ,
150170 })
171+
151172 if errors .Is (ctx .Err (), context .Canceled ) {
152173 fmt .Println ("Gracefully stopping..." )
153174 ctx = context .Background ()
0 commit comments