Skip to content
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
32 changes: 15 additions & 17 deletions pkg/compose/plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import (
"github.com/spf13/cobra"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/propagation"
"golang.org/x/sync/errgroup"
)

type JsonMessage struct {
Expand Down Expand Up @@ -75,7 +74,19 @@ func (s *composeService) runPlugin(ctx context.Context, project *types.Project,
}

func (s *composeService) executePlugin(ctx context.Context, cmd *exec.Cmd, command string, service types.ServiceConfig) (types.Mapping, error) {
eg := errgroup.Group{}
pw := progress.ContextWriter(ctx)
var action string
switch command {
case "up":
pw.Event(progress.CreatingEvent(service.Name))
action = "create"
case "down":
pw.Event(progress.RemovingEvent(service.Name))
action = "remove"
default:
return nil, fmt.Errorf("unsupported plugin command: %s", command)
}

stdout, err := cmd.StdoutPipe()
if err != nil {
return nil, err
Expand All @@ -85,25 +96,12 @@ func (s *composeService) executePlugin(ctx context.Context, cmd *exec.Cmd, comma
if err != nil {
return nil, err
}
eg.Go(cmd.Wait)

decoder := json.NewDecoder(stdout)
defer func() { _ = stdout.Close() }()

variables := types.Mapping{}

pw := progress.ContextWriter(ctx)
var action string
switch command {
case "up":
pw.Event(progress.CreatingEvent(service.Name))
action = "create"
case "down":
pw.Event(progress.RemovingEvent(service.Name))
action = "remove"
default:
return nil, fmt.Errorf("unsupported plugin command: %s", command)
}
for {
var msg JsonMessage
err = decoder.Decode(&msg)
Expand All @@ -130,10 +128,10 @@ func (s *composeService) executePlugin(ctx context.Context, cmd *exec.Cmd, comma
}
}

err = eg.Wait()
err = cmd.Wait()
if err != nil {
pw.Event(progress.ErrorMessageEvent(service.Name, err.Error()))
return nil, fmt.Errorf("failed to %s external service: %s", action, err.Error())
return nil, fmt.Errorf("failed to %s service provider: %s", action, err.Error())
}
switch command {
case "up":
Expand Down