This repository was archived by the owner on Apr 29, 2024. It is now read-only.
forked from distribution/distribution
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add reference types support to distribution.
Co-authored-by: Tejaswini Duggaraju <[email protected]> Co-authored-by: Akash Singhal <[email protected]> Co-authored-by: Aviral Takkar <[email protected]>
- Loading branch information
1 parent
985711c
commit 142317d
Showing
29 changed files
with
1,970 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
version: 0.1 | ||
log: | ||
fields: | ||
service: registry | ||
storage: | ||
cache: | ||
blobdescriptor: inmemory | ||
filesystem: | ||
rootdirectory: /opt/data/registry-root-dir | ||
http: | ||
addr: :5000 | ||
headers: | ||
X-Content-Type-Options: [nosniff] | ||
health: | ||
storagedriver: | ||
enabled: true | ||
interval: 10s | ||
threshold: 3 | ||
# Configuration for extensions. It follows the below schema | ||
# extensions | ||
# namespace: | ||
# configuration for the extension and its components in any schema specific to that namespace | ||
extensions: | ||
oci: | ||
ext: | ||
- discover # enable the discovery extension | ||
artifacts: | ||
- referrers | ||
# "distribution" is the namespace | ||
distribution: | ||
# "registry" is the extension under the namespace | ||
registry: | ||
# "taghistory" & "manifests" are the components under the extension | ||
- taghistory | ||
- manifests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package v2 | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/distribution/distribution/v3/reference" | ||
) | ||
|
||
// ExtendRoute extends the routes using the template. | ||
// The Name and Path in the template will be re-generated according to | ||
// - Namespace (ns) | ||
// - Extension Name (ext) | ||
// - Component name (component) | ||
// Returns the full route descriptor with Name and Path populated. | ||
// Returns true if the route is successfully extended, or false if route exists. | ||
func ExtendRoute(ns, ext, component string, template RouteDescriptor, nameRequired bool) (RouteDescriptor, bool) { | ||
name := RouteNameExtensionsRegistry | ||
path := routeDescriptorsMap[RouteNameBase].Path | ||
if nameRequired { | ||
name = RouteNameExtensionsRepository | ||
path += "{name:" + reference.NameRegexp.String() + "}" | ||
} | ||
name = fmt.Sprintf("%s-%s-%s-%s", name, ns, ext, component) | ||
path = fmt.Sprintf("%s/_%s/%s/%s", path, ns, ext, component) | ||
|
||
desc := template | ||
desc.Name = name | ||
desc.Path = path | ||
|
||
if _, exists := routeDescriptorsMap[desc.Name]; exists { | ||
return desc, false | ||
} | ||
|
||
routeDescriptors = append(routeDescriptors, desc) | ||
routeDescriptorsMap[desc.Name] = desc | ||
APIDescriptor.RouteDescriptors = routeDescriptors | ||
|
||
return desc, true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package distribution | ||
|
||
import ( | ||
"encoding/json" | ||
"net/http" | ||
|
||
"github.com/distribution/distribution/v3/registry/api/errcode" | ||
v2 "github.com/distribution/distribution/v3/registry/api/v2" | ||
"github.com/distribution/distribution/v3/registry/extension" | ||
"github.com/distribution/distribution/v3/registry/storage" | ||
"github.com/distribution/distribution/v3/registry/storage/driver" | ||
"github.com/opencontainers/go-digest" | ||
) | ||
|
||
type manifestsGetAPIResponse struct { | ||
Name string `json:"name"` | ||
Digests []digest.Digest `json:"digests"` | ||
} | ||
|
||
// manifestHandler handles requests for manifests under a manifest name. | ||
type manifestHandler struct { | ||
*extension.Context | ||
storageDriver driver.StorageDriver | ||
} | ||
|
||
func (th *manifestHandler) getManifests(w http.ResponseWriter, r *http.Request) { | ||
defer r.Body.Close() | ||
|
||
digests, err := th.manifests() | ||
if err != nil { | ||
switch err := err.(type) { | ||
case driver.PathNotFoundError: | ||
th.Errors = append(th.Errors, v2.ErrorCodeNameUnknown.WithDetail(map[string]string{"name": th.Repository.Named().Name()})) | ||
default: | ||
th.Errors = append(th.Errors, errcode.ErrorCodeUnknown.WithDetail(err)) | ||
} | ||
return | ||
} | ||
|
||
w.Header().Set("Content-Type", "application/json") | ||
|
||
enc := json.NewEncoder(w) | ||
if err := enc.Encode(manifestsGetAPIResponse{ | ||
Name: th.Repository.Named().Name(), | ||
Digests: digests, | ||
}); err != nil { | ||
th.Errors = append(th.Errors, errcode.ErrorCodeUnknown.WithDetail(err)) | ||
return | ||
} | ||
} | ||
|
||
func (th *manifestHandler) manifests() ([]digest.Digest, error) { | ||
manifestLinkStore := storage.GetManifestLinkReadOnlyBlobStore( | ||
th.Context, | ||
th.Repository, | ||
th.storageDriver, | ||
nil, | ||
) | ||
|
||
var dgsts []digest.Digest | ||
err := manifestLinkStore.Enumerate(th.Context, func(dgst digest.Digest) error { | ||
dgsts = append(dgsts, dgst) | ||
return nil | ||
}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return dgsts, nil | ||
} |
Oops, something went wrong.