From 775c5633effcd9ee6e4124cd4d57893234a0b4d6 Mon Sep 17 00:00:00 2001 From: Stephen J Day Date: Fri, 6 Jan 2017 17:23:18 -0800 Subject: [PATCH] *: use opencontainers/go-digest package The `digest` data type, used throughout docker for image verification and identity, has been broken out into `opencontainers/go-digest`. This PR updates the dependencies and moves uses over to the new type. Signed-off-by: Stephen J Day Upstream-commit: 7a855799175b6b984886ef1cfa337d6df1d4c668 Component: engine --- .../types/reference/image_reference_test.go | 1 + components/engine/cli/command/image/trust.go | 4 ++-- .../engine/cli/command/service/trust.go | 4 ++-- .../engine/cli/compose/schema/bindata.go | 2 +- components/engine/daemon/cluster/cluster.go | 4 ++-- .../engine/daemon/cluster/convert/node.go | 4 ++-- .../cluster/executor/container/adapter.go | 4 ++-- components/engine/daemon/disk_usage.go | 2 +- components/engine/daemon/image_pull.go | 4 ++-- components/engine/daemon/prune.go | 2 +- components/engine/distribution/config.go | 2 +- .../metadata/v2_metadata_service.go | 2 +- .../metadata/v2_metadata_service_test.go | 2 +- components/engine/distribution/pull.go | 2 +- components/engine/distribution/pull_v2.go | 22 +++++-------------- .../engine/distribution/pull_v2_test.go | 2 +- components/engine/distribution/push_v1.go | 2 +- components/engine/distribution/push_v2.go | 4 ++-- .../engine/distribution/push_v2_test.go | 2 +- .../engine/distribution/xfer/download_test.go | 2 +- components/engine/image/fs.go | 2 +- components/engine/image/fs_test.go | 2 +- components/engine/image/image.go | 2 +- components/engine/image/store.go | 9 ++++---- components/engine/image/store_test.go | 2 +- components/engine/image/tarexport/load.go | 2 +- components/engine/image/tarexport/save.go | 2 +- components/engine/image/v1/imagev1.go | 2 +- .../docker_cli_by_digest_test.go | 2 +- .../docker_cli_pull_local_test.go | 2 +- .../integration-cli/docker_cli_pull_test.go | 4 ++-- .../docker_cli_save_load_test.go | 2 +- .../integration-cli/registry/registry.go | 2 +- components/engine/layer/empty_test.go | 4 ++-- components/engine/layer/filestore.go | 8 +++---- components/engine/layer/filestore_test.go | 2 +- components/engine/layer/layer.go | 2 +- components/engine/layer/layer_store.go | 4 ++-- components/engine/layer/layer_test.go | 2 +- components/engine/layer/layer_windows.go | 2 +- components/engine/layer/migration.go | 4 ++-- components/engine/layer/ro_layer.go | 8 ++----- components/engine/migrate/v1/migratev1.go | 8 +++---- .../engine/migrate/v1/migratev1_test.go | 2 +- components/engine/plugin/backend_linux.go | 6 ++--- components/engine/plugin/blobstore.go | 9 ++++---- components/engine/plugin/manager.go | 2 +- components/engine/plugin/manager_linux.go | 2 +- components/engine/plugin/v2/plugin.go | 2 +- components/engine/reference/reference.go | 4 ++-- components/engine/reference/reference_test.go | 2 +- components/engine/reference/store.go | 2 +- components/engine/reference/store_test.go | 2 +- 53 files changed, 86 insertions(+), 99 deletions(-) diff --git a/components/engine/api/types/reference/image_reference_test.go b/components/engine/api/types/reference/image_reference_test.go index 61fb676b6c..2f6268f5bc 100644 --- a/components/engine/api/types/reference/image_reference_test.go +++ b/components/engine/api/types/reference/image_reference_test.go @@ -1,6 +1,7 @@ package reference import ( + _ "crypto/sha256" "testing" ) diff --git a/components/engine/cli/command/image/trust.go b/components/engine/cli/command/image/trust.go index 948e002bf2..58e0574396 100644 --- a/components/engine/cli/command/image/trust.go +++ b/components/engine/cli/command/image/trust.go @@ -10,7 +10,6 @@ import ( "sort" "github.com/Sirupsen/logrus" - "github.com/docker/distribution/digest" "github.com/docker/docker/api/types" "github.com/docker/docker/cli/command" "github.com/docker/docker/cli/trust" @@ -19,6 +18,7 @@ import ( "github.com/docker/docker/registry" "github.com/docker/notary/client" "github.com/docker/notary/tuf/data" + "github.com/opencontainers/go-digest" "golang.org/x/net/context" ) @@ -58,7 +58,7 @@ func PushTrustedReference(cli *command.DockerCli, repoInfo *registry.RepositoryI var pushResult types.PushResult err := json.Unmarshal(*aux, &pushResult) if err == nil && pushResult.Tag != "" { - if dgst, err := digest.ParseDigest(pushResult.Digest); err == nil { + if dgst, err := digest.Parse(pushResult.Digest); err == nil { h, err := hex.DecodeString(dgst.Hex()) if err != nil { target = nil diff --git a/components/engine/cli/command/service/trust.go b/components/engine/cli/command/service/trust.go index 052d49c32a..15f8a708f0 100644 --- a/components/engine/cli/command/service/trust.go +++ b/components/engine/cli/command/service/trust.go @@ -5,7 +5,6 @@ import ( "fmt" "github.com/Sirupsen/logrus" - "github.com/docker/distribution/digest" distreference "github.com/docker/distribution/reference" "github.com/docker/docker/api/types/swarm" "github.com/docker/docker/cli/command" @@ -13,6 +12,7 @@ import ( "github.com/docker/docker/reference" "github.com/docker/docker/registry" "github.com/docker/notary/tuf/data" + "github.com/opencontainers/go-digest" "github.com/pkg/errors" "golang.org/x/net/context" ) @@ -30,7 +30,7 @@ func resolveServiceImageDigest(dockerCli *command.DockerCli, service *swarm.Serv // could be parsed as a digest reference. Specifying an image ID // is valid but not resolvable. There is no warning message for // an image ID because it's valid to use one. - if _, err := digest.ParseDigest(image); err == nil { + if _, err := digest.Parse(image); err == nil { return nil } diff --git a/components/engine/cli/compose/schema/bindata.go b/components/engine/cli/compose/schema/bindata.go index 2acc7d29f1..c3774130b3 100644 --- a/components/engine/cli/compose/schema/bindata.go +++ b/components/engine/cli/compose/schema/bindata.go @@ -182,6 +182,7 @@ type bintree struct { Func func() (*asset, error) Children map[string]*bintree } + var _bintree = &bintree{nil, map[string]*bintree{ "data": &bintree{nil, map[string]*bintree{ "config_schema_v3.0.json": &bintree{dataConfig_schema_v30Json, map[string]*bintree{}}, @@ -234,4 +235,3 @@ func _filePath(dir, name string) string { cannonicalName := strings.Replace(name, "\\", "/", -1) return filepath.Join(append([]string{dir}, strings.Split(cannonicalName, "/")...)...) } - diff --git a/components/engine/daemon/cluster/cluster.go b/components/engine/daemon/cluster/cluster.go index 376897f2c3..d95795a788 100644 --- a/components/engine/daemon/cluster/cluster.go +++ b/components/engine/daemon/cluster/cluster.go @@ -52,7 +52,6 @@ import ( "time" "github.com/Sirupsen/logrus" - "github.com/docker/distribution/digest" distreference "github.com/docker/distribution/reference" apierrors "github.com/docker/docker/api/errors" apitypes "github.com/docker/docker/api/types" @@ -73,6 +72,7 @@ import ( "github.com/docker/swarmkit/manager/encryption" swarmnode "github.com/docker/swarmkit/node" "github.com/docker/swarmkit/protobuf/ptypes" + "github.com/opencontainers/go-digest" "github.com/pkg/errors" "golang.org/x/net/context" ) @@ -832,7 +832,7 @@ func (c *Cluster) GetServices(options apitypes.ServiceListOptions) ([]types.Serv // TODO(nishanttotla): After the packages converge, the function must // convert distreference.Named -> distreference.Canonical, and the logic simplified. func (c *Cluster) imageWithDigestString(ctx context.Context, image string, authConfig *apitypes.AuthConfig) (string, error) { - if _, err := digest.ParseDigest(image); err == nil { + if _, err := digest.Parse(image); err == nil { return "", errors.New("image reference is an image ID") } ref, err := distreference.ParseNamed(image) diff --git a/components/engine/daemon/cluster/convert/node.go b/components/engine/daemon/cluster/convert/node.go index 306f34e0b2..acc7959b58 100644 --- a/components/engine/daemon/cluster/convert/node.go +++ b/components/engine/daemon/cluster/convert/node.go @@ -14,7 +14,7 @@ func NodeFromGRPC(n swarmapi.Node) types.Node { node := types.Node{ ID: n.ID, Spec: types.NodeSpec{ - Role: types.NodeRole(strings.ToLower(n.Spec.Role.String())), + Role: types.NodeRole(strings.ToLower(n.Spec.DesiredRole.String())), Availability: types.NodeAvailability(strings.ToLower(n.Spec.Availability.String())), }, Status: types.NodeStatus{ @@ -74,7 +74,7 @@ func NodeSpecToGRPC(s types.NodeSpec) (swarmapi.NodeSpec, error) { }, } if role, ok := swarmapi.NodeRole_value[strings.ToUpper(string(s.Role))]; ok { - spec.Role = swarmapi.NodeRole(role) + spec.DesiredRole = swarmapi.NodeRole(role) } else { return swarmapi.NodeSpec{}, fmt.Errorf("invalid Role: %q", s.Role) } diff --git a/components/engine/daemon/cluster/executor/container/adapter.go b/components/engine/daemon/cluster/executor/container/adapter.go index dcd13e9165..cafa36bcb3 100644 --- a/components/engine/daemon/cluster/executor/container/adapter.go +++ b/components/engine/daemon/cluster/executor/container/adapter.go @@ -11,7 +11,6 @@ import ( "time" "github.com/Sirupsen/logrus" - "github.com/docker/distribution/digest" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/backend" containertypes "github.com/docker/docker/api/types/container" @@ -24,6 +23,7 @@ import ( "github.com/docker/swarmkit/api" "github.com/docker/swarmkit/log" "github.com/docker/swarmkit/protobuf/ptypes" + "github.com/opencontainers/go-digest" "golang.org/x/net/context" "golang.org/x/time/rate" ) @@ -54,7 +54,7 @@ func (c *containerAdapter) pullImage(ctx context.Context) error { spec := c.container.spec() // Skip pulling if the image is referenced by image ID. - if _, err := digest.ParseDigest(spec.Image); err == nil { + if _, err := digest.Parse(spec.Image); err == nil { return nil } diff --git a/components/engine/daemon/disk_usage.go b/components/engine/daemon/disk_usage.go index c3b918660d..fc77a3d8fd 100644 --- a/components/engine/daemon/disk_usage.go +++ b/components/engine/daemon/disk_usage.go @@ -4,12 +4,12 @@ import ( "fmt" "github.com/Sirupsen/logrus" - "github.com/docker/distribution/digest" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/filters" "github.com/docker/docker/layer" "github.com/docker/docker/pkg/directory" "github.com/docker/docker/volume" + "github.com/opencontainers/go-digest" ) func (daemon *Daemon) getLayerRefs() map[layer.ChainID]int { diff --git a/components/engine/daemon/image_pull.go b/components/engine/daemon/image_pull.go index 2157d15974..f1b5f83c79 100644 --- a/components/engine/daemon/image_pull.go +++ b/components/engine/daemon/image_pull.go @@ -5,7 +5,6 @@ import ( "strings" dist "github.com/docker/distribution" - "github.com/docker/distribution/digest" "github.com/docker/docker/api/types" "github.com/docker/docker/builder" "github.com/docker/docker/distribution" @@ -13,6 +12,7 @@ import ( "github.com/docker/docker/pkg/progress" "github.com/docker/docker/reference" "github.com/docker/docker/registry" + "github.com/opencontainers/go-digest" "golang.org/x/net/context" ) @@ -32,7 +32,7 @@ func (daemon *Daemon) PullImage(ctx context.Context, image, tag string, metaHead if tag != "" { // The "tag" could actually be a digest. var dgst digest.Digest - dgst, err = digest.ParseDigest(tag) + dgst, err = digest.Parse(tag) if err == nil { ref, err = reference.WithDigest(reference.TrimNamed(ref), dgst) } else { diff --git a/components/engine/daemon/prune.go b/components/engine/daemon/prune.go index a693beb4e1..967dd87873 100644 --- a/components/engine/daemon/prune.go +++ b/components/engine/daemon/prune.go @@ -5,7 +5,6 @@ import ( "regexp" "github.com/Sirupsen/logrus" - "github.com/docker/distribution/digest" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/filters" "github.com/docker/docker/image" @@ -15,6 +14,7 @@ import ( "github.com/docker/docker/runconfig" "github.com/docker/docker/volume" "github.com/docker/libnetwork" + "github.com/opencontainers/go-digest" ) // ContainersPrune removes unused containers diff --git a/components/engine/distribution/config.go b/components/engine/distribution/config.go index 78cf0530ca..13ae46e0c5 100644 --- a/components/engine/distribution/config.go +++ b/components/engine/distribution/config.go @@ -7,7 +7,6 @@ import ( "runtime" "github.com/docker/distribution" - "github.com/docker/distribution/digest" "github.com/docker/distribution/manifest/schema2" "github.com/docker/docker/api/types" "github.com/docker/docker/distribution/metadata" @@ -18,6 +17,7 @@ import ( "github.com/docker/docker/reference" "github.com/docker/docker/registry" "github.com/docker/libtrust" + "github.com/opencontainers/go-digest" "golang.org/x/net/context" ) diff --git a/components/engine/distribution/metadata/v2_metadata_service.go b/components/engine/distribution/metadata/v2_metadata_service.go index fc410a46e4..c31c7214e7 100644 --- a/components/engine/distribution/metadata/v2_metadata_service.go +++ b/components/engine/distribution/metadata/v2_metadata_service.go @@ -7,9 +7,9 @@ import ( "encoding/json" "errors" - "github.com/docker/distribution/digest" "github.com/docker/docker/api/types" "github.com/docker/docker/layer" + "github.com/opencontainers/go-digest" ) // V2MetadataService maps layer IDs to a set of known metadata for diff --git a/components/engine/distribution/metadata/v2_metadata_service_test.go b/components/engine/distribution/metadata/v2_metadata_service_test.go index 7b0ecb1572..8e3e4614c0 100644 --- a/components/engine/distribution/metadata/v2_metadata_service_test.go +++ b/components/engine/distribution/metadata/v2_metadata_service_test.go @@ -8,8 +8,8 @@ import ( "reflect" "testing" - "github.com/docker/distribution/digest" "github.com/docker/docker/layer" + "github.com/opencontainers/go-digest" ) func TestV2MetadataService(t *testing.T) { diff --git a/components/engine/distribution/pull.go b/components/engine/distribution/pull.go index 48f4431f6b..ac52ba1fcb 100644 --- a/components/engine/distribution/pull.go +++ b/components/engine/distribution/pull.go @@ -5,12 +5,12 @@ import ( "fmt" "github.com/Sirupsen/logrus" - "github.com/docker/distribution/digest" "github.com/docker/docker/api" "github.com/docker/docker/distribution/metadata" "github.com/docker/docker/pkg/progress" "github.com/docker/docker/reference" "github.com/docker/docker/registry" + "github.com/opencontainers/go-digest" "golang.org/x/net/context" ) diff --git a/components/engine/distribution/pull_v2.go b/components/engine/distribution/pull_v2.go index 88807edc7d..053e81a08f 100644 --- a/components/engine/distribution/pull_v2.go +++ b/components/engine/distribution/pull_v2.go @@ -12,7 +12,6 @@ import ( "github.com/Sirupsen/logrus" "github.com/docker/distribution" - "github.com/docker/distribution/digest" "github.com/docker/distribution/manifest/manifestlist" "github.com/docker/distribution/manifest/schema1" "github.com/docker/distribution/manifest/schema2" @@ -29,6 +28,7 @@ import ( "github.com/docker/docker/pkg/stringid" "github.com/docker/docker/reference" "github.com/docker/docker/registry" + "github.com/opencontainers/go-digest" "golang.org/x/net/context" ) @@ -228,10 +228,7 @@ func (ld *v2LayerDescriptor) Download(ctx context.Context, progressOutput progre defer reader.Close() if ld.verifier == nil { - ld.verifier, err = digest.NewDigestVerifier(ld.digest) - if err != nil { - return nil, 0, xfer.DoNotRetry{Err: err} - } + ld.verifier = ld.digest.Verifier() } _, err = io.Copy(tmpFile, io.TeeReader(reader, ld.verifier)) @@ -716,10 +713,7 @@ func (p *v2Puller) pullSchema2Config(ctx context.Context, dgst digest.Digest) (c } // Verify image config digest - verifier, err := digest.NewDigestVerifier(dgst) - if err != nil { - return nil, err - } + verifier := dgst.Verifier() if _, err := verifier.Write(configJSON); err != nil { return nil, err } @@ -742,10 +736,7 @@ func schema2ManifestDigest(ref reference.Named, mfst distribution.Manifest) (dig // If pull by digest, then verify the manifest digest. if digested, isDigested := ref.(reference.Canonical); isDigested { - verifier, err := digest.NewDigestVerifier(digested.Digest()) - if err != nil { - return "", err - } + verifier := digested.Digest().Verifier() if _, err := verifier.Write(canonical); err != nil { return "", err } @@ -798,10 +789,7 @@ func verifySchema1Manifest(signedManifest *schema1.SignedManifest, ref reference // important to do this first, before any other content validation. If the // digest cannot be verified, don't even bother with those other things. if digested, isCanonical := ref.(reference.Canonical); isCanonical { - verifier, err := digest.NewDigestVerifier(digested.Digest()) - if err != nil { - return nil, err - } + verifier := digested.Digest().Verifier() if _, err := verifier.Write(signedManifest.Canonical); err != nil { return nil, err } diff --git a/components/engine/distribution/pull_v2_test.go b/components/engine/distribution/pull_v2_test.go index b745642e3b..d65653311c 100644 --- a/components/engine/distribution/pull_v2_test.go +++ b/components/engine/distribution/pull_v2_test.go @@ -8,9 +8,9 @@ import ( "strings" "testing" - "github.com/docker/distribution/digest" "github.com/docker/distribution/manifest/schema1" "github.com/docker/docker/reference" + "github.com/opencontainers/go-digest" ) // TestFixManifestLayers checks that fixManifestLayers removes a duplicate diff --git a/components/engine/distribution/push_v1.go b/components/engine/distribution/push_v1.go index 0a12380b5e..beaa9ddbcb 100644 --- a/components/engine/distribution/push_v1.go +++ b/components/engine/distribution/push_v1.go @@ -5,7 +5,6 @@ import ( "sync" "github.com/Sirupsen/logrus" - "github.com/docker/distribution/digest" "github.com/docker/distribution/registry/client/transport" "github.com/docker/docker/distribution/metadata" "github.com/docker/docker/dockerversion" @@ -17,6 +16,7 @@ import ( "github.com/docker/docker/pkg/stringid" "github.com/docker/docker/reference" "github.com/docker/docker/registry" + "github.com/opencontainers/go-digest" "golang.org/x/net/context" ) diff --git a/components/engine/distribution/push_v2.go b/components/engine/distribution/push_v2.go index e56f80065b..f2115b39bc 100644 --- a/components/engine/distribution/push_v2.go +++ b/components/engine/distribution/push_v2.go @@ -13,7 +13,6 @@ import ( "github.com/Sirupsen/logrus" "github.com/docker/distribution" - "github.com/docker/distribution/digest" "github.com/docker/distribution/manifest/schema1" "github.com/docker/distribution/manifest/schema2" distreference "github.com/docker/distribution/reference" @@ -27,6 +26,7 @@ import ( "github.com/docker/docker/pkg/stringid" "github.com/docker/docker/reference" "github.com/docker/docker/registry" + "github.com/opencontainers/go-digest" ) const ( @@ -435,7 +435,7 @@ func (pd *v2PushDescriptor) uploadUsingSession( return distribution.Descriptor{}, fmt.Errorf("unsupported layer media type %s", m) } - digester := digest.Canonical.New() + digester := digest.Canonical.Digester() tee := io.TeeReader(reader, digester.Hash()) nn, err := layerUpload.ReadFrom(tee) diff --git a/components/engine/distribution/push_v2_test.go b/components/engine/distribution/push_v2_test.go index 6a5216b1d0..6aa3722758 100644 --- a/components/engine/distribution/push_v2_test.go +++ b/components/engine/distribution/push_v2_test.go @@ -7,13 +7,13 @@ import ( "github.com/docker/distribution" "github.com/docker/distribution/context" - "github.com/docker/distribution/digest" "github.com/docker/distribution/manifest/schema2" distreference "github.com/docker/distribution/reference" "github.com/docker/docker/distribution/metadata" "github.com/docker/docker/layer" "github.com/docker/docker/pkg/progress" "github.com/docker/docker/reference" + "github.com/opencontainers/go-digest" ) func TestGetRepositoryMountCandidates(t *testing.T) { diff --git a/components/engine/distribution/xfer/download_test.go b/components/engine/distribution/xfer/download_test.go index 0d3af82313..69323bb869 100644 --- a/components/engine/distribution/xfer/download_test.go +++ b/components/engine/distribution/xfer/download_test.go @@ -12,10 +12,10 @@ import ( "time" "github.com/docker/distribution" - "github.com/docker/distribution/digest" "github.com/docker/docker/image" "github.com/docker/docker/layer" "github.com/docker/docker/pkg/progress" + "github.com/opencontainers/go-digest" "golang.org/x/net/context" ) diff --git a/components/engine/image/fs.go b/components/engine/image/fs.go index c37ef4942f..e7d282532a 100644 --- a/components/engine/image/fs.go +++ b/components/engine/image/fs.go @@ -8,8 +8,8 @@ import ( "sync" "github.com/Sirupsen/logrus" - "github.com/docker/distribution/digest" "github.com/docker/docker/pkg/ioutils" + "github.com/opencontainers/go-digest" ) // DigestWalkFunc is function called by StoreBackend.Walk diff --git a/components/engine/image/fs_test.go b/components/engine/image/fs_test.go index 60390b80e6..6555654e13 100644 --- a/components/engine/image/fs_test.go +++ b/components/engine/image/fs_test.go @@ -11,7 +11,7 @@ import ( "path/filepath" "testing" - "github.com/docker/distribution/digest" + "github.com/opencontainers/go-digest" ) func TestFSGetSet(t *testing.T) { diff --git a/components/engine/image/image.go b/components/engine/image/image.go index 3796cf58a8..c008f3e9b4 100644 --- a/components/engine/image/image.go +++ b/components/engine/image/image.go @@ -6,8 +6,8 @@ import ( "io" "time" - "github.com/docker/distribution/digest" "github.com/docker/docker/api/types/container" + "github.com/opencontainers/go-digest" ) // ID is the content-addressable ID of an image. diff --git a/components/engine/image/store.go b/components/engine/image/store.go index b61c456097..26ae109a06 100644 --- a/components/engine/image/store.go +++ b/components/engine/image/store.go @@ -7,8 +7,9 @@ import ( "sync" "github.com/Sirupsen/logrus" - "github.com/docker/distribution/digest" + "github.com/docker/distribution/digestset" "github.com/docker/docker/layer" + "github.com/opencontainers/go-digest" ) // Store is an interface for creating and accessing images @@ -40,7 +41,7 @@ type store struct { ls LayerGetReleaser images map[ID]*imageMeta fs StoreBackend - digestSet *digest.Set + digestSet *digestset.Set } // NewImageStore returns new store object for given layer store @@ -49,7 +50,7 @@ func NewImageStore(fs StoreBackend, ls LayerGetReleaser) (Store, error) { ls: ls, images: make(map[ID]*imageMeta), fs: fs, - digestSet: digest.NewSet(), + digestSet: digestset.NewSet(), } // load all current images and retain layers @@ -170,7 +171,7 @@ func (is *store) Search(term string) (ID, error) { dgst, err := is.digestSet.Lookup(term) if err != nil { - if err == digest.ErrDigestNotFound { + if err == digestset.ErrDigestNotFound { err = fmt.Errorf("No such image: %s", term) } return "", err diff --git a/components/engine/image/store_test.go b/components/engine/image/store_test.go index 50f8aa8b84..e9c2f6d217 100644 --- a/components/engine/image/store_test.go +++ b/components/engine/image/store_test.go @@ -5,8 +5,8 @@ import ( "os" "testing" - "github.com/docker/distribution/digest" "github.com/docker/docker/layer" + "github.com/opencontainers/go-digest" ) func TestRestore(t *testing.T) { diff --git a/components/engine/image/tarexport/load.go b/components/engine/image/tarexport/load.go index 01edd91fb7..f5d3e49cb9 100644 --- a/components/engine/image/tarexport/load.go +++ b/components/engine/image/tarexport/load.go @@ -11,7 +11,6 @@ import ( "github.com/Sirupsen/logrus" "github.com/docker/distribution" - "github.com/docker/distribution/digest" "github.com/docker/docker/image" "github.com/docker/docker/image/v1" "github.com/docker/docker/layer" @@ -23,6 +22,7 @@ import ( "github.com/docker/docker/pkg/symlink" "github.com/docker/docker/pkg/system" "github.com/docker/docker/reference" + "github.com/opencontainers/go-digest" ) func (l *tarexporter) Load(inTar io.ReadCloser, outStream io.Writer, quiet bool) error { diff --git a/components/engine/image/tarexport/save.go b/components/engine/image/tarexport/save.go index 1ae931b8d2..c85b1a2ba5 100644 --- a/components/engine/image/tarexport/save.go +++ b/components/engine/image/tarexport/save.go @@ -10,13 +10,13 @@ import ( "time" "github.com/docker/distribution" - "github.com/docker/distribution/digest" "github.com/docker/docker/image" "github.com/docker/docker/image/v1" "github.com/docker/docker/layer" "github.com/docker/docker/pkg/archive" "github.com/docker/docker/pkg/system" "github.com/docker/docker/reference" + "github.com/opencontainers/go-digest" "github.com/pkg/errors" ) diff --git a/components/engine/image/v1/imagev1.go b/components/engine/image/v1/imagev1.go index b52b447e82..0e8a23cb5d 100644 --- a/components/engine/image/v1/imagev1.go +++ b/components/engine/image/v1/imagev1.go @@ -6,11 +6,11 @@ import ( "strings" "github.com/Sirupsen/logrus" - "github.com/docker/distribution/digest" "github.com/docker/docker/api/types/versions" "github.com/docker/docker/image" "github.com/docker/docker/layer" "github.com/docker/docker/pkg/stringid" + "github.com/opencontainers/go-digest" ) // noFallbackMinVersion is the minimum version for which v1compatibility diff --git a/components/engine/integration-cli/docker_cli_by_digest_test.go b/components/engine/integration-cli/docker_cli_by_digest_test.go index 66a37e8cf4..85cfef43dd 100644 --- a/components/engine/integration-cli/docker_cli_by_digest_test.go +++ b/components/engine/integration-cli/docker_cli_by_digest_test.go @@ -8,13 +8,13 @@ import ( "regexp" "strings" - "github.com/docker/distribution/digest" "github.com/docker/distribution/manifest/schema1" "github.com/docker/distribution/manifest/schema2" "github.com/docker/docker/api/types" "github.com/docker/docker/integration-cli/checker" "github.com/docker/docker/pkg/stringutils" "github.com/go-check/check" + "github.com/opencontainers/go-digest" ) var ( diff --git a/components/engine/integration-cli/docker_cli_pull_local_test.go b/components/engine/integration-cli/docker_cli_pull_local_test.go index b0b6accf06..c39566a587 100644 --- a/components/engine/integration-cli/docker_cli_pull_local_test.go +++ b/components/engine/integration-cli/docker_cli_pull_local_test.go @@ -11,12 +11,12 @@ import ( "strings" "github.com/docker/distribution" - "github.com/docker/distribution/digest" "github.com/docker/distribution/manifest" "github.com/docker/distribution/manifest/manifestlist" "github.com/docker/distribution/manifest/schema2" "github.com/docker/docker/integration-cli/checker" "github.com/go-check/check" + "github.com/opencontainers/go-digest" ) // testPullImageWithAliases pulls a specific image tag and verifies that any aliases (i.e., other diff --git a/components/engine/integration-cli/docker_cli_pull_test.go b/components/engine/integration-cli/docker_cli_pull_test.go index 6fff8e9dbb..40da4c1feb 100644 --- a/components/engine/integration-cli/docker_cli_pull_test.go +++ b/components/engine/integration-cli/docker_cli_pull_test.go @@ -7,9 +7,9 @@ import ( "sync" "time" - "github.com/docker/distribution/digest" "github.com/docker/docker/integration-cli/checker" "github.com/go-check/check" + "github.com/opencontainers/go-digest" ) // TestPullFromCentralRegistry pulls an image from the central registry and verifies that the client @@ -26,7 +26,7 @@ func (s *DockerHubPullSuite) TestPullFromCentralRegistry(c *check.C) { matches := regexp.MustCompile(`Digest: (.+)\n`).FindAllStringSubmatch(out, -1) c.Assert(len(matches), checker.Equals, 1, check.Commentf("expected exactly one image digest in the output")) c.Assert(len(matches[0]), checker.Equals, 2, check.Commentf("unexpected number of submatches for the digest")) - _, err := digest.ParseDigest(matches[0][1]) + _, err := digest.Parse(matches[0][1]) c.Check(err, checker.IsNil, check.Commentf("invalid digest %q in output", matches[0][1])) // We should have a single entry in images. diff --git a/components/engine/integration-cli/docker_cli_save_load_test.go b/components/engine/integration-cli/docker_cli_save_load_test.go index b7d82f74d2..73e19558a2 100644 --- a/components/engine/integration-cli/docker_cli_save_load_test.go +++ b/components/engine/integration-cli/docker_cli_save_load_test.go @@ -13,10 +13,10 @@ import ( "strings" "time" - "github.com/docker/distribution/digest" "github.com/docker/docker/integration-cli/checker" "github.com/docker/docker/pkg/testutil" "github.com/go-check/check" + "github.com/opencontainers/go-digest" ) // save a repo using gz compression and try to load it using stdout diff --git a/components/engine/integration-cli/registry/registry.go b/components/engine/integration-cli/registry/registry.go index 4062734c5c..800fdd1a31 100644 --- a/components/engine/integration-cli/registry/registry.go +++ b/components/engine/integration-cli/registry/registry.go @@ -8,7 +8,7 @@ import ( "os/exec" "path/filepath" - "github.com/docker/distribution/digest" + "github.com/opencontainers/go-digest" ) const ( diff --git a/components/engine/layer/empty_test.go b/components/engine/layer/empty_test.go index c22da7665d..0d8c80c01a 100644 --- a/components/engine/layer/empty_test.go +++ b/components/engine/layer/empty_test.go @@ -4,7 +4,7 @@ import ( "io" "testing" - "github.com/docker/distribution/digest" + "github.com/opencontainers/go-digest" ) func TestEmptyLayer(t *testing.T) { @@ -33,7 +33,7 @@ func TestEmptyLayer(t *testing.T) { t.Fatalf("error streaming tar for empty layer: %v", err) } - digester := digest.Canonical.New() + digester := digest.Canonical.Digester() _, err = io.Copy(digester.Hash(), tarStream) if err != nil { diff --git a/components/engine/layer/filestore.go b/components/engine/layer/filestore.go index 42b45556e3..7ea418cd5a 100644 --- a/components/engine/layer/filestore.go +++ b/components/engine/layer/filestore.go @@ -15,8 +15,8 @@ import ( "github.com/Sirupsen/logrus" "github.com/docker/distribution" - "github.com/docker/distribution/digest" "github.com/docker/docker/pkg/ioutils" + "github.com/opencontainers/go-digest" ) var ( @@ -165,7 +165,7 @@ func (fms *fileMetadataStore) GetParent(layer ChainID) (ChainID, error) { return "", err } - dgst, err := digest.ParseDigest(strings.TrimSpace(string(content))) + dgst, err := digest.Parse(strings.TrimSpace(string(content))) if err != nil { return "", err } @@ -179,7 +179,7 @@ func (fms *fileMetadataStore) GetDiffID(layer ChainID) (DiffID, error) { return "", err } - dgst, err := digest.ParseDigest(strings.TrimSpace(string(content))) + dgst, err := digest.Parse(strings.TrimSpace(string(content))) if err != nil { return "", err } @@ -296,7 +296,7 @@ func (fms *fileMetadataStore) GetMountParent(mount string) (ChainID, error) { return "", err } - dgst, err := digest.ParseDigest(strings.TrimSpace(string(content))) + dgst, err := digest.Parse(strings.TrimSpace(string(content))) if err != nil { return "", err } diff --git a/components/engine/layer/filestore_test.go b/components/engine/layer/filestore_test.go index 55e3b28530..2126a20b8f 100644 --- a/components/engine/layer/filestore_test.go +++ b/components/engine/layer/filestore_test.go @@ -10,7 +10,7 @@ import ( "syscall" "testing" - "github.com/docker/distribution/digest" + "github.com/opencontainers/go-digest" ) func randomLayerID(seed int64) ChainID { diff --git a/components/engine/layer/layer.go b/components/engine/layer/layer.go index f6b7712a38..7b993ee4ad 100644 --- a/components/engine/layer/layer.go +++ b/components/engine/layer/layer.go @@ -15,8 +15,8 @@ import ( "github.com/Sirupsen/logrus" "github.com/docker/distribution" - "github.com/docker/distribution/digest" "github.com/docker/docker/pkg/archive" + "github.com/opencontainers/go-digest" ) var ( diff --git a/components/engine/layer/layer_store.go b/components/engine/layer/layer_store.go index 4fc323f578..09a55afeab 100644 --- a/components/engine/layer/layer_store.go +++ b/components/engine/layer/layer_store.go @@ -9,11 +9,11 @@ import ( "github.com/Sirupsen/logrus" "github.com/docker/distribution" - "github.com/docker/distribution/digest" "github.com/docker/docker/daemon/graphdriver" "github.com/docker/docker/pkg/idtools" "github.com/docker/docker/pkg/plugingetter" "github.com/docker/docker/pkg/stringid" + "github.com/opencontainers/go-digest" "github.com/vbatts/tar-split/tar/asm" "github.com/vbatts/tar-split/tar/storage" ) @@ -204,7 +204,7 @@ func (ls *layerStore) loadMount(mount string) error { } func (ls *layerStore) applyTar(tx MetadataTransaction, ts io.Reader, parent string, layer *roLayer) error { - digester := digest.Canonical.New() + digester := digest.Canonical.Digester() tr := io.TeeReader(ts, digester.Hash()) tsw, err := tx.TarSplitWriter(true) diff --git a/components/engine/layer/layer_test.go b/components/engine/layer/layer_test.go index d2cc91332c..087a0aa78f 100644 --- a/components/engine/layer/layer_test.go +++ b/components/engine/layer/layer_test.go @@ -10,12 +10,12 @@ import ( "strings" "testing" - "github.com/docker/distribution/digest" "github.com/docker/docker/daemon/graphdriver" "github.com/docker/docker/daemon/graphdriver/vfs" "github.com/docker/docker/pkg/archive" "github.com/docker/docker/pkg/idtools" "github.com/docker/docker/pkg/stringid" + "github.com/opencontainers/go-digest" ) func init() { diff --git a/components/engine/layer/layer_windows.go b/components/engine/layer/layer_windows.go index e20311a091..dffb5b3caf 100644 --- a/components/engine/layer/layer_windows.go +++ b/components/engine/layer/layer_windows.go @@ -5,8 +5,8 @@ import ( "fmt" "github.com/Sirupsen/logrus" - "github.com/docker/distribution/digest" "github.com/docker/docker/daemon/graphdriver" + "github.com/opencontainers/go-digest" ) // GetLayerPath returns the path to a layer diff --git a/components/engine/layer/migration.go b/components/engine/layer/migration.go index b45c31099d..4803a1ae56 100644 --- a/components/engine/layer/migration.go +++ b/components/engine/layer/migration.go @@ -8,7 +8,7 @@ import ( "os" "github.com/Sirupsen/logrus" - "github.com/docker/distribution/digest" + "github.com/opencontainers/go-digest" "github.com/vbatts/tar-split/tar/asm" "github.com/vbatts/tar-split/tar/storage" ) @@ -98,7 +98,7 @@ func (ls *layerStore) ChecksumForGraphID(id, parent, oldTarDataPath, newTarDataP return } - dgst := digest.Canonical.New() + dgst := digest.Canonical.Digester() err = ls.assembleTarTo(id, uncompressed, &size, dgst.Hash()) if err != nil { return diff --git a/components/engine/layer/ro_layer.go b/components/engine/layer/ro_layer.go index ea07b5b9d0..c037390050 100644 --- a/components/engine/layer/ro_layer.go +++ b/components/engine/layer/ro_layer.go @@ -5,7 +5,7 @@ import ( "io" "github.com/docker/distribution" - "github.com/docker/distribution/digest" + "github.com/opencontainers/go-digest" ) type roLayer struct { @@ -156,14 +156,10 @@ func storeLayer(tx MetadataTransaction, layer *roLayer) error { } func newVerifiedReadCloser(rc io.ReadCloser, dgst digest.Digest) (io.ReadCloser, error) { - verifier, err := digest.NewDigestVerifier(dgst) - if err != nil { - return nil, err - } return &verifiedReadCloser{ rc: rc, dgst: dgst, - verifier: verifier, + verifier: dgst.Verifier(), }, nil } diff --git a/components/engine/migrate/v1/migratev1.go b/components/engine/migrate/v1/migratev1.go index 54c1817e87..c9d8108a25 100644 --- a/components/engine/migrate/v1/migratev1.go +++ b/components/engine/migrate/v1/migratev1.go @@ -14,13 +14,13 @@ import ( "encoding/json" "github.com/Sirupsen/logrus" - "github.com/docker/distribution/digest" "github.com/docker/docker/distribution/metadata" "github.com/docker/docker/image" imagev1 "github.com/docker/docker/image/v1" "github.com/docker/docker/layer" "github.com/docker/docker/pkg/ioutils" "github.com/docker/docker/reference" + "github.com/opencontainers/go-digest" ) type graphIDRegistrar interface { @@ -327,7 +327,7 @@ func migrateRefs(root, driverName string, rs refAdder, mappings map[string]image logrus.Errorf("migrate tags: invalid name %q, %q", name, err) continue } - if dgst, err := digest.ParseDigest(tag); err == nil { + if dgst, err := digest.Parse(tag); err == nil { canonical, err := reference.WithDigest(reference.TrimNamed(ref), dgst) if err != nil { logrus.Errorf("migrate tags: invalid digest %q, %q", dgst, err) @@ -425,7 +425,7 @@ func migrateImage(id, root string, ls graphIDRegistrar, is image.Store, ms metad if err != nil { return err } - diffID, err := digest.ParseDigest(string(diffIDData)) + diffID, err := digest.Parse(string(diffIDData)) if err != nil { return err } @@ -477,7 +477,7 @@ func migrateImage(id, root string, ls graphIDRegistrar, is image.Store, ms metad checksum, err := ioutil.ReadFile(filepath.Join(root, graphDirName, id, "checksum")) if err == nil { // best effort - dgst, err := digest.ParseDigest(string(checksum)) + dgst, err := digest.Parse(string(checksum)) if err == nil { V2MetadataService := metadata.NewV2MetadataService(ms) V2MetadataService.Add(layer.DiffID(), metadata.V2Metadata{Digest: dgst}) diff --git a/components/engine/migrate/v1/migratev1_test.go b/components/engine/migrate/v1/migratev1_test.go index be82fdc75e..796c07814a 100644 --- a/components/engine/migrate/v1/migratev1_test.go +++ b/components/engine/migrate/v1/migratev1_test.go @@ -13,11 +13,11 @@ import ( "runtime" "testing" - "github.com/docker/distribution/digest" "github.com/docker/docker/distribution/metadata" "github.com/docker/docker/image" "github.com/docker/docker/layer" "github.com/docker/docker/reference" + "github.com/opencontainers/go-digest" ) func TestMigrateRefs(t *testing.T) { diff --git a/components/engine/plugin/backend_linux.go b/components/engine/plugin/backend_linux.go index 26614cd7d4..6ac1e06762 100644 --- a/components/engine/plugin/backend_linux.go +++ b/components/engine/plugin/backend_linux.go @@ -16,7 +16,6 @@ import ( "strings" "github.com/Sirupsen/logrus" - "github.com/docker/distribution/digest" "github.com/docker/distribution/manifest/schema2" "github.com/docker/docker/api/types" "github.com/docker/docker/distribution" @@ -29,6 +28,7 @@ import ( "github.com/docker/docker/pkg/progress" "github.com/docker/docker/plugin/v2" "github.com/docker/docker/reference" + "github.com/opencontainers/go-digest" "github.com/pkg/errors" "golang.org/x/net/context" ) @@ -123,7 +123,7 @@ func (s *tempConfigStore) Put(c []byte) (digest.Digest, error) { func (s *tempConfigStore) Get(d digest.Digest) ([]byte, error) { if d != s.configDigest { - return nil, digest.ErrDigestNotFound + return nil, fmt.Errorf("digest not found") } return s.config, nil } @@ -556,7 +556,7 @@ func (pm *Manager) CreateFromContext(ctx context.Context, tarCtx io.ReadCloser, } defer rootFSBlob.Close() gzw := gzip.NewWriter(rootFSBlob) - layerDigester := digest.Canonical.New() + layerDigester := digest.Canonical.Digester() rootFSReader := io.TeeReader(rootFS, io.MultiWriter(gzw, layerDigester.Hash())) if err := chrootarchive.Untar(rootFSReader, tmpRootFSDir, nil); err != nil { diff --git a/components/engine/plugin/blobstore.go b/components/engine/plugin/blobstore.go index dc9e598e04..b407884cc7 100644 --- a/components/engine/plugin/blobstore.go +++ b/components/engine/plugin/blobstore.go @@ -1,18 +1,19 @@ package plugin import ( + "fmt" "io" "io/ioutil" "os" "path/filepath" "github.com/Sirupsen/logrus" - "github.com/docker/distribution/digest" "github.com/docker/docker/distribution/xfer" "github.com/docker/docker/image" "github.com/docker/docker/layer" "github.com/docker/docker/pkg/archive" "github.com/docker/docker/pkg/progress" + "github.com/opencontainers/go-digest" "github.com/pkg/errors" "golang.org/x/net/context" ) @@ -86,7 +87,7 @@ type insertion struct { } func newInsertion(tempFile *os.File) *insertion { - digester := digest.Canonical.New() + digester := digest.Canonical.Digester() return &insertion{f: tempFile, digester: digester, Writer: io.MultiWriter(tempFile, digester.Hash())} } @@ -141,7 +142,7 @@ func (dm *downloadManager) Download(ctx context.Context, initialRootFS image.Roo if err != nil { return initialRootFS, nil, err } - digester := digest.Canonical.New() + digester := digest.Canonical.Digester() if _, err := archive.ApplyLayer(dm.tmpDir, io.TeeReader(inflatedLayerData, digester.Hash())); err != nil { return initialRootFS, nil, err } @@ -174,7 +175,7 @@ func (dm *downloadManager) Put(dt []byte) (digest.Digest, error) { } func (dm *downloadManager) Get(d digest.Digest) ([]byte, error) { - return nil, digest.ErrDigestNotFound + return nil, fmt.Errorf("digest not found") } func (dm *downloadManager) RootFSFromConfig(c []byte) (*image.RootFS, error) { return configToRootFS(c) diff --git a/components/engine/plugin/manager.go b/components/engine/plugin/manager.go index 1954784fb3..a81c3edb47 100644 --- a/components/engine/plugin/manager.go +++ b/components/engine/plugin/manager.go @@ -12,7 +12,6 @@ import ( "sync" "github.com/Sirupsen/logrus" - "github.com/docker/distribution/digest" "github.com/docker/docker/api/types" "github.com/docker/docker/image" "github.com/docker/docker/layer" @@ -22,6 +21,7 @@ import ( "github.com/docker/docker/plugin/v2" "github.com/docker/docker/reference" "github.com/docker/docker/registry" + "github.com/opencontainers/go-digest" "github.com/pkg/errors" ) diff --git a/components/engine/plugin/manager_linux.go b/components/engine/plugin/manager_linux.go index a5083154d1..ef91ce3120 100644 --- a/components/engine/plugin/manager_linux.go +++ b/components/engine/plugin/manager_linux.go @@ -11,7 +11,6 @@ import ( "time" "github.com/Sirupsen/logrus" - "github.com/docker/distribution/digest" "github.com/docker/docker/api/types" "github.com/docker/docker/daemon/initlayer" "github.com/docker/docker/libcontainerd" @@ -19,6 +18,7 @@ import ( "github.com/docker/docker/pkg/plugins" "github.com/docker/docker/pkg/stringid" "github.com/docker/docker/plugin/v2" + "github.com/opencontainers/go-digest" specs "github.com/opencontainers/runtime-spec/specs-go" "github.com/pkg/errors" ) diff --git a/components/engine/plugin/v2/plugin.go b/components/engine/plugin/v2/plugin.go index 93b489a14b..b40a4aaba3 100644 --- a/components/engine/plugin/v2/plugin.go +++ b/components/engine/plugin/v2/plugin.go @@ -5,10 +5,10 @@ import ( "strings" "sync" - "github.com/docker/distribution/digest" "github.com/docker/docker/api/types" "github.com/docker/docker/pkg/plugingetter" "github.com/docker/docker/pkg/plugins" + "github.com/opencontainers/go-digest" ) // Plugin represents an individual plugin. diff --git a/components/engine/reference/reference.go b/components/engine/reference/reference.go index 15854e5a5b..620ee09340 100644 --- a/components/engine/reference/reference.go +++ b/components/engine/reference/reference.go @@ -5,9 +5,9 @@ import ( "fmt" "strings" - "github.com/docker/distribution/digest" distreference "github.com/docker/distribution/reference" "github.com/docker/docker/pkg/stringid" + "github.com/opencontainers/go-digest" ) const ( @@ -166,7 +166,7 @@ func ParseIDOrReference(idOrRef string) (digest.Digest, Named, error) { if err := stringid.ValidateID(idOrRef); err == nil { idOrRef = "sha256:" + idOrRef } - if dgst, err := digest.ParseDigest(idOrRef); err == nil { + if dgst, err := digest.Parse(idOrRef); err == nil { return dgst, nil, nil } ref, err := ParseNamed(idOrRef) diff --git a/components/engine/reference/reference_test.go b/components/engine/reference/reference_test.go index a1822b784e..481a2dd97b 100644 --- a/components/engine/reference/reference_test.go +++ b/components/engine/reference/reference_test.go @@ -3,7 +3,7 @@ package reference import ( "testing" - "github.com/docker/distribution/digest" + "github.com/opencontainers/go-digest" ) func TestValidateReferenceName(t *testing.T) { diff --git a/components/engine/reference/store.go b/components/engine/reference/store.go index 71ca236c9c..35ae33660a 100644 --- a/components/engine/reference/store.go +++ b/components/engine/reference/store.go @@ -9,8 +9,8 @@ import ( "sort" "sync" - "github.com/docker/distribution/digest" "github.com/docker/docker/pkg/ioutils" + "github.com/opencontainers/go-digest" ) var ( diff --git a/components/engine/reference/store_test.go b/components/engine/reference/store_test.go index c2c9c97d91..0d96e6b694 100644 --- a/components/engine/reference/store_test.go +++ b/components/engine/reference/store_test.go @@ -8,7 +8,7 @@ import ( "strings" "testing" - "github.com/docker/distribution/digest" + "github.com/opencontainers/go-digest" ) var (