From 0712c25bc89627a0040e2f24aaf097363214f4a4 Mon Sep 17 00:00:00 2001 From: Shiming Zhang Date: Thu, 20 Jun 2024 13:18:35 +0800 Subject: [PATCH] Update alias of domain --- cmd/crproxy/main.go | 4 ++-- crproxy.go | 3 ++- sync.go | 4 +++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/cmd/crproxy/main.go b/cmd/crproxy/main.go index e0dbe59..9359e1d 100644 --- a/cmd/crproxy/main.go +++ b/cmd/crproxy/main.go @@ -135,10 +135,10 @@ func main() { }), crproxy.WithPathInfoModifyFunc(func(info *crproxy.ImageInfo) *crproxy.ImageInfo { // docker.io/busybox => docker.io/library/busybox - if info.Host == "registry-1.docker.io" && !strings.Contains(info.Name, "/") { + if info.Host == "docker.io" && !strings.Contains(info.Name, "/") { info.Name = "library/" + info.Name } - if info.Host == "registry.ollama.ai" && !strings.Contains(info.Name, "/") { + if info.Host == "ollama.ai" && !strings.Contains(info.Name, "/") { info.Name = "library/" + info.Name } return info diff --git a/crproxy.go b/crproxy.go index 5f791a6..ad6ddaa 100644 --- a/crproxy.go +++ b/crproxy.go @@ -475,7 +475,6 @@ func (c *CRProxy) ServeHTTP(rw http.ResponseWriter, r *http.Request) { errcode.ServeJSON(rw, errcode.ErrorCodeDenied) return } - info.Host = c.getDomainAlias(info.Host) if c.modify != nil { n := c.modify(&ImageInfo{ @@ -498,6 +497,8 @@ func (c *CRProxy) ServeHTTP(rw http.ResponseWriter, r *http.Request) { return } + info.Host = c.getDomainAlias(info.Host) + if info.TagsList && c.disableTagsList { emptyTagsList(rw, r) return diff --git a/sync.go b/sync.go index bbdef70..044dd76 100644 --- a/sync.go +++ b/sync.go @@ -94,7 +94,6 @@ func (c *CRProxy) SyncImageLayer(ctx context.Context, image string, filter func( host := reference.Domain(named) - host = c.getDomainAlias(host) var name reference.Named info := &ImageInfo{ @@ -116,6 +115,9 @@ func (c *CRProxy) SyncImageLayer(ctx context.Context, image string, filter func( } } + host = c.getDomainAlias(host) + info.Host = host + err = c.ping(host) if err != nil { return err