Merge branch 'graph' of ssh://github.com/dotcloud/docker into graph

This commit is contained in:
Solomon Hykes 2013-03-22 18:27:32 -07:00
Родитель bf7602bc09 e02f7912bc
Коммит 72e16f6d96
2 изменённых файлов: 13 добавлений и 8 удалений

Просмотреть файл

@ -45,6 +45,8 @@ func (srv *Server) Help() string {
{"logs", "Fetch the logs of a container"}, {"logs", "Fetch the logs of a container"},
{"port", "Lookup the public-facing port which is NAT-ed to PRIVATE_PORT"}, {"port", "Lookup the public-facing port which is NAT-ed to PRIVATE_PORT"},
{"ps", "List containers"}, {"ps", "List containers"},
{"pull", "Pull an image or a repository to the docker registry server"},
{"push", "Push an image or a repository to the docker registry server"},
{"restart", "Restart a running container"}, {"restart", "Restart a running container"},
{"rm", "Remove a container"}, {"rm", "Remove a container"},
{"rmi", "Remove an image"}, {"rmi", "Remove an image"},
@ -403,20 +405,21 @@ func (srv *Server) CmdPush(stdin io.ReadCloser, stdout io.Writer, args ...string
if err := cmd.Parse(args); err != nil { if err := cmd.Parse(args); err != nil {
return nil return nil
} }
if cmd.NArg() == 0 { if cmd.NArg() == 0 || *user == "" {
cmd.Usage() cmd.Usage()
return nil return nil
} }
if srv.runtime.authConfig == nil {
return fmt.Errorf("Please login prior to push. ('docker login')")
}
// Try to get the image // Try to get the image
// FIXME: Handle lookup // FIXME: Handle lookup
// FIXME: Also push the tags in case of ./docker push myrepo:mytag // FIXME: Also push the tags in case of ./docker push myrepo:mytag
// img, err := srv.runtime.LookupImage(cmd.Arg(0)) // img, err := srv.runtime.LookupImage(cmd.Arg(0))
img, err := srv.runtime.graph.Get(cmd.Arg(0)) img, err := srv.runtime.graph.Get(cmd.Arg(0))
if err != nil { if err != nil {
if *user == "" {
return fmt.Errorf("Not logged in and no user specified\n")
}
// If it fails, try to get the repository // If it fails, try to get the repository
if repo, exists := srv.runtime.repositories.Repositories[cmd.Arg(0)]; exists { if repo, exists := srv.runtime.repositories.Repositories[cmd.Arg(0)]; exists {
fmt.Fprintf(stdout, "Pushing %s (%d images) on %s...\n", cmd.Arg(0), len(repo), *user+"/"+cmd.Arg(0)) fmt.Fprintf(stdout, "Pushing %s (%d images) on %s...\n", cmd.Arg(0), len(repo), *user+"/"+cmd.Arg(0))
@ -445,11 +448,15 @@ func (srv *Server) CmdPull(stdin io.ReadCloser, stdout io.Writer, args ...string
if err := cmd.Parse(args); err != nil { if err := cmd.Parse(args); err != nil {
return nil return nil
} }
if cmd.NArg() == 0 { if cmd.NArg() == 0 || *user == "" {
cmd.Usage() cmd.Usage()
return nil return nil
} }
if srv.runtime.authConfig == nil {
return fmt.Errorf("Please login prior to push. ('docker login')")
}
if srv.runtime.graph.LookupRemoteImage(cmd.Arg(0), srv.runtime.authConfig) { if srv.runtime.graph.LookupRemoteImage(cmd.Arg(0), srv.runtime.authConfig) {
fmt.Fprintf(stdout, "Pulling %s...\n", cmd.Arg(0)) fmt.Fprintf(stdout, "Pulling %s...\n", cmd.Arg(0))
if err := srv.runtime.graph.PullImage(cmd.Arg(0), srv.runtime.authConfig); err != nil { if err := srv.runtime.graph.PullImage(cmd.Arg(0), srv.runtime.authConfig); err != nil {
@ -458,9 +465,6 @@ func (srv *Server) CmdPull(stdin io.ReadCloser, stdout io.Writer, args ...string
fmt.Fprintf(stdout, "Pulled\n") fmt.Fprintf(stdout, "Pulled\n")
return nil return nil
} }
if *user == "" {
return fmt.Errorf("Not loggin and no user specified\n")
}
// FIXME: Allow pull repo:tag // FIXME: Allow pull repo:tag
fmt.Fprintf(stdout, "Pulling %s from %s...\n", cmd.Arg(0), *user+"/"+cmd.Arg(0)) fmt.Fprintf(stdout, "Pulling %s from %s...\n", cmd.Arg(0), *user+"/"+cmd.Arg(0))
if err := srv.runtime.graph.PullRepository(*user, cmd.Arg(0), "", srv.runtime.repositories, srv.runtime.authConfig); err != nil { if err := srv.runtime.graph.PullRepository(*user, cmd.Arg(0), "", srv.runtime.repositories, srv.runtime.authConfig); err != nil {

Просмотреть файл

@ -203,6 +203,7 @@ func (graph *Graph) PushImage(imgOrig *Image, authConfig *auth.AuthConfig) error
if err != nil { if err != nil {
return err return err
} }
req.Header.Add("Content-type", "application/json")
req.SetBasicAuth(authConfig.Username, authConfig.Password) req.SetBasicAuth(authConfig.Username, authConfig.Password)
res, err := client.Do(req) res, err := client.Do(req)
if err != nil || res.StatusCode != 200 { if err != nil || res.StatusCode != 200 {