2016-04-07 21:29:18 +00:00
|
|
|
package daemon
|
|
|
|
|
|
|
|
import (
|
2017-01-26 00:54:18 +00:00
|
|
|
"github.com/docker/distribution/reference"
|
2016-04-07 21:29:18 +00:00
|
|
|
"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, err := daemon.GetImageID(imageName)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2017-01-26 00:54:18 +00:00
|
|
|
newTag, err := reference.ParseNormalizedNamed(repository)
|
2016-04-07 21:29:18 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if tag != "" {
|
2017-01-26 00:54:18 +00:00
|
|
|
if newTag, err = reference.WithTag(reference.TrimNamed(newTag), tag); err != nil {
|
2016-04-07 21:29:18 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return daemon.TagImageWithReference(imageID, newTag)
|
|
|
|
}
|
|
|
|
|
|
|
|
// TagImageWithReference adds the given reference to the image ID provided.
|
|
|
|
func (daemon *Daemon) TagImageWithReference(imageID image.ID, newTag reference.Named) error {
|
2016-09-15 23:37:32 +00:00
|
|
|
if err := daemon.referenceStore.AddTag(newTag, imageID.Digest(), true); err != nil {
|
2016-04-07 21:29:18 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2017-01-26 00:54:18 +00:00
|
|
|
daemon.LogImageEvent(imageID.String(), reference.FamiliarString(newTag), "tag")
|
2016-04-07 21:29:18 +00:00
|
|
|
return nil
|
|
|
|
}
|