8000 Move manifest to discrete package by stevvooe · Pull Request #21 · distribution/distribution · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Move manifest to discrete package #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 5, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"github.com/docker/distribution/common/testutil"
"github.com/docker/distribution/configuration"
"github.com/docker/distribution/digest"
"github.com/docker/distribution/storage"
"github.com/docker/distribution/manifest"
_ "github.com/docker/distribution/storagedriver/inmemory"
"github.com/docker/libtrust"
"github.com/gorilla/handlers"
Expand Down Expand Up @@ -268,10 +268,10 @@ func TestManifestAPI(t *testing.T) {

// --------------------------------
// Attempt to push unsigned manifest with missing layers
unsignedManifest := &storage.Manifest{
unsignedManifest := &manifest.Manifest{
Name: imageName,
Tag: tag,
FSLayers: []storage.FSLayer{
FSLayers: []manifest.FSLayer{
{
BlobSum: "asdf",
},
Expand Down Expand Up @@ -345,7 +345,7 @@ func TestManifestAPI(t *testing.T) {

// -------------------
// Push the signed manifest with all layers pushed.
signedManifest, err := unsignedManifest.Sign(pk)
signedManifest, err := manifest.Sign(unsignedManifest, pk)
if err != nil {
t.Fatalf("unexpected error signing manifest: %v", err)
}
Expand All @@ -362,7 +362,7 @@ func TestManifestAPI(t *testing.T) {

checkResponse(t, "fetching uploaded manifest", resp, http.StatusOK)

var fetchedManifest storage.SignedManifest
var fetchedManifest manifest.SignedManifest
dec = json.NewDecoder(resp.Body)
if err := dec.Decode(&fetchedManifest); err != nil {
t.Fatalf("error decoding fetched manifest: %v", err)
Expand Down Expand Up @@ -404,7 +404,7 @@ func TestManifestAPI(t *testing.T) {

func putManifest(t *testing.T, msg, url string, v interface{}) *http.Response {
var body []byte
if sm, ok := v.(*storage.SignedManifest); ok {
if sm, ok := v.(*manifest.SignedManifest); ok {
body = sm.Raw
} else {
var err error
Expand Down
12 changes: 6 additions & 6 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ import (

"github.com/docker/distribution/api/v2"
"github.com/docker/distribution/digest"
"github.com/docker/distribution/storage"
"github.com/docker/distribution/manifest"
)

// Client implements the client interface to the registry http api
type Client interface {
// GetImageManifest returns an image manifest for the image at the given
// name, tag pair.
GetImageManifest(name, tag string) (*storage.SignedManifest, error)
GetImageManifest(name, tag string) (*manifest.SignedManifest, error)

// PutImageManifest uploads an image manifest for the image at the given
// name, tag pair.
PutImageManifest(name, tag string, imageManifest *storage.SignedManifest) error
PutImageManifest(name, tag string, imageManifest *manifest.SignedManifest) error

// DeleteImage removes the image at the given name, tag pair.
DeleteImage(name, tag string) error
Expand Down Expand Up @@ -91,7 +91,7 @@ type clientImpl struct {

// TODO(bbland): use consistent route generation between server and client

func (r *clientImpl) GetImageManifest(name, tag string) (*storage.SignedManifest, error) {
func (r *clientImpl) GetImageManifest(name, tag string) (*manifest.SignedManifest, error) {
manifestURL, err := r.ub.BuildManifestURL(name, tag)
if err != nil {
return nil, err
Expand Down Expand Up @@ -124,15 +124,15 @@ func (r *clientImpl) GetImageManifest(name, tag string) (*storage.SignedManifest

decoder := json.NewDecoder(response.Body)

manifest := new(storage.SignedManifest)
manifest := new(manifest.SignedManifest)
err = decoder.Decode(manifest)
if err != nil {
return nil, err
}
return manifest, nil
}

func (r *clientImpl) PutImageManifest(name, tag string, manifest *storage.SignedManifest) error {
func (r *clientImpl) PutImageManifest(name, tag string, manifest *manifest.SignedManifest) error {
manifestURL, err := r.ub.BuildManifestURL(name, tag)
if err != nil {
return err
Expand Down
64 changes: 32 additions & 32 deletions client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

"github.com/docker/distribution/common/testutil"
"github.com/docker/distribution/digest"
"github.com/docker/distribution/storage"
"github.com/docker/distribution/manifest"
)

type testBlob struct {
Expand All @@ -33,33 +33,33 @@ func TestPush(t *testing.T) {
},
}
uploadLocations := make([]string, len(testBlobs))
blobs := make([]storage.FSLayer, len(testBlobs))
history := make([]storage.ManifestHistory, len(testBlobs))
blobs := make([]manifest.FSLayer, len(testBlobs))
history := make([]manifest.History, len(testBlobs))

for i, blob := range testBlobs {
// TODO(bbland): this is returning the same location for all uploads,
// because we can't know which blob will get which location.
// It's sort of okay because we're using unique digests, but this needs
// to change at some point.
uploadLocations[i] = fmt.Sprintf("/v2/%s/blobs/test-uuid", name)
blobs[i] = storage.FSLayer{BlobSum: blob.digest}
history[i] = storage.ManifestHistory{V1Compatibility: blob.digest.String()}
blobs[i] = manifest.FSLayer{BlobSum: blob.digest}
history[i] = manifest.History{V1Compatibility: blob.digest.String()}
}

manifest := &storage.SignedManifest{
Manifest: storage.Manifest{
m := &manifest.SignedManifest{
Manifest: manifest.Manifest{
Name: name,
Tag: tag,
Architecture: "x86",
FSLayers: blobs,
History: history,
Versioned: storage.Versioned{
Versioned: manifest.Versioned{
SchemaVersion: 1,
},
},
}
var err error
manifest.Raw, err = json.Marshal(manifest)
m.Raw, err = json.Marshal(m)

blobRequestResponseMappings := make([]testutil.RequestResponseMapping, 2*len(testBlobs))
for i, blob := range testBlobs {
Expand Down Expand Up @@ -94,7 +94,7 @@ func TestPush(t *testing.T) {
Request: testutil.Request{
Method: "PUT",
Route: "/v2/" + name + "/manifests/" + tag,
Body: manifest.Raw,
Body: m.Raw,
},
Response: testutil.Response{
StatusCode: http.StatusOK,
Expand All @@ -119,7 +119,7 @@ func TestPush(t *testing.T) {
}
objectStore := &memoryObjectStore{
mutex: new(sync.Mutex),
manifestStorage: make(map[string]*storage.SignedManifest),
manifestStorage: make(map[string]*manifest.SignedManifest),
layerStorage: make(map[digest.Digest]Layer),
}

Expand All @@ -139,7 +139,7 @@ func TestPush(t *testing.T) {
writer.Close()
}

objectStore.WriteManifest(name, tag, manifest)
objectStore.WriteManifest(name, tag, m)

err = Push(client, objectStore, name, tag)
if err != nil {
Expand All @@ -160,27 +160,27 @@ func TestPull(t *testing.T) {
contents: []byte("some other contents"),
},
}
blobs := make([]storage.FSLayer, len(testBlobs))
history := make([]storage.ManifestHistory, len(testBlobs))
blobs := make([]manifest.FSLayer, len(testBlobs))
history := make([]manifest.History, len(testBlobs))

for i, blob := range testBlobs {
blobs[i] = storage.FSLayer{BlobSum: blob.digest}
history[i] = storage.ManifestHistory{V1Compatibility: blob.digest.String()}
blobs[i] = manifest.FSLayer{BlobSum: blob.digest}
history[i] = manifest.History{V1Compatibility: blob.digest.String()}
}

manifest := &storage.SignedManifest{
Manifest: storage.Manifest{
m := &manifest.SignedManifest{
Manifest: manifest.Manifest{
Name: name,
Tag: tag,
Architecture: "x86",
FSLayers: blobs,
History: history,
Versioned: storage.Versioned{
Versioned: manifest.Versioned{
SchemaVersion: 1,
},
},
}
manifestBytes, err := json.Marshal(manifest)
manifestBytes, err := json.Marshal(m)

blobRequestResponseMappings := make([]testutil.RequestResponseMapping, len(testBlobs))
for i, blob := range testBlobs {
Expand Down Expand Up @@ -213,7 +213,7 @@ func TestPull(t *testing.T) {
}
objectStore := &memoryObjectStore{
mutex: new(sync.Mutex),
manifestStorage: make(map[string]*storage.SignedManifest),
manifestStorage: make(map[string]*manifest.SignedManifest),
layerStorage: make(map[digest.Digest]Layer),
}

Expand All @@ -222,7 +222,7 @@ func TestPull(t *testing.T) {
t.Fatal(err)
}

m, err := objectStore.Manifest(name, tag)
m, err = objectStore.Manifest(name, tag)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -272,25 +272,25 @@ func TestPullResume(t *testing.T) {
contents: []byte("some other contents"),
},
}
layers := make([]storage.FSLayer, len(testBlobs))
history := make([]storage.ManifestHistory, len(testBlobs))
layers := make([]manifest.FSLayer, len(testBlobs))
history := make([]manifest.History, len(testBlobs))

for i, layer := range testBlobs {
layers[i] = storage.FSLayer{BlobSum: layer.digest}
history[i] = storage.ManifestHistory{V1Compatibility: layer.digest.String()}
layers[i] = manifest.FSLayer{BlobSum: layer.digest}
history[i] = manifest.History{V1Compatibility: layer.digest.String()}
}

manifest := &storage.Manifest{
m := &manifest.Manifest{
Name: name,
Tag: tag,
Architecture: "x86",
FSLayers: layers,
History: history,
Versioned: storage.Versioned{
Versioned: manifest.Versioned{
SchemaVersion: 1,
},
}
manifestBytes, err := json.Marshal(manifest)
manifestBytes, err := json.Marshal(m)

layerRequestResponseMappings := make([]testutil.RequestResponseMapping, 2*len(testBlobs))
for i, blob := range testBlobs {
Expand Down Expand Up @@ -340,7 +340,7 @@ func TestPullResume(t *testing.T) {
}
objectStore := &memoryObjectStore{
mutex: new(sync.Mutex),
manifestStorage: make(map[string]*storage.SignedManifest),
manifestStorage: make(map[string]*manifest.SignedManifest),
layerStorage: make(map[digest.Digest]Layer),
}

Expand All @@ -355,12 +355,12 @@ func TestPullResume(t *testing.T) {
t.Fatal(err)
}

m, err := objectStore.Manifest(name, tag)
sm, err := objectStore.Manifest(name, tag)
if err != nil {
t.Fatal(err)
}

mBytes, err := json.Marshal(m)
mBytes, err := json.Marshal(sm)
if err != nil {
t.Fatal(err)
}
Expand Down
12 changes: 6 additions & 6 deletions client/objectstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"sync"

"github.com/docker/distribution/digest"
"github.com/docker/distribution/storage"
"github.com/docker/distribution/manifest"
)

var (
Expand All @@ -26,11 +26,11 @@ var (
type ObjectStore interface {
// Manifest retrieves the image manifest stored at the given repository name
// and tag
Manifest(name, tag string) (*storage.SignedManifest, error)
Manifest(name, tag string) (*manifest.SignedManifest, error)

// WriteManifest stores an image manifest at the given repository name and
// tag
WriteManifest(name, tag string, manifest *storage.SignedManifest) error
WriteManifest(name, tag string, manifest *manifest.SignedManifest) error

// Layer returns a handle to a layer for reading and writing
Layer(dgst digest.Digest) (Layer, error)
Expand Down Expand Up @@ -83,11 +83,11 @@ type LayerWriter interface {
// memoryObjectStore is an in-memory implementation of the ObjectStore interface
type memoryObjectStore struct {
mutex *sync.Mutex
manifestStorage map[string]*storage.SignedManifest
manifestStorage map[string]*manifest.SignedManifest
layerStorage map[digest.Digest]Layer
}

func (objStore *memoryObjectStore) Manifest(name, tag string) (*storage.SignedManifest, error) {
func (objStore *memoryObjectStore) Manifest(name, tag string) (*manifest.SignedManifest, error) {
objStore.mutex.Lock()
defer objStore.mutex.Unlock()

Expand All @@ -98,7 +98,7 @@ func (objStore *memoryObjectStore) Manifest(name, tag string) (*storage.SignedMa
return manifest, nil
}

func (objStore *memoryObjectStore) WriteManifest(name, tag string, manifest *storage.SignedManifest) error {
func (objStore *memoryObjectStore) WriteManifest(name, tag string, manifest *manifest.SignedManifest) error {
objStore.mutex.Lock()
defer objStore.mutex.Unlock()

Expand Down
6 changes: 3 additions & 3 deletions client/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"fmt"
"io"

"github.com/docker/distribution/storage"

log "github.com/Sirupsen/logrus"

"github.com/docker/distribution/manifest"
)

// simultaneousLayerPullWindow is the size of the parallel layer pull window.
Expand Down Expand Up @@ -77,7 +77,7 @@ func Pull(c Client, objectStore ObjectStore, name, tag string) error {
return nil
}

func pullLayer(c Client, objectStore ObjectStore, name string, fsLayer storage.FSLayer) error {
func pullLayer(c Client, objectStore ObjectStore, name string, fsLayer manifest.FSLayer) error {
log.WithField("layer", fsLayer).Info("Pulling layer")

layer, err := objectStore.Layer(fsLayer.BlobSum)
Expand Down
6 changes: 3 additions & 3 deletions client/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import (
"fmt"

log "github.com/Sirupsen/logrus"
"github.com/docker/distribution/storage"
"github.com/docker/distribution/manifest"
)

// simultaneousLayerPushWindow is the size of the parallel layer push window.
// A layer may not be pushed until the layer preceeding it by the length of the
// push window has been successfully pushed.
const simultaneousLayerPushWindow = 4

type pushFunction func(fsLayer storage.FSLayer) error
type pushFunction func(fsLayer manifest.FSLayer) error

// Push implements a client push workflow for the image defined by the given
// name and tag pair, using the given ObjectStore for local manifest and layer
Expand Down Expand Up @@ -71,7 +71,7 @@ func Push(c Client, objectStore ObjectStore, name, tag string) error {
return nil
}

func pushLayer(c Client, objectStore ObjectStore, name string, fsLayer storage.FSLayer) error {
func pushLayer(c Client, objectStore ObjectStore, name string, fsLayer manifest.FSLayer) error {
log.WithField("layer", fsLayer).Info("Pushing layer")

layer, err := objectStore.Layer(fsLayer.BlobSum)
Expand Down
3 changes: 2 additions & 1 deletion images.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/docker/distribution/api/v2"
"github.com/docker/distribution/digest"
"github.com/docker/distribution/manifest"
"github.com/docker/distribution/storage"
"github.com/gorilla/handlers"
)
Expand Down Expand Up @@ -56,7 +57,7 @@ func (imh *imageManifestHandler) PutImageManifest(w http.ResponseWriter, r *http
manifests := imh.services.Manifests()
dec := json.NewDecoder(r.Body)

var manifest storage.SignedManifest
var manifest manifest.SignedManifest
if err := dec.Decode(&manifest); err != nil {
imh.Errors.Push(v2.ErrorCodeManifestInvalid, err)
w.WriteHeader(http.StatusBadRequest)
Expand Down
Loading
0