Skip to content

Add playground session id #113

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 25, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions internal/local_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/docker/docker/client"
"github.com/docker/docker/pkg/stdcopy"
"github.com/ethereum/go-ethereum/log"
"github.com/google/uuid"
"gopkg.in/yaml.v2"
)

Expand Down Expand Up @@ -62,6 +63,10 @@ type LocalRunner struct {

// wether to bind the ports to the local interface
bindHostPortsLocally bool

// sessionID is a random sequence that is used to identify the session
// it is used to identify the containers in the cleanup process
sessionID string
}

type task struct {
Expand Down Expand Up @@ -97,8 +102,6 @@ func NewLocalRunner(out *output, manifest *Manifest, overrides map[string]string
return nil, fmt.Errorf("failed to create docker client: %w", err)
}

fmt.Println(bindHostPortsLocally)

// merge the overrides with the manifest overrides
if overrides == nil {
overrides = make(map[string]string)
Expand Down Expand Up @@ -149,6 +152,7 @@ func NewLocalRunner(out *output, manifest *Manifest, overrides map[string]string
taskUpdateCh: make(chan struct{}),
exitErr: make(chan error, 2),
bindHostPortsLocally: bindHostPortsLocally,
sessionID: uuid.New().String(),
}

if interactive {
Expand Down Expand Up @@ -295,8 +299,9 @@ func (d *LocalRunner) ExitErr() <-chan error {
}

func (d *LocalRunner) Stop() error {
// only stop the containers that belong to this session
containers, err := d.client.ContainerList(context.Background(), container.ListOptions{
Filters: filters.NewArgs(filters.Arg("label", "playground=true")),
Filters: filters.NewArgs(filters.Arg("label", fmt.Sprintf("playground.session=%s", d.sessionID))),
})
if err != nil {
return fmt.Errorf("error getting container list: %w", err)
Expand Down Expand Up @@ -518,8 +523,9 @@ func (d *LocalRunner) toDockerComposeService(s *service) (map[string]interface{}
labels := map[string]string{
// It is important to use the playground label to identify the containers
// during the cleanup process
"playground": "true",
"service": s.Name,
"playground": "true",
"playground.session": d.sessionID,
"service": s.Name,
}

// add the local ports exposed by the service as labels
Expand Down Expand Up @@ -722,7 +728,7 @@ func (d *LocalRunner) trackLogs(serviceName string, containerID string) error {

func (d *LocalRunner) trackContainerStatusAndLogs() {
eventCh, errCh := d.client.Events(context.Background(), events.ListOptions{
Filters: filters.NewArgs(filters.Arg("label", "playground=true")),
Filters: filters.NewArgs(filters.Arg("label", fmt.Sprintf("playground.session=%s", d.sessionID))),
})

for {
Expand Down