mirror of
https://github.com/moby/moby.git
synced 2026-08-13 17:06:44 +00:00
Using "familiarname" (e.g. "ubuntu") should be mostly done for presenting
image refernces to the user, but internally, we should use the canonical
format where possible ("docker.io/library/ubuntu").
There's still many places where we use the familiar (short) form, but
let's start with not converting references in the client.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
38 lines
1.0 KiB
Go
38 lines
1.0 KiB
Go
package client // import "github.com/docker/docker/client"
|
|
|
|
import (
|
|
"context"
|
|
"net/url"
|
|
|
|
"github.com/distribution/reference"
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
// ImageTag tags an image in the docker host
|
|
func (cli *Client) ImageTag(ctx context.Context, source, target string) error {
|
|
if _, err := reference.ParseAnyReference(source); err != nil {
|
|
return errors.Wrapf(err, "Error parsing reference: %q is not a valid repository/tag", source)
|
|
}
|
|
|
|
ref, err := reference.ParseNormalizedNamed(target)
|
|
if err != nil {
|
|
return errors.Wrapf(err, "Error parsing reference: %q is not a valid repository/tag", target)
|
|
}
|
|
|
|
if _, isCanonical := ref.(reference.Canonical); isCanonical {
|
|
return errors.New("refusing to create a tag with a digest reference")
|
|
}
|
|
|
|
ref = reference.TagNameOnly(ref)
|
|
|
|
query := url.Values{}
|
|
query.Set("repo", ref.Name())
|
|
if tagged, ok := ref.(reference.Tagged); ok {
|
|
query.Set("tag", tagged.Tag())
|
|
}
|
|
|
|
resp, err := cli.post(ctx, "/images/"+source+"/tag", query, nil, nil)
|
|
ensureReaderClosed(resp)
|
|
return err
|
|
}
|