2015-03-25 03:57:23 +00:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
2015-12-06 20:37:54 +00:00
|
|
|
"io"
|
2015-03-25 03:57:23 +00:00
|
|
|
|
2016-02-03 23:41:26 +00:00
|
|
|
"golang.org/x/net/context"
|
|
|
|
|
2015-05-05 04:18:28 +00:00
|
|
|
Cli "github.com/docker/docker/cli"
|
2015-12-06 20:37:54 +00:00
|
|
|
"github.com/docker/docker/pkg/jsonmessage"
|
2015-03-25 03:57:23 +00:00
|
|
|
flag "github.com/docker/docker/pkg/mflag"
|
2015-12-04 21:55:15 +00:00
|
|
|
"github.com/docker/docker/reference"
|
2015-03-25 03:57:23 +00:00
|
|
|
"github.com/docker/docker/registry"
|
2016-01-05 00:05:26 +00:00
|
|
|
"github.com/docker/engine-api/types"
|
2015-03-25 03:57:23 +00:00
|
|
|
)
|
|
|
|
|
2015-03-25 17:34:41 +00:00
|
|
|
// CmdPush pushes an image or repository to the registry.
|
|
|
|
//
|
|
|
|
// Usage: docker push NAME[:TAG]
|
2015-03-25 03:57:23 +00:00
|
|
|
func (cli *DockerCli) CmdPush(args ...string) error {
|
2015-10-08 12:46:21 +00:00
|
|
|
cmd := Cli.Subcmd("push", []string{"NAME[:TAG]"}, Cli.DockerCommands["push"].Description, true)
|
2015-07-15 20:42:45 +00:00
|
|
|
addTrustedFlags(cmd, false)
|
2015-03-25 03:57:23 +00:00
|
|
|
cmd.Require(flag.Exact, 1)
|
|
|
|
|
2015-03-29 01:22:46 +00:00
|
|
|
cmd.ParseFlags(args, true)
|
2015-03-25 03:57:23 +00:00
|
|
|
|
2015-11-18 22:20:54 +00:00
|
|
|
ref, err := reference.ParseNamed(cmd.Arg(0))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2015-03-25 03:57:23 +00:00
|
|
|
// Resolve the Repository name from fqn to RepositoryInfo
|
2015-11-18 22:20:54 +00:00
|
|
|
repoInfo, err := registry.ParseRepositoryInfo(ref)
|
2015-03-25 03:57:23 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
// Resolve the Auth config relevant for this server
|
2016-02-08 00:55:17 +00:00
|
|
|
authConfig := cli.resolveAuthConfig(repoInfo.Index)
|
2015-03-25 03:57:23 +00:00
|
|
|
|
2015-12-06 20:37:54 +00:00
|
|
|
requestPrivilege := cli.registryAuthenticationPrivilegedFunc(repoInfo.Index, "push")
|
2015-07-15 20:42:45 +00:00
|
|
|
if isTrusted() {
|
2016-04-13 08:33:46 +00:00
|
|
|
return cli.trustedPush(repoInfo, ref, authConfig, requestPrivilege)
|
2015-07-15 20:42:45 +00:00
|
|
|
}
|
|
|
|
|
2016-04-13 08:33:46 +00:00
|
|
|
responseBody, err := cli.imagePushPrivileged(authConfig, ref.String(), requestPrivilege)
|
2015-12-21 23:02:44 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
defer responseBody.Close()
|
|
|
|
|
|
|
|
return jsonmessage.DisplayJSONMessagesStream(responseBody, cli.out, cli.outFd, cli.isTerminalOut, nil)
|
2015-12-06 20:37:54 +00:00
|
|
|
}
|
|
|
|
|
2016-04-13 08:33:46 +00:00
|
|
|
func (cli *DockerCli) imagePushPrivileged(authConfig types.AuthConfig, ref string, requestPrivilege types.RequestPrivilegeFunc) (io.ReadCloser, error) {
|
2015-12-12 02:14:52 +00:00
|
|
|
encodedAuth, err := encodeAuthToBase64(authConfig)
|
2015-12-06 20:37:54 +00:00
|
|
|
if err != nil {
|
2015-12-21 23:02:44 +00:00
|
|
|
return nil, err
|
2015-12-06 20:37:54 +00:00
|
|
|
}
|
|
|
|
options := types.ImagePushOptions{
|
2016-04-13 08:33:46 +00:00
|
|
|
RegistryAuth: encodedAuth,
|
|
|
|
PrivilegeFunc: requestPrivilege,
|
2015-12-06 20:37:54 +00:00
|
|
|
}
|
|
|
|
|
2016-04-13 08:33:46 +00:00
|
|
|
return cli.client.ImagePush(context.Background(), ref, options)
|
2015-03-25 03:57:23 +00:00
|
|
|
}
|