Sfoglia il codice sorgente

* Registry: Use the size to have a good progress bar while pushing
* Registry: Use the actual archive if it exists in order to speed up the push
+ Registry: Remove the archive if it exists after the push

Guillaume J. Charmes 12 anni fa
parent
commit
80f4b0df75
1 ha cambiato i file con 32 aggiunte e 3 eliminazioni
  1. 32 3
      registry.go

+ 32 - 3
registry.go

@@ -10,6 +10,7 @@ import (
 	"io/ioutil"
 	"net/http"
 	"net/url"
+	"os"
 	"path"
 	"strings"
 )
@@ -425,6 +426,7 @@ func pushImageRec(graph *Graph, stdout io.Writer, img *Image, registry string, t
 		return fmt.Errorf("Error while retrieving checksum for %s: %v", img.Id, err)
 	}
 	req.Header.Set("X-Docker-Checksum", checksum)
+	Debugf("Setting checksum for %s: %s", img.ShortId(), checksum)
 	res, err := doWithCookies(client, req)
 	if err != nil {
 		return fmt.Errorf("Failed to upload metadata: %s", err)
@@ -450,14 +452,36 @@ func pushImageRec(graph *Graph, stdout io.Writer, img *Image, registry string, t
 	}
 
 	fmt.Fprintf(stdout, "Pushing %s fs layer\r\n", img.Id)
+	root, err := img.root()
+	if err != nil {
+		return err
+	}
+
+	var layerData *TempArchive
 
-	layerData, err := graph.TempLayerArchive(img.Id, Xz, stdout)
+	// If the archive exists, use it
+	file, err := os.Open(layerArchivePath(root))
 	if err != nil {
-		return fmt.Errorf("Failed to generate layer archive: %s", err)
+		if os.IsNotExist(err) {
+			// If the archive does not exist, create one from the layer
+			layerData, err = graph.TempLayerArchive(img.Id, Xz, stdout)
+			if err != nil {
+				return fmt.Errorf("Failed to generate layer archive: %s", err)
+			}
+		} else {
+			return err
+		}
+	} else {
+		defer file.Close()
+		st, err := file.Stat()
+		if err != nil {
+			return err
+		}
+		layerData = &TempArchive{file, st.Size()}
 	}
 
 	req3, err := http.NewRequest("PUT", registry+"/images/"+img.Id+"/layer",
-		ProgressReader(layerData, -1, stdout, ""))
+		ProgressReader(layerData, int(layerData.Size), stdout, ""))
 	if err != nil {
 		return err
 	}
@@ -479,6 +503,11 @@ func pushImageRec(graph *Graph, stdout io.Writer, img *Image, registry string, t
 		}
 		return fmt.Errorf("Received HTTP code %d while uploading layer: %s", res3.StatusCode, errBody)
 	}
+
+	// If we pushed an archive, then remove it, we don't need it anymore
+	if err := os.Remove(layerArchivePath(root)); err != nil {
+		return err
+	}
 	return nil
 }