2015-03-24 23:57:23 -04:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net/url"
|
|
|
|
|
2015-05-05 00:18:28 -04:00
|
|
|
Cli "github.com/docker/docker/cli"
|
2015-03-24 23:57:23 -04:00
|
|
|
flag "github.com/docker/docker/pkg/mflag"
|
|
|
|
"github.com/docker/docker/pkg/parsers"
|
|
|
|
"github.com/docker/docker/registry"
|
|
|
|
)
|
|
|
|
|
2015-03-25 13:34:41 -04:00
|
|
|
// CmdPush pushes an image or repository to the registry.
|
|
|
|
//
|
|
|
|
// Usage: docker push NAME[:TAG]
|
2015-03-24 23:57:23 -04:00
|
|
|
func (cli *DockerCli) CmdPush(args ...string) error {
|
2015-05-05 00:18:28 -04:00
|
|
|
cmd := Cli.Subcmd("push", []string{"NAME[:TAG]"}, "Push an image or a repository to a registry", true)
|
2015-03-24 23:57:23 -04:00
|
|
|
cmd.Require(flag.Exact, 1)
|
|
|
|
|
2015-03-28 21:22:46 -04:00
|
|
|
cmd.ParseFlags(args, true)
|
2015-03-24 23:57:23 -04:00
|
|
|
|
2015-07-03 05:26:09 -04:00
|
|
|
remote, tag := parsers.ParseRepositoryTag(cmd.Arg(0))
|
2015-03-24 23:57:23 -04:00
|
|
|
|
|
|
|
// Resolve the Repository name from fqn to RepositoryInfo
|
|
|
|
repoInfo, err := registry.ParseRepositoryInfo(remote)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
// Resolve the Auth config relevant for this server
|
2015-04-22 08:06:58 -04:00
|
|
|
authConfig := registry.ResolveAuthConfig(cli.configFile, repoInfo.Index)
|
2015-03-24 23:57:23 -04:00
|
|
|
// If we're not using a custom registry, we know the restrictions
|
|
|
|
// applied to repository names and can warn the user in advance.
|
|
|
|
// Custom repositories can have different rules, and we must also
|
|
|
|
// allow pushing by image ID.
|
|
|
|
if repoInfo.Official {
|
|
|
|
username := authConfig.Username
|
|
|
|
if username == "" {
|
|
|
|
username = "<user>"
|
|
|
|
}
|
|
|
|
return fmt.Errorf("You cannot push a \"root\" repository. Please rename your repository to <user>/<repo> (ex: %s/%s)", username, repoInfo.LocalName)
|
|
|
|
}
|
|
|
|
|
|
|
|
v := url.Values{}
|
|
|
|
v.Set("tag", tag)
|
|
|
|
|
2015-01-12 14:56:01 -05:00
|
|
|
_, _, err = cli.clientRequestAttemptLogin("POST", "/images/"+remote+"/push?"+v.Encode(), nil, cli.out, repoInfo.Index, "push")
|
|
|
|
return err
|
2015-03-24 23:57:23 -04:00
|
|
|
}
|