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

Add some verbosity to the push/pull

This commit is contained in:
Guillaume J. Charmes 2013-03-22 13:21:44 -07:00
parent 6e35f28352
commit 966cddf26b
2 changed files with 15 additions and 14 deletions

View file

@ -438,7 +438,7 @@ func (srv *Server) CmdPush(stdin io.ReadCloser, stdout io.Writer, args ...string
// If it fails, try to get the repository // If it fails, try to get the repository
if localRepo, exists := srv.runtime.repositories.Repositories[local]; exists { if localRepo, exists := srv.runtime.repositories.Repositories[local]; exists {
fmt.Fprintf(stdout, "Pushing %s (%d tags) on %s...\n", local, len(localRepo), remote) fmt.Fprintf(stdout, "Pushing %s (%d tags) on %s...\n", local, len(localRepo), remote)
if err := srv.runtime.graph.PushRepository(remote, localRepo, srv.runtime.authConfig); err != nil { if err := srv.runtime.graph.PushRepository(stdout, remote, localRepo, srv.runtime.authConfig); err != nil {
return err return err
} }
fmt.Fprintf(stdout, "Push completed\n") fmt.Fprintf(stdout, "Push completed\n")
@ -449,7 +449,7 @@ func (srv *Server) CmdPush(stdin io.ReadCloser, stdout io.Writer, args ...string
return nil return nil
} }
fmt.Fprintf(stdout, "Pushing image %s..\n", img.Id) fmt.Fprintf(stdout, "Pushing image %s..\n", img.Id)
err = srv.runtime.graph.PushImage(img, srv.runtime.authConfig) err = srv.runtime.graph.PushImage(stdout, img, srv.runtime.authConfig)
if err != nil { if err != nil {
return err return err
} }
@ -482,7 +482,7 @@ func (srv *Server) CmdPull(stdin io.ReadCloser, stdout io.Writer, args ...string
} }
// FIXME: Allow pull repo:tag // FIXME: Allow pull repo:tag
fmt.Fprintf(stdout, "Pulling %s...\n", remote) fmt.Fprintf(stdout, "Pulling %s...\n", remote)
if err := srv.runtime.graph.PullRepository(remote, "", srv.runtime.repositories, srv.runtime.authConfig); err != nil { if err := srv.runtime.graph.PullRepository(stdout, remote, "", srv.runtime.repositories, srv.runtime.authConfig); err != nil {
return err return err
} }
fmt.Fprintf(stdout, "Pull completed\n") fmt.Fprintf(stdout, "Pull completed\n")

View file

@ -19,7 +19,7 @@ const REGISTRY_ENDPOINT = auth.REGISTRY_SERVER + "/v1"
func NewImgJson(src []byte) (*Image, error) { func NewImgJson(src []byte) (*Image, error) {
ret := &Image{} ret := &Image{}
fmt.Printf("Json string: {%s}\n", src) Debugf("Json string: {%s}\n", src)
// FIXME: Is there a cleaner way to "puryfy" the input json? // FIXME: Is there a cleaner way to "puryfy" the input json?
src = []byte(strings.Replace(string(src), "null", "\"\"", -1)) src = []byte(strings.Replace(string(src), "null", "\"\"", -1))
@ -161,10 +161,10 @@ func (graph *Graph) PullImage(imgId string, authConfig *auth.AuthConfig) error {
} }
// FIXME: Handle the askedTag parameter // FIXME: Handle the askedTag parameter
func (graph *Graph) PullRepository(remote, askedTag string, repositories *TagStore, authConfig *auth.AuthConfig) error { func (graph *Graph) PullRepository(stdout io.Writer, remote, askedTag string, repositories *TagStore, authConfig *auth.AuthConfig) error {
client := &http.Client{} client := &http.Client{}
fmt.Printf("Pulling repo: %s\n", REGISTRY_ENDPOINT+"/users/"+remote) fmt.Fprintf(stdout, "Pulling repo: %s\n", REGISTRY_ENDPOINT+"/users/"+remote)
req, err := http.NewRequest("GET", REGISTRY_ENDPOINT+"/users/"+remote, nil) req, err := http.NewRequest("GET", REGISTRY_ENDPOINT+"/users/"+remote, nil)
if err != nil { if err != nil {
@ -202,7 +202,7 @@ func (graph *Graph) PullRepository(remote, askedTag string, repositories *TagSto
} }
// Push a local image to the registry with its history if needed // Push a local image to the registry with its history if needed
func (graph *Graph) PushImage(imgOrig *Image, authConfig *auth.AuthConfig) error { func (graph *Graph) PushImage(stdout io.Writer, imgOrig *Image, authConfig *auth.AuthConfig) error {
client := &http.Client{} client := &http.Client{}
// FIXME: Factorize the code // FIXME: Factorize the code
@ -214,7 +214,7 @@ func (graph *Graph) PushImage(imgOrig *Image, authConfig *auth.AuthConfig) error
return fmt.Errorf("Error while retreiving the path for {%s}: %s", img.Id, err) return fmt.Errorf("Error while retreiving the path for {%s}: %s", img.Id, err)
} }
Debugf("Pushing image [%s] on {%s}\n", img.Id, REGISTRY_ENDPOINT+"/images/"+img.Id+"/json") fmt.Fprintf(stdout, "Pushing image [%s] on {%s}\n", img.Id, REGISTRY_ENDPOINT+"/images/"+img.Id+"/json")
// FIXME: try json with UTF8 // FIXME: try json with UTF8
jsonData := strings.NewReader(string(jsonRaw)) jsonData := strings.NewReader(string(jsonRaw))
@ -231,11 +231,12 @@ func (graph *Graph) PushImage(imgOrig *Image, authConfig *auth.AuthConfig) error
"Error: Internal server error trying to push image {%s} (json): %s", "Error: Internal server error trying to push image {%s} (json): %s",
img.Id, err) img.Id, err)
} }
fmt.Printf("Pushing return status: %d\n", res.StatusCode) Debugf("Pushing return status: %d\n", res.StatusCode)
switch res.StatusCode { switch res.StatusCode {
case 204: case 204:
// Case where the image is already on the Registry // Case where the image is already on the Registry
// FIXME: Do not be silent? // FIXME: Do not be silent?
fmt.Fprintf(stdout, "The image %s is already up to date on the registry.\n", img.Id)
return nil return nil
case 400: case 400:
return fmt.Errorf("Error: Invalid Json") return fmt.Errorf("Error: Invalid Json")
@ -324,7 +325,7 @@ func (graph *Graph) pushTag(remote, revision, tag string, authConfig *auth.AuthC
} }
return err return err
} }
fmt.Printf("Result of push tag: %d\n", res.StatusCode) Debugf("Result of push tag: %d\n", res.StatusCode)
switch res.StatusCode { switch res.StatusCode {
default: default:
return fmt.Errorf("Error %d\n", res.StatusCode) return fmt.Errorf("Error %d\n", res.StatusCode)
@ -349,14 +350,14 @@ func (graph *Graph) LookupRemoteRepository(remote string, authConfig *auth.AuthC
return true return true
} }
func (graph *Graph) pushPrimitive(remote, tag, imgId string, authConfig *auth.AuthConfig) error { func (graph *Graph) pushPrimitive(stdout io.Writer, remote, tag, imgId string, authConfig *auth.AuthConfig) error {
// CHeck if the local impage exists // CHeck if the local impage exists
img, err := graph.Get(imgId) img, err := graph.Get(imgId)
if err != nil { if err != nil {
return err return err
} }
// Push the image // Push the image
if err = graph.PushImage(img, authConfig); err != nil { if err = graph.PushImage(stdout, img, authConfig); err != nil {
return err return err
} }
// And then the tag // And then the tag
@ -368,7 +369,7 @@ func (graph *Graph) pushPrimitive(remote, tag, imgId string, authConfig *auth.Au
// Push a repository to the registry. // Push a repository to the registry.
// Remote has the format '<user>/<repo> // Remote has the format '<user>/<repo>
func (graph *Graph) PushRepository(remote string, localRepo Repository, authConfig *auth.AuthConfig) error { func (graph *Graph) PushRepository(stdout io.Writer, remote string, localRepo Repository, authConfig *auth.AuthConfig) error {
// Check if the remote repository exists // Check if the remote repository exists
// FIXME: @lopter How to handle this? // FIXME: @lopter How to handle this?
// if !graph.LookupRemoteRepository(remote, authConfig) { // if !graph.LookupRemoteRepository(remote, authConfig) {
@ -377,7 +378,7 @@ func (graph *Graph) PushRepository(remote string, localRepo Repository, authConf
// For each image within the repo, push them // For each image within the repo, push them
for tag, imgId := range localRepo { for tag, imgId := range localRepo {
if err := graph.pushPrimitive(remote, tag, imgId, authConfig); err != nil { if err := graph.pushPrimitive(stdout, remote, tag, imgId, authConfig); err != nil {
// FIXME: Continue on error? // FIXME: Continue on error?
return err return err
} }