Implement path spec for manifest storage

This commit is contained in:
Stephen J Day 2014-11-21 17:04:35 -08:00
parent e158e3cd65
commit 4bbabc6e36
2 changed files with 28 additions and 7 deletions

View file

@ -24,7 +24,7 @@ const storagePathVersion = "v2"
// <root>/v2 // <root>/v2
// -> repositories/ // -> repositories/
// -><name>/ // -><name>/
// -> images/ // -> manifests/
// <manifests by tag name> // <manifests by tag name>
// -> layers/ // -> layers/
// -> tarsum/ // -> tarsum/
@ -48,6 +48,7 @@ const storagePathVersion = "v2"
// //
// We cover the path formats implemented by this path mapper below. // We cover the path formats implemented by this path mapper below.
// //
// manifestPathSpec: <root>/v2/repositories/<name>/manifests/<tag>
// layerLinkPathSpec: <root>/v2/repositories/<name>/layers/tarsum/<tarsum version>/<tarsum hash alg>/<tarsum hash> // layerLinkPathSpec: <root>/v2/repositories/<name>/layers/tarsum/<tarsum version>/<tarsum hash alg>/<tarsum hash>
// layerIndexLinkPathSpec: <root>/v2/layerindex/tarsum/<tarsum version>/<tarsum hash alg>/<tarsum hash> // layerIndexLinkPathSpec: <root>/v2/layerindex/tarsum/<tarsum version>/<tarsum hash alg>/<tarsum hash>
// blobPathSpec: <root>/v2/blob/sha256/<first two hex bytes of digest>/<hex digest> // blobPathSpec: <root>/v2/blob/sha256/<first two hex bytes of digest>/<hex digest>
@ -84,7 +85,13 @@ func (pm *pathMapper) path(spec pathSpec) (string, error) {
// to an intermediate path object, than can be consumed and mapped by the // to an intermediate path object, than can be consumed and mapped by the
// other version. // other version.
rootPrefix := []string{pm.root, pm.version}
repoPrefix := append(rootPrefix, "repositories")
switch v := spec.(type) { switch v := spec.(type) {
case manifestPathSpec:
// TODO(sday): May need to store manifest by architecture.
return path.Join(append(repoPrefix, v.name, "manifests", v.tag)...), nil
case layerLinkPathSpec: case layerLinkPathSpec:
if !strings.HasPrefix(v.digest.Algorithm(), "tarsum") { if !strings.HasPrefix(v.digest.Algorithm(), "tarsum") {
// Only tarsum is supported, for now // Only tarsum is supported, for now
@ -101,9 +108,8 @@ func (pm *pathMapper) path(spec pathSpec) (string, error) {
return "", err return "", err
} }
p := path.Join(append([]string{pm.root, pm.version, "repositories", v.name, "layers"}, tarSumInfoPathComponents(tsi)...)...) return path.Join(append(append(repoPrefix, v.name, "layers"),
tarSumInfoPathComponents(tsi)...)...), nil
return p, nil
case layerIndexLinkPathSpec: case layerIndexLinkPathSpec:
if !strings.HasPrefix(v.digest.Algorithm(), "tarsum") { if !strings.HasPrefix(v.digest.Algorithm(), "tarsum") {
// Only tarsum is supported, for now // Only tarsum is supported, for now
@ -120,9 +126,8 @@ func (pm *pathMapper) path(spec pathSpec) (string, error) {
return "", err return "", err
} }
p := path.Join(append([]string{pm.root, pm.version, "layerindex"}, tarSumInfoPathComponents(tsi)...)...) return path.Join(append(append(rootPrefix, "layerindex"),
tarSumInfoPathComponents(tsi)...)...), nil
return p, nil
case blobPathSpec: case blobPathSpec:
p := path.Join([]string{pm.root, pm.version, "blob", v.alg, v.digest[:2], v.digest}...) p := path.Join([]string{pm.root, pm.version, "blob", v.alg, v.digest[:2], v.digest}...)
return p, nil return p, nil
@ -139,6 +144,15 @@ type pathSpec interface {
pathSpec() pathSpec()
} }
// manifestPathSpec describes the path elements used to build a manifest path.
// The contents should be a signed manifest json file.
type manifestPathSpec struct {
name string
tag string
}
func (manifestPathSpec) pathSpec() {}
// layerLink specifies a path for a layer link, which is a file with a blob // layerLink specifies a path for a layer link, which is a file with a blob
// id. The layer link will contain a content addressable blob id reference // id. The layer link will contain a content addressable blob id reference
// into the blob store. The format of the contents is as follows: // into the blob store. The format of the contents is as follows:

View file

@ -16,6 +16,13 @@ func TestPathMapper(t *testing.T) {
expected string expected string
err error err error
}{ }{
{
spec: manifestPathSpec{
name: "foo/bar",
tag: "thetag",
},
expected: "/pathmapper-test/repositories/foo/bar/manifests/thetag",
},
{ {
spec: layerLinkPathSpec{ spec: layerLinkPathSpec{
name: "foo/bar", name: "foo/bar",