Skip to content

Commit

Permalink
executor: Don't repull image if pinned by digest
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
aaronlehmann committed Nov 10, 2016
1 parent 2161f35 commit f69e5c1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions daemon/cluster/executor/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
13 changes: 13 additions & 0 deletions daemon/cluster/executor/container/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit f69e5c1

Please sign in to comment.