execute all build in definition, fix parallel building deadlock
This commit is contained in:
parent
e0b9c1d74e
commit
37861599bc
@ -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()
|
||||
|
15
main.go
15
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,23 +49,27 @@ 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++ {
|
||||
wait.Wait()
|
||||
close(errors)
|
||||
for err := range errors {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for _, cmd := range buildCommands {
|
||||
err = cmd.Run()
|
||||
|
Loading…
Reference in New Issue
Block a user