From 9caf29a19af0fe638f484f53d3bef52ac38894ba Mon Sep 17 00:00:00 2001 From: Simon Date: Sun, 23 Jun 2024 20:00:06 +0200 Subject: [PATCH] Allow to change the registry defaults via environment variables --- types/model/name.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/types/model/name.go b/types/model/name.go index e645a844..54430e6f 100644 --- a/types/model/name.go +++ b/types/model/name.go @@ -7,6 +7,7 @@ import ( "errors" "fmt" "log/slog" + "os" "path/filepath" "strings" ) @@ -34,12 +35,25 @@ func Unqualified(n Name) error { // spot in logs. const MissingPart = "!MISSING!" -const ( +var ( defaultHost = "registry.ollama.ai" defaultNamespace = "library" defaultTag = "latest" ) +func init() { + // Overwrite default Host/Namespace/Tag if they are set in the env + if host := os.Getenv("REGISTRY_DEFAULT_HOST"); host != "" { + defaultHost = host + } + if namespace := os.Getenv("REGISTRY_DEFAULT_NAMESPACE"); namespace != "" { + defaultNamespace = namespace + } + if tag := os.Getenv("REGISTRY_DEFAULT_TAG"); tag != "" { + defaultTag = tag + } +} + // DefaultName returns a name with the default values for the host, namespace, // and tag parts. The model and digest parts are empty. //