Browse code

Merge pull request #28265 from aaronlehmann/dont-repull-digest

executor: Don't repull image if pinned by digest

Tõnis Tiigi authored on 2016/11/11 12:19:31
Showing 2 changed files
... ...
@@ -50,4 +50,5 @@ type Backend interface {
50 50
 	UpdateAttachment(string, string, string, *network.NetworkingConfig) error
51 51
 	WaitForDetachment(context.Context, string, string, string, string) error
52 52
 	GetRepository(context.Context, reference.NamedTagged, *types.AuthConfig) (distribution.Repository, bool, error)
53
+	LookupImage(name string) (*types.ImageInspect, error)
53 54
 }
... ...
@@ -17,6 +17,7 @@ import (
17 17
 	"github.com/docker/docker/api/types/events"
18 18
 	"github.com/docker/docker/api/types/versions"
19 19
 	executorpkg "github.com/docker/docker/daemon/cluster/executor"
20
+	"github.com/docker/docker/reference"
20 21
 	"github.com/docker/libnetwork"
21 22
 	"github.com/docker/swarmkit/agent/exec"
22 23
 	"github.com/docker/swarmkit/api"
... ...
@@ -51,6 +52,18 @@ func newContainerAdapter(b executorpkg.Backend, task *api.Task, secrets exec.Sec
51 51
 func (c *containerAdapter) pullImage(ctx context.Context) error {
52 52
 	spec := c.container.spec()
53 53
 
54
+	// Skip pulling if the image is referenced by digest and already
55
+	// exists locally.
56
+	named, err := reference.ParseNamed(spec.Image)
57
+	if err == nil {
58
+		if _, ok := named.(reference.Canonical); ok {
59
+			_, err := c.backend.LookupImage(spec.Image)
60
+			if err == nil {
61
+				return nil
62
+			}
63
+		}
64
+	}
65
+
54 66
 	// if the image needs to be pulled, the auth config will be retrieved and updated
55 67
 	var encodedAuthConfig string
56 68
 	if spec.PullOptions != nil {