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()
|
||||
|
21
main.go
21
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 {
|
||||
|
Loading…
Reference in New Issue
Block a user