mirror of
https://github.com/docker/compose.git
synced 2025-07-27 23:54:04 +02:00
simplification
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
parent
559a51e590
commit
7cea455c4d
@ -33,7 +33,6 @@ import (
|
|||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"go.opentelemetry.io/otel"
|
"go.opentelemetry.io/otel"
|
||||||
"go.opentelemetry.io/otel/propagation"
|
"go.opentelemetry.io/otel/propagation"
|
||||||
"golang.org/x/sync/errgroup"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type JsonMessage struct {
|
type JsonMessage struct {
|
||||||
@ -75,23 +74,6 @@ 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) {
|
func (s *composeService) executePlugin(ctx context.Context, cmd *exec.Cmd, command string, service types.ServiceConfig) (types.Mapping, error) {
|
||||||
eg := errgroup.Group{}
|
|
||||||
stdout, err := cmd.StdoutPipe()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = cmd.Start()
|
|
||||||
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)
|
pw := progress.ContextWriter(ctx)
|
||||||
var action string
|
var action string
|
||||||
switch command {
|
switch command {
|
||||||
@ -104,6 +86,22 @@ func (s *composeService) executePlugin(ctx context.Context, cmd *exec.Cmd, comma
|
|||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("unsupported plugin command: %s", command)
|
return nil, fmt.Errorf("unsupported plugin command: %s", command)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stdout, err := cmd.StdoutPipe()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = cmd.Start()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
decoder := json.NewDecoder(stdout)
|
||||||
|
defer func() { _ = stdout.Close() }()
|
||||||
|
|
||||||
|
variables := types.Mapping{}
|
||||||
|
|
||||||
for {
|
for {
|
||||||
var msg JsonMessage
|
var msg JsonMessage
|
||||||
err = decoder.Decode(&msg)
|
err = decoder.Decode(&msg)
|
||||||
@ -130,10 +128,10 @@ func (s *composeService) executePlugin(ctx context.Context, cmd *exec.Cmd, comma
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err = eg.Wait()
|
err = cmd.Wait()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
pw.Event(progress.ErrorMessageEvent(service.Name, err.Error()))
|
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 {
|
switch command {
|
||||||
case "up":
|
case "up":
|
||||||
|
Loading…
x
Reference in New Issue
Block a user