migrate registry domain

This commit is contained in:
Michael Yang 2024-02-13 16:34:55 -08:00
parent 09c0972a6a
commit bf5ba6065b
3 changed files with 41 additions and 2 deletions

View File

@ -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",

View File

@ -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
})
}

View File

@ -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)