diff --git a/commands.go b/commands.go index 869581c2bb..a0a322afab 100644 --- a/commands.go +++ b/commands.go @@ -442,26 +442,21 @@ func (srv *Server) CmdPush(stdin io.ReadCloser, stdout io.Writer, args ...string img, err := srv.runtime.graph.Get(local) if err != nil { Debugf("The push refers to a repository [%s] (len: %d)\n", local, len(srv.runtime.repositories.Repositories[local])) - // If it fails, try to get the repository if localRepo, exists := srv.runtime.repositories.Repositories[local]; exists { - fmt.Fprintf(stdout, "Pushing %s (%d tags) on %s...\n", local, len(localRepo), remote) if err := srv.runtime.graph.PushRepository(stdout, remote, localRepo, srv.runtime.authConfig); err != nil { return err } - fmt.Fprintf(stdout, "Push completed\n") return nil } else { return err } return nil } - fmt.Fprintf(stdout, "Pushing image %s..\n", img.Id) err = srv.runtime.graph.PushImage(stdout, img, srv.runtime.authConfig) if err != nil { return err } - fmt.Fprintf(stdout, "Push completed\n") return nil } diff --git a/registry.go b/registry.go index 7b879d57b1..1c3a50bcd7 100644 --- a/registry.go +++ b/registry.go @@ -220,7 +220,7 @@ func (graph *Graph) PushImage(stdout io.Writer, imgOrig *Image, authConfig *auth return fmt.Errorf("Error while retreiving the path for {%s}: %s", img.Id, err) } - fmt.Fprintf(stdout, "Pushing image [%s] on {%s}\n", img.Id, REGISTRY_ENDPOINT+"/images/"+img.Id+"/json") + fmt.Fprintf(stdout, "Pushing %s metadata\n", img.Id) // FIXME: try json with UTF8 jsonData := strings.NewReader(string(jsonRaw)) @@ -253,19 +253,16 @@ func (graph *Graph) PushImage(stdout io.Writer, imgOrig *Image, authConfig *auth } } + fmt.Fprintf(stdout, "Pushing %s fs layer\n", img.Id) req2, err := http.NewRequest("PUT", REGISTRY_ENDPOINT+"/images/"+img.Id+"/layer", nil) req2.SetBasicAuth(authConfig.Username, authConfig.Password) res2, err := client.Do(req2) if err != nil || res2.StatusCode != 307 { - return fmt.Errorf( - "Internal server error trying to push image {%s} (layer 1): %s\n", - img.Id, err) + return fmt.Errorf("Registry returned error: %s", err) } url, err := res2.Location() if err != nil || url == nil { - return fmt.Errorf( - "Fail to retrieve layer storage URL for image {%s}: %s\n", - img.Id, err) + return fmt.Errorf("Failed to retrieve layer upload location: %s", err) } // FIXME: Don't do this :D. Check the S3 requierement and implement chunks of 5MB @@ -273,9 +270,7 @@ func (graph *Graph) PushImage(stdout io.Writer, imgOrig *Image, authConfig *auth layerData2, err := Tar(path.Join(graph.Root, img.Id, "layer"), Gzip) layerData, err := Tar(path.Join(graph.Root, img.Id, "layer"), Gzip) if err != nil { - return fmt.Errorf( - "Error while retrieving layer for {%s}: %s\n", - img.Id, err) + return fmt.Errorf("Failed to generate layer archive: %s", err) } req3, err := http.NewRequest("PUT", url.String(), layerData) if err != nil { @@ -356,17 +351,20 @@ func (graph *Graph) LookupRemoteRepository(remote string, authConfig *auth.AuthC return true } +// FIXME: this should really be PushTag func (graph *Graph) pushPrimitive(stdout io.Writer, remote, tag, imgId string, authConfig *auth.AuthConfig) error { // Check if the local impage exists img, err := graph.Get(imgId) if err != nil { - fmt.Fprintf(stdout, "Image %s for tag %s not found, skipping.\n", imgId, tag) + fmt.Fprintf(stdout, "Skipping tag %s:%s: %s does not exist\n", remote, tag, imgId) return nil } + fmt.Fprintf(stdout, "Pushing tag %s:%s\n", remote, tag) // Push the image if err = graph.PushImage(stdout, img, authConfig); err != nil { return err } + fmt.Fprintf(stdout, "Registering tag %s:%s\n", remote, tag) // And then the tag if err = graph.pushTag(remote, imgId, tag, authConfig); err != nil { return err @@ -383,6 +381,7 @@ func (graph *Graph) PushRepository(stdout io.Writer, remote string, localRepo Re // return fmt.Errorf("The remote repository %s does not exist\n", remote) // } + fmt.Fprintf(stdout, "Pushing repository %s (%d tags)\n", remote, len(localRepo)) // For each image within the repo, push them for tag, imgId := range localRepo { if err := graph.pushPrimitive(stdout, remote, tag, imgId, authConfig); err != nil {