diff --git a/registry/registry.go b/registry/registry.go index 1c75e83680..8a5fc1acf8 100644 --- a/registry/registry.go +++ b/registry/registry.go @@ -112,10 +112,9 @@ func (r *Registry) getImagesInRepository(repository string, authConfig *auth.Aut // Retrieve an image from the Registry. // Returns the Image object as well as the layer as an Archive (io.Reader) -func (r *Registry) GetRemoteImageJson(stdout io.Writer, imgId, registry string, token []string) ([]byte, error) { +func (r *Registry) GetRemoteImageJson(imgId, registry string, token []string) ([]byte, error) { client := r.getHttpClient() - fmt.Fprintf(stdout, "Pulling %s metadata\r\n", imgId) // Get the Json req, err := http.NewRequest("GET", registry+"/images/"+imgId+"/json", nil) if err != nil { @@ -137,22 +136,22 @@ func (r *Registry) GetRemoteImageJson(stdout io.Writer, imgId, registry string, return jsonString, nil } -func (r *Registry) GetRemoteImageLayer(stdout io.Writer, imgId, registry string, token []string) (io.Reader, error) { +func (r *Registry) GetRemoteImageLayer(imgId, registry string, token []string) (io.ReadCloser, int, error) { client := r.getHttpClient() req, err := http.NewRequest("GET", registry+"/images/"+imgId+"/layer", nil) if err != nil { - return nil, fmt.Errorf("Error while getting from the server: %s\n", err) + return nil, -1, fmt.Errorf("Error while getting from the server: %s\n", err) } req.Header.Set("Authorization", "Token "+strings.Join(token, ", ")) res, err := client.Do(req) if err != nil { - return nil, err + return nil, -1, err } - return utils.ProgressReader(res.Body, int(res.ContentLength), stdout, "Downloading %v/%v (%v)"), nil + return res.Body, int(res.ContentLength), nil } -func (r *Registry) GetRemoteTags(stdout io.Writer, registries []string, repository string, token []string) (map[string]string, error) { +func (r *Registry) GetRemoteTags(registries []string, repository string, token []string) (map[string]string, error) { client := r.getHttpClient() if strings.Count(repository, "/") == 0 { // This will be removed once the Registry supports auto-resolution on @@ -189,7 +188,7 @@ func (r *Registry) GetRemoteTags(stdout io.Writer, registries []string, reposito return nil, fmt.Errorf("Could not reach any registry endpoint") } -func (r *Registry) getImageForTag(stdout io.Writer, tag, remote, registry string, token []string) (string, error) { +func (r *Registry) getImageForTag(tag, remote, registry string, token []string) (string, error) { client := r.getHttpClient() if !strings.Contains(remote, "/") { @@ -466,7 +465,7 @@ func (r *Registry) PushImageJsonIndex(remote string, imgList []*ImgData, validat }, nil } -func (r *Registry) SearchRepositories(stdout io.Writer, term string) (*SearchResults, error) { +func (r *Registry) SearchRepositories(term string) (*SearchResults, error) { client := r.getHttpClient() u := auth.IndexServerAddress() + "/search?q=" + url.QueryEscape(term) req, err := http.NewRequest("GET", u, nil) diff --git a/server.go b/server.go index 7e56b1e324..29b9acd769 100644 --- a/server.go +++ b/server.go @@ -48,7 +48,7 @@ func (srv *Server) ContainerExport(name string, out io.Writer) error { } func (srv *Server) ImagesSearch(term string) ([]ApiSearch, error) { - results, err := srv.registry.SearchRepositories(nil, term) + results, err := srv.registry.SearchRepositories(term) if err != nil { return nil, err } @@ -287,7 +287,7 @@ func (srv *Server) ContainerTag(name, repo, tag string, force bool) error { return nil } -func (srv *Server) pullImage(stdout io.Writer, imgId, registry string, token []string) error { +func (srv *Server) pullImage(out io.Writer, imgId, registry string, token []string) error { history, err := srv.registry.GetRemoteHistory(imgId, registry, token) if err != nil { return err @@ -297,7 +297,8 @@ func (srv *Server) pullImage(stdout io.Writer, imgId, registry string, token []s // FIXME: Launch the getRemoteImage() in goroutines for _, id := range history { if !srv.runtime.graph.Exists(id) { - imgJson, err := srv.registry.GetRemoteImageJson(stdout, id, registry, token) + fmt.Fprintf(out, "Pulling %s metadata\r\n", id) + imgJson, err := srv.registry.GetRemoteImageJson(id, registry, token) if err != nil { // FIXME: Keep goging in case of error? return err @@ -308,13 +309,12 @@ func (srv *Server) pullImage(stdout io.Writer, imgId, registry string, token []s } // Get the layer - fmt.Fprintf(stdout, "Pulling %s fs layer\r\n", img.Id) - layer, err := srv.registry.GetRemoteImageLayer(stdout, img.Id, registry, token) + fmt.Fprintf(out, "Pulling %s fs layer\r\n", img.Id) + layer, contentLength, err := srv.registry.GetRemoteImageLayer(img.Id, registry, token) if err != nil { return err } - - if err := srv.runtime.graph.Register(layer, false, img); err != nil { + if err := srv.runtime.graph.Register(utils.ProgressReader(layer, contentLength, out, "Downloading %v/%v (%v)"), false, img); err != nil { return err } } @@ -336,7 +336,7 @@ func (srv *Server) pullRepository(stdout io.Writer, remote, askedTag string) err } utils.Debugf("Retrieving the tag list") - tagsList, err := srv.registry.GetRemoteTags(stdout, repoData.Endpoints, remote, repoData.Tokens) + tagsList, err := srv.registry.GetRemoteTags(repoData.Endpoints, remote, repoData.Tokens) if err != nil { return err }