瀏覽代碼

Cleaned up UI of 'docker push'

Solomon Hykes 12 年之前
父節點
當前提交
b31211cbe9
共有 2 個文件被更改,包括 10 次插入16 次删除
  1. 0 5
      commands.go
  2. 10 11
      registry.go

+ 0 - 5
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)
 	img, err := srv.runtime.graph.Get(local)
 	if err != nil {
 	if err != nil {
 		Debugf("The push refers to a repository [%s] (len: %d)\n", local, len(srv.runtime.repositories.Repositories[local]))
 		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 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)
 			if err := srv.runtime.graph.PushRepository(stdout, 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")
 			return nil
 			return nil
 		} else {
 		} else {
 			return err
 			return err
 		}
 		}
 		return nil
 		return nil
 	}
 	}
-	fmt.Fprintf(stdout, "Pushing image %s..\n", img.Id)
 	err = srv.runtime.graph.PushImage(stdout, img, srv.runtime.authConfig)
 	err = srv.runtime.graph.PushImage(stdout, img, srv.runtime.authConfig)
 	if err != nil {
 	if err != nil {
 		return err
 		return err
 	}
 	}
-	fmt.Fprintf(stdout, "Push completed\n")
 	return nil
 	return nil
 }
 }
 
 

+ 10 - 11
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)
 			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
 		// FIXME: try json with UTF8
 		jsonData := strings.NewReader(string(jsonRaw))
 		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, err := http.NewRequest("PUT", REGISTRY_ENDPOINT+"/images/"+img.Id+"/layer", nil)
 		req2.SetBasicAuth(authConfig.Username, authConfig.Password)
 		req2.SetBasicAuth(authConfig.Username, authConfig.Password)
 		res2, err := client.Do(req2)
 		res2, err := client.Do(req2)
 		if err != nil || res2.StatusCode != 307 {
 		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()
 		url, err := res2.Location()
 		if err != nil || url == nil {
 		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
 		// 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)
 		layerData2, err := Tar(path.Join(graph.Root, img.Id, "layer"), Gzip)
 		layerData, err := Tar(path.Join(graph.Root, img.Id, "layer"), Gzip)
 		layerData, err := Tar(path.Join(graph.Root, img.Id, "layer"), Gzip)
 		if err != nil {
 		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)
 		req3, err := http.NewRequest("PUT", url.String(), layerData)
 		if err != nil {
 		if err != nil {
@@ -356,17 +351,20 @@ func (graph *Graph) LookupRemoteRepository(remote string, authConfig *auth.AuthC
 	return true
 	return true
 }
 }
 
 
+// FIXME: this should really be PushTag
 func (graph *Graph) pushPrimitive(stdout io.Writer, 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 {
-		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
 		return nil
 	}
 	}
+	fmt.Fprintf(stdout, "Pushing tag %s:%s\n", remote, tag)
 	// Push the image
 	// Push the image
 	if err = graph.PushImage(stdout, img, authConfig); err != nil {
 	if err = graph.PushImage(stdout, img, authConfig); err != nil {
 		return err
 		return err
 	}
 	}
+	fmt.Fprintf(stdout, "Registering tag %s:%s\n", remote, tag)
 	// And then the tag
 	// And then the tag
 	if err = graph.pushTag(remote, imgId, tag, authConfig); err != nil {
 	if err = graph.pushTag(remote, imgId, tag, authConfig); err != nil {
 		return err
 		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)
 	// 	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 each image within the repo, push them
 	for tag, imgId := range localRepo {
 	for tag, imgId := range localRepo {
 		if err := graph.pushPrimitive(stdout, remote, tag, imgId, authConfig); err != nil {
 		if err := graph.pushPrimitive(stdout, remote, tag, imgId, authConfig); err != nil {