1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

add parallel pull to 1.4

This commit is contained in:
Victor Vieux 2013-07-30 12:09:07 +00:00
parent e1fa989ec9
commit 46f59dd933
6 changed files with 24 additions and 15 deletions

2
api.go
View file

@ -386,7 +386,7 @@ func postImagesCreate(srv *Server, version float64, w http.ResponseWriter, r *ht
}
sf := utils.NewStreamFormatter(version > 1.0)
if image != "" { //pull
if err := srv.ImagePull(image, tag, w, sf, &auth.AuthConfig{}); err != nil {
if err := srv.ImagePull(image, tag, w, sf, &auth.AuthConfig{}, version > 1.3); err != nil {
if sf.Used() {
w.Write(sf.FormatError(err))
return nil

View file

@ -55,7 +55,7 @@ func (b *buildFile) CmdFrom(name string) error {
if err != nil {
if b.runtime.graph.IsNotExist(err) {
remote, tag := utils.ParseRepositoryTag(name)
if err := b.srv.ImagePull(remote, tag, b.out, utils.NewStreamFormatter(false), nil); err != nil {
if err := b.srv.ImagePull(remote, tag, b.out, utils.NewStreamFormatter(false), nil, true); err != nil {
return err
}
image, err = b.runtime.repositories.LookupImage(name)

View file

@ -40,6 +40,10 @@ You can still call an old version of the api using
What's new
----------
.. http:post:: /images/create
**New!** When pull a repo, all images are now downloaded in parallel.
.. http:get:: /containers/(id)/top
**New!** You can now use ps args with docker top, like `docker top <container_id> aux`

View file

@ -101,7 +101,7 @@ func init() {
// If the unit test is not found, try to download it.
if img, err := globalRuntime.repositories.LookupImage(unitTestImageName); err != nil || img.ID != unitTestImageID {
// Retrieve the Image
if err := srv.ImagePull(unitTestImageName, "", os.Stdout, utils.NewStreamFormatter(false), nil); err != nil {
if err := srv.ImagePull(unitTestImageName, "", os.Stdout, utils.NewStreamFormatter(false), nil, true); err != nil {
panic(err)
}
}

View file

@ -446,7 +446,7 @@ func (srv *Server) pullImage(r *registry.Registry, out io.Writer, imgID, endpoin
return nil
}
func (srv *Server) pullRepository(r *registry.Registry, out io.Writer, localName, remoteName, askedTag, indexEp string, sf *utils.StreamFormatter) error {
func (srv *Server) pullRepository(r *registry.Registry, out io.Writer, localName, remoteName, askedTag, indexEp string, sf *utils.StreamFormatter, parallel bool) error {
out.Write(sf.FormatStatus("", "Pulling repository %s", localName))
repoData, err := r.GetRepositoryData(indexEp, remoteName)
@ -492,7 +492,7 @@ func (srv *Server) pullRepository(r *registry.Registry, out io.Writer, localName
errors := make(chan error)
for _, image := range repoData.ImgList {
go func(img *registry.ImgData) {
downloadImage := func(img *registry.ImgData) {
if askedTag != "" && img.Tag != askedTag {
utils.Debugf("(%s) does not match %s (id: %s), skipping", img.Tag, askedTag, img.ID)
errors <- nil
@ -518,12 +518,20 @@ func (srv *Server) pullRepository(r *registry.Registry, out io.Writer, localName
errors <- fmt.Errorf("Could not find repository on any of the indexed registries.")
}
errors <- nil
}(image)
}
if parallel {
go downloadImage(image)
} else {
downloadImage(image)
}
}
for i := 0; i < len(repoData.ImgList); i++ {
if err := <-errors; err != nil {
return err
if parallel {
for i := 0; i < len(repoData.ImgList); i++ {
if err := <-errors; err != nil {
return err
}
}
}
@ -577,7 +585,7 @@ func (srv *Server) poolRemove(kind, key string) error {
return nil
}
func (srv *Server) ImagePull(localName string, tag string, out io.Writer, sf *utils.StreamFormatter, authConfig *auth.AuthConfig) error {
func (srv *Server) ImagePull(localName string, tag string, out io.Writer, sf *utils.StreamFormatter, authConfig *auth.AuthConfig, parallel bool) error {
r, err := registry.NewRegistry(srv.runtime.root, authConfig, srv.versionInfos()...)
if err != nil {
return err
@ -599,7 +607,7 @@ func (srv *Server) ImagePull(localName string, tag string, out io.Writer, sf *ut
}
out = utils.NewWriteFlusher(out)
err = srv.pullRepository(r, out, localName, remoteName, tag, endpoint, sf)
err = srv.pullRepository(r, out, localName, remoteName, tag, endpoint, sf, parallel)
if err != nil {
if err := srv.pullImage(r, out, remoteName, endpoint, nil, sf); err != nil {
return err

View file

@ -635,7 +635,6 @@ func (jm *JSONMessage) Display(out io.Writer) error {
return nil
}
func DisplayJSONMessagesStream(in io.Reader, out io.Writer) error {
dec := json.NewDecoder(in)
jm := JSONMessage{}
@ -670,8 +669,6 @@ func DisplayJSONMessagesStream(in io.Reader, out io.Writer) error {
return nil
}
=======
>>>>>>> master
type StreamFormatter struct {
json bool
used bool
@ -708,7 +705,7 @@ func (sf *StreamFormatter) FormatError(err error) []byte {
func (sf *StreamFormatter) FormatProgress(id, action, progress string) []byte {
sf.used = true
if sf.json {
b, err := json.Marshal(&JSONMessage{Status: action, Progress: progress, ID:id})
b, err := json.Marshal(&JSONMessage{Status: action, Progress: progress, ID: id})
if err != nil {
return nil
}