buildx-manager/buildx/build.go

63 lines
1.7 KiB
Go
Raw Permalink Normal View History

2024-10-04 23:43:59 +00:00
package buildx
import (
"path/filepath"
"git.tek.govt.hu/dowerx/buildx-manager/config"
)
2024-10-05 09:39:40 +00:00
func RepoToCommands(repo *Repository, registries []string) ([]Command, []Command, error) {
2024-10-04 23:43:59 +00:00
cfg := config.GetConfig()
workdir, err := filepath.Abs(repo.Path)
if err != nil {
2024-10-05 09:39:40 +00:00
return nil, nil, err
2024-10-04 23:43:59 +00:00
}
globalArgs := make([]string, 0)
for _, arg := range repo.GlobalArguments {
globalArgs = append(globalArgs, "--build-arg", arg.Key+"="+arg.Value)
}
2024-10-05 09:39:40 +00:00
buildCommands := make([]Command, 0)
2024-10-04 23:43:59 +00:00
// builds
for _, build := range repo.Builds {
2024-10-05 09:39:40 +00:00
cmd := Command{Program: cfg.DockerExecutable, Arguments: []string{"buildx", "build", "-f", build.Dockerfile, "--platform", "linux/" + build.Architecture, cfg.Action}, WorkingDirectory: workdir}
2024-10-04 23:43:59 +00:00
// 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 {
2024-10-05 09:39:40 +00:00
for _, registry := range registries {
cmd.Arguments = append(cmd.Arguments, "--tag", registry+"/"+repo.Library+"/"+repo.Name+":"+tag)
}
2024-10-04 23:43:59 +00:00
}
2024-10-05 09:39:40 +00:00
cmd.Arguments = append(cmd.Arguments, build.Context)
buildCommands = append(buildCommands, cmd)
2024-10-04 23:43:59 +00:00
}
// tags
2024-10-05 09:39:40 +00:00
tagCommands := make([]Command, 0)
for _, registry := range registries {
for _, groupTag := range repo.Tags {
cmd := Command{Program: cfg.DockerExecutable, Arguments: []string{"buildx", "imagetools", "create", "--tag", registry + "/" + repo.Library + "/" + repo.Name + ":" + groupTag.Name}}
for _, tag := range groupTag.Tags {
cmd.Arguments = append(cmd.Arguments, registry+"/"+repo.Library+"/"+repo.Name+":"+tag)
}
tagCommands = append(tagCommands, cmd)
2024-10-04 23:43:59 +00:00
}
}
2024-10-05 09:39:40 +00:00
return buildCommands, tagCommands, err
2024-10-04 23:43:59 +00:00
}