From bf5ba6065b6984ea4ccbf6fa68587a15bc395e25 Mon Sep 17 00:00:00 2001 From: Michael Yang Date: Tue, 13 Feb 2024 16:34:55 -0800 Subject: [PATCH] migrate registry domain --- docs/api.md | 2 +- server/modelpath.go | 34 +++++++++++++++++++++++++++++++++- server/routes.go | 7 +++++++ 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/docs/api.md b/docs/api.md index c577bb1a5..816496729 100644 --- a/docs/api.md +++ b/docs/api.md @@ -468,7 +468,7 @@ curl http://localhost:11434/api/chat -d '{ ```json { - "model": "registry.ollama.ai/library/llama3:latest", + "model": "ollama.com/library/llama3:latest", "created_at": "2023-12-12T14:13:43.416799Z", "message": { "role": "assistant", diff --git a/server/modelpath.go b/server/modelpath.go index 92911542a..39f42305f 100644 --- a/server/modelpath.go +++ b/server/modelpath.go @@ -3,6 +3,8 @@ package server import ( "errors" "fmt" + "io/fs" + "log/slog" "net/url" "os" "path/filepath" @@ -21,7 +23,7 @@ type ModelPath struct { } const ( - DefaultRegistry = "registry.ollama.ai" + DefaultRegistry = "ollama.com" DefaultNamespace = "library" DefaultTag = "latest" DefaultProtocolScheme = "https" @@ -151,3 +153,33 @@ func GetBlobsPath(digest string) (string, error) { return path, nil } + +func migrateRegistryDomain() error { + manifests, err := GetManifestPath() + if err != nil { + return err + } + + olddomainpath := filepath.Join(manifests, "registry.ollama.ai") + newdomainpath := filepath.Join(manifests, DefaultRegistry) + + return filepath.Walk(olddomainpath, func(path string, info fs.FileInfo, err error) error { + if err != nil { + return err + } + + if !info.IsDir() { + slog.Info("migrating registry domain", "path", path) + newpath := filepath.Join(newdomainpath, strings.TrimPrefix(path, olddomainpath)) + if err := os.MkdirAll(filepath.Dir(newpath), 0o755); err != nil { + return err + } + + if err := os.Rename(path, newpath); err != nil { + return err + } + } + + return nil + }) +} diff --git a/server/routes.go b/server/routes.go index ac6b713a7..00db0f4b4 100644 --- a/server/routes.go +++ b/server/routes.go @@ -1070,6 +1070,13 @@ func Serve(ln net.Listener) error { } } + // migrate registry.ollama.ai to ollama.com + if err := migrateRegistryDomain(); err != nil { + if !errors.Is(err, os.ErrNotExist) { + return err + } + } + ctx, done := context.WithCancel(context.Background()) schedCtx, schedDone := context.WithCancel(ctx) sched := InitScheduler(schedCtx)