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