diff options
author | Aaron Lehmann <aaron.lehmann@docker.com> | 2017-02-09 16:30:46 -0800 |
---|---|---|
committer | Aaron Lehmann <aaron.lehmann@docker.com> | 2017-02-09 16:30:46 -0800 |
commit | b7a2d85316314112809e8e2f6abf84bb10428f38 (patch) | |
tree | 4223ea189bccb81d5cf7a83da9e70169e617a146 /reference | |
parent | 7efc2865181ad3fd6fd36f383e110994949916c9 (diff) | |
download | docker-b7a2d85316314112809e8e2f6abf84bb10428f38.tar.gz |
reference: Handle combination of tag and digest in AddReference
With the switchover to the unified reference package, AddReference no
longer does the right thing when passed a reference that has both a
digest and a tag. It would put both the digest in the tag in the
reference stored in the repositories.json file, which isn't the right
format, and would mean that neither "docker run" nor docker services
could locate the image. This meant that a simple "docker service create"
command like "docker service create --name foo busybox top" would create
a service that immediately went into a restart loop, because it couldn't
use the image that had been pulled.
Fix AddReference to strip out the tag when both a tag and digest are
specified. We do this because we don't necessarily want to overwrite the
tag - when both a digest and tag are specified, the tag is only
advisory.
Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
Diffstat (limited to 'reference')
-rw-r--r-- | reference/store.go | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/reference/store.go b/reference/store.go index 844ebf5319..5a0aec593d 100644 --- a/reference/store.go +++ b/reference/store.go @@ -107,6 +107,20 @@ func (store *store) AddDigest(ref reference.Canonical, id digest.Digest, force b } func (store *store) addReference(ref reference.Named, id digest.Digest, force bool) error { + // If the reference includes a digest and a tag, we must store only the + // digest. + canonical, isCanonical := ref.(reference.Canonical) + _, isNamedTagged := ref.(reference.NamedTagged) + + if isCanonical && isNamedTagged { + trimmed, err := reference.WithDigest(reference.TrimNamed(canonical), canonical.Digest()) + if err != nil { + // should never happen + return err + } + ref = trimmed + } + refName := reference.FamiliarName(ref) refStr := reference.FamiliarString(ref) |