moby/daemon/image_tag.go
Daniel Nephin 016eea004b
Set a LastUpdated time in image metadata when an image tag is updated.
Signed-off-by: Daniel Nephin <dnephin@docker.com>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2017-06-26 12:16:26 -07:00

40 lines
1.2 KiB
Go

package daemon
import (
"github.com/docker/distribution/reference"
"github.com/docker/docker/image"
)
// TagImage creates the tag specified by newTag, pointing to the image named
// imageName (alternatively, imageName can also be an image ID).
func (daemon *Daemon) TagImage(imageName, repository, tag string) error {
imageID, platform, err := daemon.GetImageIDAndPlatform(imageName)
if err != nil {
return err
}
newTag, err := reference.ParseNormalizedNamed(repository)
if err != nil {
return err
}
if tag != "" {
if newTag, err = reference.WithTag(reference.TrimNamed(newTag), tag); err != nil {
return err
}
}
return daemon.TagImageWithReference(imageID, platform, newTag)
}
// TagImageWithReference adds the given reference to the image ID provided.
func (daemon *Daemon) TagImageWithReference(imageID image.ID, platform string, newTag reference.Named) error {
if err := daemon.stores[platform].referenceStore.AddTag(newTag, imageID.Digest(), true); err != nil {
return err
}
if err := daemon.stores[platform].imageStore.SetLastUpdated(imageID); err != nil {
return err
}
daemon.LogImageEvent(imageID.String(), reference.FamiliarString(newTag), "tag")
return nil
}