feat: add ability to customize the registry repo with a template

This commit is contained in:
Jose Diaz-Gonzalez
2024-01-19 06:20:43 -05:00
parent ea28367689
commit 214dc9b69a
5 changed files with 67 additions and 15 deletions

View File

@@ -1,16 +1,42 @@
package registry
import (
"bytes"
"errors"
"fmt"
"os"
"strconv"
"strings"
"text/template"
"github.com/codeskyblue/go-sh"
"github.com/dokku/dokku/plugins/common"
)
func getImageRepoFromTemplate(appName string) (string, error) {
imageRepoTemplate := common.PropertyGet("registry", "--global", "image-repo-template")
if imageRepoTemplate == "" {
return "", nil
}
tmpl, err := template.New("template").Parse(imageRepoTemplate)
if err != nil {
return "", fmt.Errorf("Unable to parse image-repo-template: %w", err)
}
type templateData struct {
AppName string
}
data := templateData{AppName: appName}
var doc bytes.Buffer
if err := tmpl.Execute(&doc, data); err != nil {
return "", fmt.Errorf("Unable to execute image-repo-template: %w", err)
}
return strings.TrimSpace(doc.String()), nil
}
func getRegistryServerForApp(appName string) string {
value := common.PropertyGet("registry", appName, "server")
if value == "" {