Implement docker tag with standalone client lib.
Signed-off-by: David Calavera <david.calavera@gmail.com>
This commit is contained in:
parent
9ec1cf92f5
commit
21ffdf0e0e
2 changed files with 32 additions and 10 deletions
25
api/client/lib/image_tag.go
Normal file
25
api/client/lib/image_tag.go
Normal file
|
@ -0,0 +1,25 @@
|
|||
package lib
|
||||
|
||||
import "net/url"
|
||||
|
||||
// ImageTagOptions hold parameters to tag an image
|
||||
type ImageTagOptions struct {
|
||||
ImageID string
|
||||
RepositoryName string
|
||||
Tag string
|
||||
Force bool
|
||||
}
|
||||
|
||||
// ImageTag tags an image in the docker host
|
||||
func (cli *Client) ImageTag(options types.ImageTagOptions) error {
|
||||
query := url.Values{}
|
||||
query.Set("repo", options.RepositoryName)
|
||||
query.Set("tag", options.Tag)
|
||||
if options.Force {
|
||||
query.Set("force", "1")
|
||||
}
|
||||
|
||||
resp, err := cli.POST("/images/"+options.ImageID+"/tag", query, nil, nil)
|
||||
ensureReaderClosed(resp)
|
||||
return err
|
||||
}
|
|
@ -2,9 +2,9 @@ package client
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"net/url"
|
||||
|
||||
"github.com/docker/distribution/reference"
|
||||
"github.com/docker/docker/api/client/lib"
|
||||
Cli "github.com/docker/docker/cli"
|
||||
flag "github.com/docker/docker/pkg/mflag"
|
||||
"github.com/docker/docker/registry"
|
||||
|
@ -20,7 +20,6 @@ func (cli *DockerCli) CmdTag(args ...string) error {
|
|||
|
||||
cmd.ParseFlags(args, true)
|
||||
|
||||
v := url.Values{}
|
||||
ref, err := reference.ParseNamed(cmd.Arg(1))
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -41,15 +40,13 @@ func (cli *DockerCli) CmdTag(args ...string) error {
|
|||
if err := registry.ValidateRepositoryName(ref); err != nil {
|
||||
return err
|
||||
}
|
||||
v.Set("repo", ref.Name())
|
||||
v.Set("tag", tag)
|
||||
|
||||
if *force {
|
||||
v.Set("force", "1")
|
||||
options := lib.ImageTagOptions{
|
||||
ImageID: cmd.Arg(0),
|
||||
RepositoryName: ref.Name(),
|
||||
Tag: tag,
|
||||
Force: *force,
|
||||
}
|
||||
|
||||
if _, _, err := readBody(cli.call("POST", "/images/"+cmd.Arg(0)+"/tag?"+v.Encode(), nil, nil)); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return cli.client.ImageTag(options)
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue