diff --git a/commands.go b/commands.go index 67877bc3b3..6659252bef 100644 --- a/commands.go +++ b/commands.go @@ -456,12 +456,12 @@ func (srv *Server) CmdPush(stdin io.ReadCloser, stdout io.Writer, args ...string } func (srv *Server) CmdPull(stdin io.ReadCloser, stdout io.Writer, args ...string) error { - cmd := rcli.Subcmd(stdout, "pull", "[OPTIONS] IMAGE", "Pull an image or a repository from the registry") - user := cmd.String("u", "", "specify the user for the repository") + cmd := rcli.Subcmd(stdout, "pull", "IMAGE", "Pull an image or a repository from the registry") if err := cmd.Parse(args); err != nil { return nil } - if cmd.NArg() == 0 || *user == "" { + remote := cmd.Arg(0) + if remote == "" { cmd.Usage() return nil } @@ -470,17 +470,17 @@ func (srv *Server) CmdPull(stdin io.ReadCloser, stdout io.Writer, args ...string 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 { + if srv.runtime.graph.LookupRemoteImage(remote, srv.runtime.authConfig) { + fmt.Fprintf(stdout, "Pulling %s...\n", remote) + if err := srv.runtime.graph.PullImage(remote, srv.runtime.authConfig); err != nil { return err } fmt.Fprintf(stdout, "Pulled\n") return nil } // 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 { + fmt.Fprintf(stdout, "Pulling %s...\n", remote) + if err := srv.runtime.graph.PullRepository(remote, "", srv.runtime.repositories, srv.runtime.authConfig); err != nil { return err } fmt.Fprintf(stdout, "Pull completed\n") diff --git a/registry.go b/registry.go index 40037c15cc..318a65a0e7 100644 --- a/registry.go +++ b/registry.go @@ -106,7 +106,7 @@ func (graph *Graph) getRemoteImage(imgId string, authConfig *auth.AuthConfig) (* } req.SetBasicAuth(authConfig.Username, authConfig.Password) res, err := client.Do(req) - if err != nil || res.StatusCode != 307 { + if err != nil || res.StatusCode != 200 { if res != nil { return nil, nil, fmt.Errorf("Internal server error: %d trying to get image %s", res.StatusCode, imgId) } @@ -126,10 +126,15 @@ func (graph *Graph) getRemoteImage(imgId string, authConfig *auth.AuthConfig) (* img.Id = imgId // Get the layer - res, err = http.Get(REGISTRY_ENDPOINT + "/images/" + imgId + "/layer") + req, err = http.NewRequest("GET", REGISTRY_ENDPOINT+"/images/"+imgId+"/layer", nil) if err != nil { return nil, nil, fmt.Errorf("Error while getting from the server: %s\n", err) } + req.SetBasicAuth(authConfig.Username, authConfig.Password) + res, err = client.Do(req) + if err != nil { + return nil, nil, err + } return img, res.Body, nil } @@ -156,10 +161,12 @@ func (graph *Graph) PullImage(imgId string, authConfig *auth.AuthConfig) error { } // FIXME: Handle the askedTag parameter -func (graph *Graph) PullRepository(user, repoName, askedTag string, repositories *TagStore, authConfig *auth.AuthConfig) error { +func (graph *Graph) PullRepository(remote, askedTag string, repositories *TagStore, authConfig *auth.AuthConfig) error { client := &http.Client{} - req, err := http.NewRequest("GET", REGISTRY_ENDPOINT+"/users/"+user+"/"+repoName, nil) + fmt.Printf("Pulling repo: %s\n", REGISTRY_ENDPOINT+"/users/"+remote) + + req, err := http.NewRequest("GET", REGISTRY_ENDPOINT+"/users/"+remote, nil) if err != nil { return err } @@ -167,7 +174,7 @@ func (graph *Graph) PullRepository(user, repoName, askedTag string, repositories res, err := client.Do(req) if err != nil || res.StatusCode != 200 { if res != nil { - return fmt.Errorf("Internal server error: %d trying to pull %s", res.StatusCode, repoName) + return fmt.Errorf("Internal server error: %d trying to pull %s", res.StatusCode, remote) } return err } @@ -184,7 +191,7 @@ func (graph *Graph) PullRepository(user, repoName, askedTag string, repositories if err = graph.PullImage(rev, authConfig); err != nil { return err } - if err = repositories.Set(repoName, tag, rev, true); err != nil { + if err = repositories.Set(remote, tag, rev, true); err != nil { return err } }