From 30e5e0a7810867cf8f683ca1db7834fdc5d7622d Mon Sep 17 00:00:00 2001 From: Aaron Lehmann Date: Mon, 28 Nov 2016 13:53:52 -0800 Subject: [PATCH] Don't resolve or pull images referenced by ID If a swarm service is created using an image ID, it's useless to try to pull this reference or resolve it to a manifest digest. Avoid doing this when a fully qualified image ID is given. Signed-off-by: Aaron Lehmann (cherry picked from commit 089842c4b47c262187b0b1a8d6d124f3faa03752) Signed-off-by: Victor Vieux --- daemon/cluster/cluster.go | 4 ++++ daemon/cluster/executor/container/adapter.go | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/daemon/cluster/cluster.go b/daemon/cluster/cluster.go index 8bb46a6998..b2afe15eef 100644 --- a/daemon/cluster/cluster.go +++ b/daemon/cluster/cluster.go @@ -16,6 +16,7 @@ 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" @@ -1024,6 +1025,9 @@ 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 { + return "", errors.New("image reference is an image ID") + } ref, err := distreference.ParseNamed(image) if err != nil { return "", err diff --git a/daemon/cluster/executor/container/adapter.go b/daemon/cluster/executor/container/adapter.go index 010c18c5b3..1613b1d114 100644 --- a/daemon/cluster/executor/container/adapter.go +++ b/daemon/cluster/executor/container/adapter.go @@ -10,6 +10,7 @@ import ( "time" "github.com/Sirupsen/logrus" + "github.com/docker/distribution/digest" "github.com/docker/docker/api/server/httputils" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/backend" @@ -53,6 +54,11 @@ func newContainerAdapter(b executorpkg.Backend, task *api.Task, secrets exec.Sec 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 { + return nil + } + // Skip pulling if the image is referenced by digest and already // exists locally. named, err := reference.ParseNamed(spec.Image)