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 {
|
2017-05-16 23:56:56 +00:00
|
|
|
imageID, platform, err := daemon.GetImageIDAndPlatform(imageName)
|
2016-04-07 21:29:18 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-16 23:56:56 +00:00
|
|
|
return daemon.TagImageWithReference(imageID, platform, newTag)
|
2016-04-07 21:29:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TagImageWithReference adds the given reference to the image ID provided.
|
2017-05-16 23:56:56 +00:00
|
|
|
func (daemon *Daemon) TagImageWithReference(imageID image.ID, platform string, newTag reference.Named) error {
|
2017-08-17 22:43:36 +00:00
|
|
|
if err := daemon.referenceStore.AddTag(newTag, imageID.Digest(), true); err != nil {
|
2016-04-07 21:29:18 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2017-03-02 20:47:02 +00:00
|
|
|
if err := daemon.stores[platform].imageStore.SetLastUpdated(imageID); err != nil {
|
|
|
|
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
|
|
|
|
}
|