63 lines
1.4 KiB
Go
63 lines
1.4 KiB
Go
package buildx
|
|
|
|
import (
|
|
"git.tek.govt.hu/dowerx/buildx-manager/config"
|
|
"golang.org/x/exp/rand"
|
|
)
|
|
|
|
var uniqueTags map[string][]string = make(map[string][]string)
|
|
var groupTags map[string][]string = make(map[string][]string)
|
|
var runes = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
|
|
|
|
func uid() string {
|
|
for {
|
|
id := make([]rune, 16)
|
|
for i := range id {
|
|
id[i] = runes[rand.Intn(len(runes))]
|
|
}
|
|
|
|
_, exists := uniqueTags[string(id)]
|
|
if !exists {
|
|
return string(id)
|
|
}
|
|
}
|
|
}
|
|
|
|
func addUniqueTag(id string, tag string) {
|
|
uniqueTags[id] = append(uniqueTags[id], tag)
|
|
}
|
|
|
|
func addGroupTag(id string, tag string) {
|
|
groupTags[id] = append(groupTags[id], tag)
|
|
}
|
|
|
|
func TagsToCommands(registries []string) []Command {
|
|
cfg := config.GetConfig()
|
|
|
|
commands := make([]Command, 0)
|
|
|
|
for _, registry := range registries {
|
|
|
|
// unique tags
|
|
for id, tags := range uniqueTags {
|
|
for _, tag := range tags {
|
|
cmd := Command{Program: cfg.DockerExecutable, Arguments: []string{"buildx", "imagetools", "create", "-t", registry + "/" + tag, id}}
|
|
commands = append(commands, cmd)
|
|
}
|
|
}
|
|
|
|
// group tags
|
|
for newTag, tags := range groupTags {
|
|
cmd := Command{Program: cfg.DockerExecutable, Arguments: []string{"buildx", "imagetools", "create", "-t", registry + "/" + newTag}}
|
|
|
|
for _, tag := range tags {
|
|
cmd.Arguments = append(cmd.Arguments, registry+"/"+tag)
|
|
}
|
|
|
|
commands = append(commands, cmd)
|
|
}
|
|
}
|
|
|
|
return commands
|
|
}
|