2024-10-04 23:43:59 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2024-11-01 20:13:51 +00:00
|
|
|
"sync"
|
2024-10-04 23:43:59 +00:00
|
|
|
|
|
|
|
"git.tek.govt.hu/dowerx/buildx-manager/buildx"
|
|
|
|
"git.tek.govt.hu/dowerx/buildx-manager/config"
|
|
|
|
"github.com/sanity-io/litter"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
cfg := config.GetConfig()
|
|
|
|
|
|
|
|
job, err := buildx.LoadJob(cfg.File)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2024-10-05 09:39:40 +00:00
|
|
|
var buildCommands []buildx.Command
|
|
|
|
var tagCommands []buildx.Command
|
2024-10-04 23:43:59 +00:00
|
|
|
|
|
|
|
for _, repo := range job.Repositories {
|
2024-11-01 20:13:51 +00:00
|
|
|
bcmd, tcmd, err := buildx.RepoToCommands(&repo, job.Registries)
|
2024-10-04 23:43:59 +00:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2024-11-01 20:13:51 +00:00
|
|
|
buildCommands = append(buildCommands, bcmd...)
|
|
|
|
tagCommands = append(tagCommands, tcmd...)
|
2024-10-04 23:43:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if cfg.Verbose {
|
|
|
|
fmt.Println("config:")
|
|
|
|
litter.Dump(cfg)
|
|
|
|
|
|
|
|
fmt.Println("\njob loaded:")
|
|
|
|
litter.Dump(job)
|
|
|
|
|
|
|
|
fmt.Println("\nbuild commands:", len(buildCommands))
|
|
|
|
litter.Dump(buildCommands)
|
|
|
|
|
|
|
|
fmt.Println("\ntag commands:", len(tagCommands))
|
|
|
|
litter.Dump(tagCommands)
|
|
|
|
}
|
|
|
|
|
|
|
|
if cfg.Dryrun {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// build
|
|
|
|
if cfg.Parallel {
|
2024-11-01 20:13:51 +00:00
|
|
|
errors := make(chan error, len(buildCommands))
|
|
|
|
|
|
|
|
var wait sync.WaitGroup
|
2024-10-04 23:43:59 +00:00
|
|
|
|
|
|
|
// start builds
|
|
|
|
for _, cmd := range buildCommands {
|
2024-11-01 20:13:51 +00:00
|
|
|
wait.Add(1)
|
2024-10-04 23:43:59 +00:00
|
|
|
go func() {
|
|
|
|
errors <- cmd.Run()
|
2024-11-01 20:13:51 +00:00
|
|
|
wait.Done()
|
2024-10-04 23:43:59 +00:00
|
|
|
}()
|
|
|
|
}
|
|
|
|
|
|
|
|
// wait for builds
|
2024-11-01 20:13:51 +00:00
|
|
|
wait.Wait()
|
|
|
|
close(errors)
|
|
|
|
for err := range errors {
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
2024-10-04 23:43:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for _, cmd := range buildCommands {
|
|
|
|
err = cmd.Run()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// tag
|
|
|
|
for _, cmd := range tagCommands {
|
|
|
|
err = cmd.Run()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|