diff --git a/go.mod b/go.mod index 34dc51483..03c65cc7d 100644 --- a/go.mod +++ b/go.mod @@ -18,6 +18,7 @@ require ( github.com/pkg/browser v0.0.0-20210904010418-6d279e18f982 github.com/spf13/cobra v1.2.1 github.com/spf13/viper v1.8.1 + golang.org/x/sync v0.0.0-20210220032951-036812b2e83c google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c google.golang.org/grpc v1.38.0 google.golang.org/protobuf v1.26.0 diff --git a/go.sum b/go.sum index 613653ac5..0d8196b7d 100644 --- a/go.sum +++ b/go.sum @@ -430,6 +430,7 @@ golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= diff --git a/pkg/plugin/system/BUILD.bazel b/pkg/plugin/system/BUILD.bazel index c7b63dc31..4a3f41a61 100644 --- a/pkg/plugin/system/BUILD.bazel +++ b/pkg/plugin/system/BUILD.bazel @@ -15,6 +15,7 @@ go_library( "//pkg/plugin/system/bep", "@com_github_spf13_cobra//:cobra", "@in_gopkg_yaml_v2//:yaml_v2", + "@org_golang_x_sync//errgroup", ], ) diff --git a/pkg/plugin/system/system.go b/pkg/plugin/system/system.go index 90c49433a..d3639ba39 100644 --- a/pkg/plugin/system/system.go +++ b/pkg/plugin/system/system.go @@ -15,9 +15,9 @@ import ( "reflect" "time" - yaml "gopkg.in/yaml.v2" - "github.com/spf13/cobra" + "golang.org/x/sync/errgroup" + yaml "gopkg.in/yaml.v2" rootFlags "aspect.build/cli/pkg/aspect/root/flags" "aspect.build/cli/pkg/aspecterrors" @@ -71,28 +71,32 @@ func (ps *pluginSystem) Configure(streams ioutils.Streams) error { return fmt.Errorf("failed to configure plugin system: %w", err) } + g := new(errgroup.Group) + for _, p := range aspectplugins { - // TODO(f0rmiga): make this loop concurrent so that all plugins are - // configured faster. + p := p - aspectplugin, err := ps.clientFactory.New(p, streams) - if err != nil { - return fmt.Errorf("failed to configure plugin system: %w", err) - } + g.Go(func() error { + aspectplugin, err := ps.clientFactory.New(p, streams) + if err != nil { + return fmt.Errorf("failed to configure plugin system: %w", err) + } - propertiesBytes, err := yaml.Marshal(p.Properties) - if err != nil { - return fmt.Errorf("failed to configure plugin system: %w", err) - } + propertiesBytes, err := yaml.Marshal(p.Properties) + if err != nil { + return fmt.Errorf("failed to configure plugin system: %w", err) + } - if err := aspectplugin.Setup(propertiesBytes); err != nil { - return fmt.Errorf("failed to setup plugin: %w", err) - } + if err := aspectplugin.Setup(propertiesBytes); err != nil { + return fmt.Errorf("failed to configure plugin system: %w", err) + } - ps.addPlugin(aspectplugin) + ps.addPlugin(aspectplugin) + return nil + }) } - return nil + return g.Wait() } func (ps *pluginSystem) addPlugin(plugin *client.PluginInstance) { diff --git a/pkg/plugin/system/system_test.go b/pkg/plugin/system/system_test.go index 7ed5c6927..97f5ad9dd 100644 --- a/pkg/plugin/system/system_test.go +++ b/pkg/plugin/system/system_test.go @@ -532,7 +532,7 @@ func TestConfigure(t *testing.T) { err := ps.Configure(streams) - g.Expect(err).To(MatchError("failed to setup plugin: setup error")) + g.Expect(err).To(MatchError("failed to configure plugin system: setup error")) }) t.Run("marshaled properties are passed to plugin.Setup", func(t *testing.T) {