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 := exec.Command(c.Program, c.Arguments...)
|
||||||
cmd.Dir = c.WorkingDirectory
|
cmd.Dir = c.WorkingDirectory
|
||||||
|
|
||||||
|
fmt.Println("running command:")
|
||||||
|
litter.Dump(c)
|
||||||
|
|
||||||
if config.GetConfig().Verbose {
|
if config.GetConfig().Verbose {
|
||||||
cmd.Stdout = os.Stdout
|
cmd.Stdout = os.Stdout
|
||||||
cmd.Stderr = os.Stderr
|
cmd.Stderr = os.Stderr
|
||||||
|
|
||||||
fmt.Println("running command:")
|
|
||||||
litter.Dump(c)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return cmd.Run()
|
return cmd.Run()
|
||||||
|
15
main.go
15
main.go
@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"git.tek.govt.hu/dowerx/buildx-manager/buildx"
|
"git.tek.govt.hu/dowerx/buildx-manager/buildx"
|
||||||
"git.tek.govt.hu/dowerx/buildx-manager/config"
|
"git.tek.govt.hu/dowerx/buildx-manager/config"
|
||||||
@ -20,10 +21,12 @@ func main() {
|
|||||||
var tagCommands []buildx.Command
|
var tagCommands []buildx.Command
|
||||||
|
|
||||||
for _, repo := range job.Repositories {
|
for _, repo := range job.Repositories {
|
||||||
buildCommands, tagCommands, err = buildx.RepoToCommands(&repo, job.Registries)
|
bcmd, tcmd, err := buildx.RepoToCommands(&repo, job.Registries)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
buildCommands = append(buildCommands, bcmd...)
|
||||||
|
tagCommands = append(tagCommands, tcmd...)
|
||||||
}
|
}
|
||||||
|
|
||||||
if cfg.Verbose {
|
if cfg.Verbose {
|
||||||
@ -46,23 +49,27 @@ func main() {
|
|||||||
|
|
||||||
// build
|
// build
|
||||||
if cfg.Parallel {
|
if cfg.Parallel {
|
||||||
errors := make(chan error)
|
errors := make(chan error, len(buildCommands))
|
||||||
|
|
||||||
|
var wait sync.WaitGroup
|
||||||
|
|
||||||
// start builds
|
// start builds
|
||||||
for _, cmd := range buildCommands {
|
for _, cmd := range buildCommands {
|
||||||
|
wait.Add(1)
|
||||||
go func() {
|
go func() {
|
||||||
errors <- cmd.Run()
|
errors <- cmd.Run()
|
||||||
|
wait.Done()
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
// wait for builds
|
// wait for builds
|
||||||
for i := 0; i < len(buildCommands); i++ {
|
wait.Wait()
|
||||||
|
close(errors)
|
||||||
for err := range errors {
|
for err := range errors {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
for _, cmd := range buildCommands {
|
for _, cmd := range buildCommands {
|
||||||
err = cmd.Run()
|
err = cmd.Run()
|
||||||
|
Loading…
Reference in New Issue
Block a user