buildx-manager/main.go
2024-10-05 01:43:59 +02:00

89 lines
1.4 KiB
Go

package main
import (
"fmt"
"time"
"git.tek.govt.hu/dowerx/buildx-manager/buildx"
"git.tek.govt.hu/dowerx/buildx-manager/config"
"github.com/sanity-io/litter"
"golang.org/x/exp/rand"
)
func main() {
rand.Seed(uint64(time.Now().Unix()))
cfg := config.GetConfig()
job, err := buildx.LoadJob(cfg.File)
if err != nil {
panic(err)
}
buildCommands := make([]buildx.Command, 0)
for _, repo := range job.Repositories {
cmd, err := buildx.RepoToCommands(&repo)
if err != nil {
panic(err)
}
buildCommands = append(buildCommands, cmd...)
}
tagCommands := buildx.TagsToCommands(job.Registries)
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 {
errors := make(chan error)
// start builds
for _, cmd := range buildCommands {
go func() {
errors <- cmd.Run()
}()
}
// wait for builds
for i := 0; i < len(buildCommands); i++ {
for err := range errors {
if err != nil {
panic(err)
}
}
}
} 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)
}
}
}