@@ -21,6 +21,7 @@ import (
21
21
"github.com/docker/docker/client"
22
22
"github.com/docker/docker/pkg/stdcopy"
23
23
"github.com/ethereum/go-ethereum/log"
24
+ "github.com/google/uuid"
24
25
"gopkg.in/yaml.v2"
25
26
)
26
27
@@ -62,6 +63,10 @@ type LocalRunner struct {
62
63
63
64
// wether to bind the ports to the local interface
64
65
bindHostPortsLocally bool
66
+
67
+ // sessionID is a random sequence that is used to identify the session
68
+ // it is used to identify the containers in the cleanup process
69
+ sessionID string
65
70
}
66
71
67
72
type task struct {
@@ -97,8 +102,6 @@ func NewLocalRunner(out *output, manifest *Manifest, overrides map[string]string
97
102
return nil , fmt .Errorf ("failed to create docker client: %w" , err )
98
103
}
99
104
100
- fmt .Println (bindHostPortsLocally )
101
-
102
105
// merge the overrides with the manifest overrides
103
106
if overrides == nil {
104
107
overrides = make (map [string ]string )
@@ -149,6 +152,7 @@ func NewLocalRunner(out *output, manifest *Manifest, overrides map[string]string
149
152
taskUpdateCh : make (chan struct {}),
150
153
exitErr : make (chan error , 2 ),
151
154
bindHostPortsLocally : bindHostPortsLocally ,
155
+ sessionID : uuid .New ().String (),
152
156
}
153
157
154
158
if interactive {
@@ -295,8 +299,9 @@ func (d *LocalRunner) ExitErr() <-chan error {
295
299
}
296
300
297
301
func (d * LocalRunner ) Stop () error {
302
+ // only stop the containers that belong to this session
298
303
containers , err := d .client .ContainerList (context .Background (), container.ListOptions {
299
- Filters : filters .NewArgs (filters .Arg ("label" , "playground=true" )),
304
+ Filters : filters .NewArgs (filters .Arg ("label" , fmt . Sprintf ( "playground.session=%s" , d . sessionID ) )),
300
305
})
301
306
if err != nil {
302
307
return fmt .Errorf ("error getting container list: %w" , err )
@@ -518,8 +523,9 @@ func (d *LocalRunner) toDockerComposeService(s *service) (map[string]interface{}
518
523
labels := map [string ]string {
519
524
// It is important to use the playground label to identify the containers
520
525
// during the cleanup process
521
- "playground" : "true" ,
522
- "service" : s .Name ,
526
+ "playground" : "true" ,
527
+ "playground.session" : d .sessionID ,
528
+ "service" : s .Name ,
523
529
}
524
530
525
531
// add the local ports exposed by the service as labels
@@ -722,7 +728,7 @@ func (d *LocalRunner) trackLogs(serviceName string, containerID string) error {
722
728
723
729
func (d * LocalRunner ) trackContainerStatusAndLogs () {
724
730
eventCh , errCh := d .client .Events (context .Background (), events.ListOptions {
725
- Filters : filters .NewArgs (filters .Arg ("label" , "playground=true" )),
731
+ Filters : filters .NewArgs (filters .Arg ("label" , fmt . Sprintf ( "playground.session=%s" , d . sessionID ) )),
726
732
})
727
733
728
734
for {
0 commit comments