buildx-manager/buildx/build.go

53 lines
1.2 KiB
Go
Raw Normal View History

2024-10-04 23:43:59 +00:00
package buildx
import (
"path/filepath"
"git.tek.govt.hu/dowerx/buildx-manager/config"
)
func RepoToCommands(repo *Repository) ([]Command, error) {
cfg := config.GetConfig()
workdir, err := filepath.Abs(repo.Path)
if err != nil {
return nil, err
}
globalArgs := make([]string, 0)
for _, arg := range repo.GlobalArguments {
globalArgs = append(globalArgs, "--build-arg", arg.Key+"="+arg.Value)
}
commands := make([]Command, 0)
// builds
for _, build := range repo.Builds {
id := uid()
cmd := Command{Program: cfg.DockerExecutable, Arguments: []string{"buildx", "build", "-f", build.Dockerfile, "--platform", "linux/" + build.Architecture, "--tag", id, cfg.Action}, WorkingDirectory: workdir}
// args
cmd.Arguments = append(cmd.Arguments, globalArgs...)
for _, arg := range build.Arguments {
cmd.Arguments = append(cmd.Arguments, "--build-arg", arg.Key+"="+arg.Value)
}
// tags
for _, tag := range build.Tags {
addUniqueTag(id, repo.Library+"/"+tag)
}
commands = append(commands, cmd)
}
// tags
for _, rtag := range repo.Tags {
for _, tag := range rtag.Tags {
addGroupTag(repo.Library+"/"+rtag.Name, repo.Library+"/"+tag)
}
}
return commands, err
}