diff --git a/buildx/command.go b/buildx/command.go index 4619925..9430bec 100644 --- a/buildx/command.go +++ b/buildx/command.go @@ -19,12 +19,12 @@ func (c *Command) Run() error { cmd := exec.Command(c.Program, c.Arguments...) cmd.Dir = c.WorkingDirectory + fmt.Println("running command:") + litter.Dump(c) + if config.GetConfig().Verbose { cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr - - fmt.Println("running command:") - litter.Dump(c) } return cmd.Run() diff --git a/main.go b/main.go index fe3208b..a4b087e 100644 --- a/main.go +++ b/main.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "sync" "git.tek.govt.hu/dowerx/buildx-manager/buildx" "git.tek.govt.hu/dowerx/buildx-manager/config" @@ -20,10 +21,12 @@ func main() { var tagCommands []buildx.Command for _, repo := range job.Repositories { - buildCommands, tagCommands, err = buildx.RepoToCommands(&repo, job.Registries) + bcmd, tcmd, err := buildx.RepoToCommands(&repo, job.Registries) if err != nil { panic(err) } + buildCommands = append(buildCommands, bcmd...) + tagCommands = append(tagCommands, tcmd...) } if cfg.Verbose { @@ -46,21 +49,25 @@ func main() { // build if cfg.Parallel { - errors := make(chan error) + errors := make(chan error, len(buildCommands)) + + var wait sync.WaitGroup // start builds for _, cmd := range buildCommands { + wait.Add(1) go func() { errors <- cmd.Run() + wait.Done() }() } // wait for builds - for i := 0; i < len(buildCommands); i++ { - for err := range errors { - if err != nil { - panic(err) - } + wait.Wait() + close(errors) + for err := range errors { + if err != nil { + panic(err) } } } else {