about summary refs log tree commit diff
path: root/tools
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@google.com>2020-10-27T13·24+0100
committerVincent Ambo <mail@tazj.in>2020-10-27T14·29+0100
commit94570aa83f0ebb9a192ff9d62e14b811457a6284 (patch)
treeea5edbbbe3d1af31774f3ff79ac9a9f64adec8b4 /tools
parentcbbf45b5cb268a605134022d91308e6c57c9d273 (diff)
feat(main): Implement serving of manifests by digest
Modifies the layer serving endpoint to be a generic blob-serving
endpoint that can handle both manifest and layer object "types".

Note that this commit does not yet populate the CAS with any
manifests.
Diffstat (limited to 'tools')
-rw-r--r--tools/nixery/main.go23
1 files changed, 12 insertions, 11 deletions
diff --git a/tools/nixery/main.go b/tools/nixery/main.go
index 573f42767d04..8a6d3c3aedaa 100644
--- a/tools/nixery/main.go
+++ b/tools/nixery/main.go
@@ -53,8 +53,8 @@ var version string = "devel"
 // routes required for serving images, since pushing and other such
 // functionality is not available.
 var (
-	manifestTagRegex = regexp.MustCompile(`^/v2/([\w|\-|\.|\_|\/]+)/manifests/([\w|\-|\.|\_]+)$`)
-	layerRegex       = regexp.MustCompile(`^/v2/([\w|\-|\.|\_|\/]+)/blobs/sha256:(\w+)$`)
+	manifestRegex = regexp.MustCompile(`^/v2/([\w|\-|\.|\_|\/]+)/manifests/([\w|\-|\.|\_]+)$`)
+	blobRegex     = regexp.MustCompile(`^/v2/([\w|\-|\.|\_|\/]+)/(blobs|manifests)/sha256:(\w+)$`)
 )
 
 // Downloads the popularity information for the package set from the
@@ -156,15 +156,16 @@ func (h *registryHandler) serveManifestTag(w http.ResponseWriter, r *http.Reques
 	w.Write(manifest)
 }
 
-// serveLayer serves an image layer from storage (if it exists).
-func (h *registryHandler) serveLayer(w http.ResponseWriter, r *http.Request, digest string) {
+// serveBlob serves a blob from storage by digest
+func (h *registryHandler) serveBlob(w http.ResponseWriter, r *http.Request, blobType, digest string) {
 	storage := h.state.Storage
 	err := storage.Serve(digest, r, w)
 	if err != nil {
 		log.WithError(err).WithFields(log.Fields{
-			"layer":   digest,
+			"type":    blobType,
+			"digest":  digest,
 			"backend": storage.Name(),
-		}).Error("failed to serve layer from storage backend")
+		}).Error("failed to serve blob from storage backend")
 	}
 }
 
@@ -176,16 +177,16 @@ func (h *registryHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
 	}
 
 	// Build & serve a manifest by tag
-	manifestMatches := manifestTagRegex.FindStringSubmatch(r.RequestURI)
+	manifestMatches := manifestRegex.FindStringSubmatch(r.RequestURI)
 	if len(manifestMatches) == 3 {
 		h.serveManifestTag(w, r, manifestMatches[1], manifestMatches[2])
 		return
 	}
 
-	// Serve an image layer
-	layerMatches := layerRegex.FindStringSubmatch(r.RequestURI)
-	if len(layerMatches) == 3 {
-		h.serveLayer(w, r, layerMatches[2])
+	// Serve a blob by digest
+	layerMatches := blobRegex.FindStringSubmatch(r.RequestURI)
+	if len(layerMatches) == 4 {
+		h.serveBlob(w, r, layerMatches[2], layerMatches[3])
 		return
 	}