mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
If curl is installed, 'docker pull' will use it to download images with a pretty progress bar. Otherwise it will fallback to regular http.Get()
This commit is contained in:
parent
aa12da6f50
commit
003ec21d36
3 changed files with 27 additions and 4 deletions
|
@ -157,7 +157,7 @@ Step by step host setup
|
|||
3. Type the following commands:
|
||||
|
||||
apt-get update
|
||||
apt-get install lxc wget bsdtar
|
||||
apt-get install lxc wget bsdtar curl
|
||||
|
||||
4. Download the latest version of the [docker binaries](https://dl.dropbox.com/u/20637798/docker.tar.gz) (`wget https://dl.dropbox.com/u/20637798/docker.tar.gz`) (warning: this may not be the most up-to-date build)
|
||||
5. Extract the contents of the tar file `tar -xf docker.tar.gz`
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
"math/rand"
|
||||
"os/exec"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
@ -83,3 +84,19 @@ func Pv(src io.Reader, info io.Writer) io.Reader {
|
|||
}()
|
||||
return r
|
||||
}
|
||||
|
||||
// Curl makes an http request by executing the unix command 'curl', and returns
|
||||
// the body of the response. If `stderr` is not nil, a progress bar will be
|
||||
// written to it.
|
||||
func Curl(url string, stderr io.Writer) (io.Reader, error) {
|
||||
curl := exec.Command("curl", "-#", "-L", url)
|
||||
output, err := curl.StdoutPipe()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
curl.Stderr = stderr
|
||||
if err := curl.Start(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return output, nil
|
||||
}
|
||||
|
|
|
@ -390,12 +390,18 @@ func (srv *Server) CmdPull(stdin io.ReadCloser, stdout io.Writer, args ...string
|
|||
u.Path = path.Join("/docker.io/images", u.Path)
|
||||
}
|
||||
fmt.Fprintf(stdout, "Downloading from %s\n", u.String())
|
||||
resp, err := http.Get(u.String())
|
||||
// Download with curl (pretty progress bar)
|
||||
// If curl is not available, fallback to http.Get()
|
||||
archive, err := future.Curl(u.String(), stdout)
|
||||
if err != nil {
|
||||
if resp, err := http.Get(u.String()); err != nil {
|
||||
return err
|
||||
} else {
|
||||
archive = resp.Body
|
||||
}
|
||||
}
|
||||
fmt.Fprintf(stdout, "Unpacking to %s\n", name)
|
||||
img, err := srv.images.Import(name, resp.Body, nil)
|
||||
img, err := srv.images.Import(name, archive, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue