1
0
Fork 0
mirror of https://github.com/imjasonh/kontain.me synced 2026-07-08 00:55:14 +00:00

Support pull by digest, for images that have previously been built

This commit is contained in:
Jason Hall 2019-05-24 15:54:38 +02:00
parent e9b607a2f7
commit 7f6572d0a2
4 changed files with 53 additions and 33 deletions

View file

@ -71,10 +71,15 @@ func (s *server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
switch {
case path == "": // API Version check.
w.Header().Set("Docker-Distribution-API-Version", "registry/2.0")
case strings.Contains(path, "/blobs/"),
strings.Contains(path, "/manifests/sha256:"):
// Extract requested blob digest and redirect to serve it from GCS.
// If it doesn't exist, this will return 404.
parts := strings.Split(r.URL.Path, "/")
digest := parts[len(parts)-1]
serve.Blob(w, r, digest)
case strings.Contains(path, "/manifests/"):
s.serveBuildpackManifest(w, r)
case strings.Contains(path, "/blobs/"):
serve.Blob(w, r)
default:
serve.Error(w, serve.ErrNotFound)
}
@ -149,7 +154,7 @@ func (s *server) serveBuildpackManifest(w http.ResponseWriter, r *http.Request)
}
// Serve the manifest.
serve.Manifest(w, img)
serve.Manifest(w, r, img)
}
type cachedManifest struct {

View file

@ -59,10 +59,15 @@ func (s *server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// API Version check.
w.Header().Set("Docker-Distribution-API-Version", "registry/2.0")
return
case strings.HasPrefix(path, "ko/") && strings.Contains(path, "/manifests/"):
case strings.Contains(path, "/blobs/"),
strings.Contains(path, "/manifests/sha256:"):
// Extract requested blob digest and redirect to serve it from GCS.
// If it doesn't exist, this will return 404.
parts := strings.Split(r.URL.Path, "/")
digest := parts[len(parts)-1]
serve.Blob(w, r, digest)
case strings.Contains(path, "/manifests/"):
s.serveKoManifest(w, r)
case strings.HasPrefix(path, "ko/") && strings.Contains(path, "/blobs/"):
serve.Blob(w, r)
default:
serve.Error(w, serve.ErrNotFound)
}
@ -119,5 +124,5 @@ func (s *server) serveKoManifest(w http.ResponseWriter, r *http.Request) {
serve.Error(w, serve.ErrInvalid)
return
}
serve.Manifest(w, img)
serve.Manifest(w, r, img)
}

View file

@ -42,10 +42,15 @@ func (s *server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// API Version check.
w.Header().Set("Docker-Distribution-API-Version", "registry/2.0")
return
case strings.Contains(path, "/blobs/"),
strings.Contains(path, "/manifests/sha256:"):
// Extract requested blob digest and redirect to serve it from GCS.
// If it doesn't exist, this will return 404.
parts := strings.Split(r.URL.Path, "/")
digest := parts[len(parts)-1]
serve.Blob(w, r, digest)
case strings.Contains(path, "/manifests/"):
s.serveRandomManifest(w, r)
case strings.Contains(path, "/blobs/"):
serve.Blob(w, r)
default:
serve.Error(w, serve.ErrNotFound)
}
@ -77,5 +82,5 @@ func (s *server) serveRandomManifest(w http.ResponseWriter, r *http.Request) {
serve.Error(w, err)
return
}
serve.Manifest(w, img)
serve.Manifest(w, r, img)
}