From f69e5c18ac1186af96a75918fc60f0b8e5ae7675 Mon Sep 17 00:00:00 2001 From: Aaron Lehmann Date: Thu, 10 Nov 2016 13:51:52 -0800 Subject: [PATCH] executor: Don't repull image if pinned by digest If the image reference in the spec uses a digest, and an image with that digest already exists locally, avoid an unnecessary repull. Signed-off-by: Aaron Lehmann --- daemon/cluster/executor/backend.go | 1 + daemon/cluster/executor/container/adapter.go | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/daemon/cluster/executor/backend.go b/daemon/cluster/executor/backend.go index 1a1d4ff091..84d2b4e8b1 100644 --- a/daemon/cluster/executor/backend.go +++ b/daemon/cluster/executor/backend.go @@ -48,4 +48,5 @@ type Backend interface { UpdateAttachment(string, string, string, *network.NetworkingConfig) error WaitForDetachment(context.Context, string, string, string, string) error GetRepository(context.Context, reference.NamedTagged, *types.AuthConfig) (distribution.Repository, bool, error) + LookupImage(name string) (*types.ImageInspect, error) } diff --git a/daemon/cluster/executor/container/adapter.go b/daemon/cluster/executor/container/adapter.go index 98ea358100..469cbeaa41 100644 --- a/daemon/cluster/executor/container/adapter.go +++ b/daemon/cluster/executor/container/adapter.go @@ -16,6 +16,7 @@ import ( "github.com/docker/docker/api/types/events" "github.com/docker/docker/api/types/versions" executorpkg "github.com/docker/docker/daemon/cluster/executor" + "github.com/docker/docker/reference" "github.com/docker/libnetwork" "github.com/docker/swarmkit/agent/exec" "github.com/docker/swarmkit/api" @@ -49,6 +50,18 @@ 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 digest and already + // exists locally. + named, err := reference.ParseNamed(spec.Image) + if err == nil { + if _, ok := named.(reference.Canonical); ok { + _, err := c.backend.LookupImage(spec.Image) + if err == nil { + return nil + } + } + } + // if the image needs to be pulled, the auth config will be retrieved and updated var encodedAuthConfig string if spec.PullOptions != nil {