github.com/crquan/docker@v1.8.1/api/client/push.go (about)

     1  package client
     2  
     3  import (
     4  	"fmt"
     5  	"net/url"
     6  
     7  	Cli "github.com/docker/docker/cli"
     8  	flag "github.com/docker/docker/pkg/mflag"
     9  	"github.com/docker/docker/pkg/parsers"
    10  	"github.com/docker/docker/registry"
    11  )
    12  
    13  // CmdPush pushes an image or repository to the registry.
    14  //
    15  // Usage: docker push NAME[:TAG]
    16  func (cli *DockerCli) CmdPush(args ...string) error {
    17  	cmd := Cli.Subcmd("push", []string{"NAME[:TAG]"}, "Push an image or a repository to a registry", true)
    18  	addTrustedFlags(cmd, false)
    19  	cmd.Require(flag.Exact, 1)
    20  
    21  	cmd.ParseFlags(args, true)
    22  
    23  	remote, tag := parsers.ParseRepositoryTag(cmd.Arg(0))
    24  
    25  	// Resolve the Repository name from fqn to RepositoryInfo
    26  	repoInfo, err := registry.ParseRepositoryInfo(remote)
    27  	if err != nil {
    28  		return err
    29  	}
    30  	// Resolve the Auth config relevant for this server
    31  	authConfig := registry.ResolveAuthConfig(cli.configFile, repoInfo.Index)
    32  	// If we're not using a custom registry, we know the restrictions
    33  	// applied to repository names and can warn the user in advance.
    34  	// Custom repositories can have different rules, and we must also
    35  	// allow pushing by image ID.
    36  	if repoInfo.Official {
    37  		username := authConfig.Username
    38  		if username == "" {
    39  			username = "<user>"
    40  		}
    41  		return fmt.Errorf("You cannot push a \"root\" repository. Please rename your repository to <user>/<repo> (ex: %s/%s)", username, repoInfo.LocalName)
    42  	}
    43  
    44  	if isTrusted() {
    45  		return cli.trustedPush(repoInfo, tag, authConfig)
    46  	}
    47  
    48  	v := url.Values{}
    49  	v.Set("tag", tag)
    50  
    51  	_, _, err = cli.clientRequestAttemptLogin("POST", "/images/"+remote+"/push?"+v.Encode(), nil, cli.out, repoInfo.Index, "push")
    52  	return err
    53  }