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