From 3870ebee6db450efcebac81b829694a047583442 Mon Sep 17 00:00:00 2001 From: creack Date: Fri, 22 Mar 2013 03:22:36 -0700 Subject: [PATCH 1/3] Add content type to Push --- registry.go | 1 + 1 file changed, 1 insertion(+) diff --git a/registry.go b/registry.go index da1186ee54..7d6add42d4 100644 --- a/registry.go +++ b/registry.go @@ -203,6 +203,7 @@ func (graph *Graph) PushImage(imgOrig *Image, authConfig *auth.AuthConfig) error if err != nil { return err } + req.Header.Add("Content-type", "application/json") req.SetBasicAuth(authConfig.Username, authConfig.Password) res, err := client.Do(req) if err != nil || res.StatusCode != 200 { From e4f9a0dca0a3eb9fd762ef502d40a089ed16acd4 Mon Sep 17 00:00:00 2001 From: creack Date: Fri, 22 Mar 2013 03:24:37 -0700 Subject: [PATCH 2/3] Update the help with push/pull --- commands.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/commands.go b/commands.go index 1d782bf96c..8c2875370f 100644 --- a/commands.go +++ b/commands.go @@ -45,6 +45,8 @@ func (srv *Server) Help() string { {"logs", "Fetch the logs of a container"}, {"port", "Lookup the public-facing port which is NAT-ed to PRIVATE_PORT"}, {"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"}, {"rm", "Remove a container"}, {"rmi", "Remove an image"}, From e02f7912bcc07dbddd47bcf0106ca881fd768559 Mon Sep 17 00:00:00 2001 From: creack Date: Fri, 22 Mar 2013 03:43:57 -0700 Subject: [PATCH 3/3] Enforce login for push/pull --- commands.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/commands.go b/commands.go index 8c2875370f..3a1bf7f1d5 100644 --- a/commands.go +++ b/commands.go @@ -405,20 +405,21 @@ func (srv *Server) CmdPush(stdin io.ReadCloser, stdout io.Writer, args ...string if err := cmd.Parse(args); err != nil { return nil } - if cmd.NArg() == 0 { + if cmd.NArg() == 0 || *user == "" { cmd.Usage() return nil } + if srv.runtime.authConfig == nil { + return fmt.Errorf("Please login prior to push. ('docker login')") + } + // Try to get the image // FIXME: Handle lookup // FIXME: Also push the tags in case of ./docker push myrepo:mytag // img, err := srv.runtime.LookupImage(cmd.Arg(0)) img, err := srv.runtime.graph.Get(cmd.Arg(0)) 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 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)) @@ -447,11 +448,15 @@ func (srv *Server) CmdPull(stdin io.ReadCloser, stdout io.Writer, args ...string if err := cmd.Parse(args); err != nil { return nil } - if cmd.NArg() == 0 { + if cmd.NArg() == 0 || *user == "" { cmd.Usage() 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) { fmt.Fprintf(stdout, "Pulling %s...\n", cmd.Arg(0)) if err := srv.runtime.graph.PullImage(cmd.Arg(0), srv.runtime.authConfig); err != nil { @@ -460,9 +465,6 @@ func (srv *Server) CmdPull(stdin io.ReadCloser, stdout io.Writer, args ...string fmt.Fprintf(stdout, "Pulled\n") return nil } - if *user == "" { - return fmt.Errorf("Not loggin and no user specified\n") - } // FIXME: Allow pull repo:tag 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 {