|
@@ -2,6 +2,7 @@ package docker
|
|
|
|
|
|
import (
|
|
import (
|
|
"fmt"
|
|
"fmt"
|
|
|
|
+ "github.com/dotcloud/docker/auth"
|
|
"github.com/dotcloud/docker/registry"
|
|
"github.com/dotcloud/docker/registry"
|
|
"github.com/dotcloud/docker/utils"
|
|
"github.com/dotcloud/docker/utils"
|
|
"io"
|
|
"io"
|
|
@@ -67,6 +68,7 @@ func (srv *Server) ImagesSearch(term string) ([]ApiSearch, error) {
|
|
}
|
|
}
|
|
|
|
|
|
func (srv *Server) ImageInsert(name, url, path string, out io.Writer) error {
|
|
func (srv *Server) ImageInsert(name, url, path string, out io.Writer) error {
|
|
|
|
+ out = utils.NewWriteFlusher(out)
|
|
img, err := srv.runtime.repositories.LookupImage(name)
|
|
img, err := srv.runtime.repositories.LookupImage(name)
|
|
if err != nil {
|
|
if err != nil {
|
|
return err
|
|
return err
|
|
@@ -288,6 +290,7 @@ func (srv *Server) ContainerTag(name, repo, tag string, force bool) error {
|
|
}
|
|
}
|
|
|
|
|
|
func (srv *Server) pullImage(out io.Writer, imgId, registry string, token []string) error {
|
|
func (srv *Server) pullImage(out io.Writer, imgId, registry string, token []string) error {
|
|
|
|
+ out = utils.NewWriteFlusher(out)
|
|
history, err := srv.registry.GetRemoteHistory(imgId, registry, token)
|
|
history, err := srv.registry.GetRemoteHistory(imgId, registry, token)
|
|
if err != nil {
|
|
if err != nil {
|
|
return err
|
|
return err
|
|
@@ -322,8 +325,9 @@ func (srv *Server) pullImage(out io.Writer, imgId, registry string, token []stri
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
-func (srv *Server) pullRepository(stdout io.Writer, remote, askedTag string) error {
|
|
|
|
- utils.Debugf("Retrieving repository data")
|
|
|
|
|
|
+func (srv *Server) pullRepository(out io.Writer, remote, askedTag string) error {
|
|
|
|
+ out = utils.NewWriteFlusher(out)
|
|
|
|
+ fmt.Fprintf(out, "Pulling repository %s from %s\r\n", remote, auth.IndexServerAddress())
|
|
repoData, err := srv.registry.GetRepositoryData(remote)
|
|
repoData, err := srv.registry.GetRepositoryData(remote)
|
|
if err != nil {
|
|
if err != nil {
|
|
return err
|
|
return err
|
|
@@ -360,11 +364,11 @@ func (srv *Server) pullRepository(stdout io.Writer, remote, askedTag string) err
|
|
utils.Debugf("%s does not match %s, skipping", img.Tag, askedTag)
|
|
utils.Debugf("%s does not match %s, skipping", img.Tag, askedTag)
|
|
continue
|
|
continue
|
|
}
|
|
}
|
|
- fmt.Fprintf(stdout, "Pulling image %s (%s) from %s\n", img.Id, img.Tag, remote)
|
|
|
|
|
|
+ fmt.Fprintf(out, "Pulling image %s (%s) from %s\n", img.Id, img.Tag, remote)
|
|
success := false
|
|
success := false
|
|
for _, ep := range repoData.Endpoints {
|
|
for _, ep := range repoData.Endpoints {
|
|
- if err := srv.pullImage(stdout, img.Id, "https://"+ep+"/v1", repoData.Tokens); err != nil {
|
|
|
|
- fmt.Fprintf(stdout, "Error while retrieving image for tag: %s (%s); checking next endpoint\n", askedTag, err)
|
|
|
|
|
|
+ if err := srv.pullImage(out, img.Id, "https://"+ep+"/v1", repoData.Tokens); err != nil {
|
|
|
|
+ fmt.Fprintf(out, "Error while retrieving image for tag: %s (%s); checking next endpoint\n", askedTag, err)
|
|
continue
|
|
continue
|
|
}
|
|
}
|
|
if err := srv.runtime.repositories.Set(remote, img.Tag, img.Id, true); err != nil {
|
|
if err := srv.runtime.repositories.Set(remote, img.Tag, img.Id, true); err != nil {
|
|
@@ -476,6 +480,7 @@ func (srv *Server) getImageList(localRepo map[string]string) ([]*registry.ImgDat
|
|
}
|
|
}
|
|
|
|
|
|
func (srv *Server) pushRepository(out io.Writer, name string, localRepo map[string]string) error {
|
|
func (srv *Server) pushRepository(out io.Writer, name string, localRepo map[string]string) error {
|
|
|
|
+ out = utils.NewWriteFlusher(out)
|
|
fmt.Fprintf(out, "Processing checksums\n")
|
|
fmt.Fprintf(out, "Processing checksums\n")
|
|
imgList, err := srv.getImageList(localRepo)
|
|
imgList, err := srv.getImageList(localRepo)
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -515,6 +520,7 @@ func (srv *Server) pushRepository(out io.Writer, name string, localRepo map[stri
|
|
}
|
|
}
|
|
|
|
|
|
func (srv *Server) pushImage(out io.Writer, remote, imgId, ep string, token []string) error {
|
|
func (srv *Server) pushImage(out io.Writer, remote, imgId, ep string, token []string) error {
|
|
|
|
+ out = utils.NewWriteFlusher(out)
|
|
jsonRaw, err := ioutil.ReadFile(path.Join(srv.runtime.graph.Root, imgId, "json"))
|
|
jsonRaw, err := ioutil.ReadFile(path.Join(srv.runtime.graph.Root, imgId, "json"))
|
|
if err != nil {
|
|
if err != nil {
|
|
return fmt.Errorf("Error while retreiving the path for {%s}: %s", imgId, err)
|
|
return fmt.Errorf("Error while retreiving the path for {%s}: %s", imgId, err)
|
|
@@ -574,6 +580,7 @@ func (srv *Server) pushImage(out io.Writer, remote, imgId, ep string, token []st
|
|
}
|
|
}
|
|
|
|
|
|
func (srv *Server) ImagePush(name, registry string, out io.Writer) error {
|
|
func (srv *Server) ImagePush(name, registry string, out io.Writer) error {
|
|
|
|
+ out = utils.NewWriteFlusher(out)
|
|
img, err := srv.runtime.graph.Get(name)
|
|
img, err := srv.runtime.graph.Get(name)
|
|
if err != nil {
|
|
if err != nil {
|
|
fmt.Fprintf(out, "The push refers to a repository [%s] (len: %d)\n", name, len(srv.runtime.repositories.Repositories[name]))
|
|
fmt.Fprintf(out, "The push refers to a repository [%s] (len: %d)\n", name, len(srv.runtime.repositories.Repositories[name]))
|
|
@@ -610,7 +617,7 @@ func (srv *Server) ImageImport(src, repo, tag string, in io.Reader, out io.Write
|
|
u.Host = src
|
|
u.Host = src
|
|
u.Path = ""
|
|
u.Path = ""
|
|
}
|
|
}
|
|
- fmt.Fprintln(out, "Downloading from", u)
|
|
|
|
|
|
+ fmt.Fprintf(out, "Downloading from %s\n", u)
|
|
// Download with curl (pretty progress bar)
|
|
// Download with curl (pretty progress bar)
|
|
// If curl is not available, fallback to http.Get()
|
|
// If curl is not available, fallback to http.Get()
|
|
resp, err = utils.Download(u.String(), out)
|
|
resp, err = utils.Download(u.String(), out)
|
|
@@ -629,7 +636,7 @@ func (srv *Server) ImageImport(src, repo, tag string, in io.Reader, out io.Write
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- fmt.Fprintln(out, img.ShortId())
|
|
|
|
|
|
+ fmt.Fprintf(out, "%s\n", img.ShortId())
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|