Browse code

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 <aaron.lehmann@docker.com>

Aaron Lehmann authored on 2016/11/29 06:53:52
Showing 2 changed files
... ...
@@ -16,6 +16,7 @@ import (
16 16
 	"time"
17 17
 
18 18
 	"github.com/Sirupsen/logrus"
19
+	"github.com/docker/distribution/digest"
19 20
 	distreference "github.com/docker/distribution/reference"
20 21
 	apierrors "github.com/docker/docker/api/errors"
21 22
 	apitypes "github.com/docker/docker/api/types"
... ...
@@ -1021,6 +1022,9 @@ func (c *Cluster) GetServices(options apitypes.ServiceListOptions) ([]types.Serv
1021 1021
 // TODO(nishanttotla): After the packages converge, the function must
1022 1022
 // convert distreference.Named -> distreference.Canonical, and the logic simplified.
1023 1023
 func (c *Cluster) imageWithDigestString(ctx context.Context, image string, authConfig *apitypes.AuthConfig) (string, error) {
1024
+	if _, err := digest.ParseDigest(image); err == nil {
1025
+		return "", errors.New("image reference is an image ID")
1026
+	}
1024 1027
 	ref, err := distreference.ParseNamed(image)
1025 1028
 	if err != nil {
1026 1029
 		return "", err
... ...
@@ -10,6 +10,7 @@ import (
10 10
 	"time"
11 11
 
12 12
 	"github.com/Sirupsen/logrus"
13
+	"github.com/docker/distribution/digest"
13 14
 	"github.com/docker/docker/api/server/httputils"
14 15
 	"github.com/docker/docker/api/types"
15 16
 	"github.com/docker/docker/api/types/backend"
... ...
@@ -53,6 +54,11 @@ func newContainerAdapter(b executorpkg.Backend, task *api.Task, secrets exec.Sec
53 53
 func (c *containerAdapter) pullImage(ctx context.Context) error {
54 54
 	spec := c.container.spec()
55 55
 
56
+	// Skip pulling if the image is referenced by image ID.
57
+	if _, err := digest.ParseDigest(spec.Image); err == nil {
58
+		return nil
59
+	}
60
+
56 61
 	// Skip pulling if the image is referenced by digest and already
57 62
 	// exists locally.
58 63
 	named, err := reference.ParseNamed(spec.Image)