2016-04-07 17:29:18 -04:00
|
|
|
package daemon
|
|
|
|
|
|
|
|
import (
|
2017-01-25 19:54:18 -05:00
|
|
|
"github.com/docker/distribution/reference"
|
2016-04-07 17:29:18 -04: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-25 19:54:18 -05:00
|
|
|
newTag, err := reference.ParseNormalizedNamed(repository)
|
2016-04-07 17:29:18 -04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if tag != "" {
|
2017-01-25 19:54:18 -05:00
|
|
|
if newTag, err = reference.WithTag(reference.TrimNamed(newTag), tag); err != nil {
|
2016-04-07 17:29:18 -04: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 19:37:32 -04:00
|
|
|
if err := daemon.referenceStore.AddTag(newTag, imageID.Digest(), true); err != nil {
|
2016-04-07 17:29:18 -04:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2017-01-25 19:54:18 -05:00
|
|
|
daemon.LogImageEvent(imageID.String(), reference.FamiliarString(newTag), "tag")
|
2016-04-07 17:29:18 -04:00
|
|
|
return nil
|
|
|
|
}
|