Explorar el Código

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()

Solomon Hykes hace 12 años
padre
commit
003ec21d36
Se han modificado 3 ficheros con 27 adiciones y 4 borrados
  1. 1 1
      README.md
  2. 17 0
      future/future.go
  3. 9 3
      server/server.go

+ 1 - 1
README.md

@@ -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`

+ 17 - 0
future/future.go

@@ -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
+}

+ 9 - 3
server/server.go

@@ -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 {
-		return err
+		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
 	}