Quellcode durchsuchen

Make sure new repositories can be pushed with multiple tags

Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)
Michael Crosby vor 11 Jahren
Ursprung
Commit
a2aab7757e
2 geänderte Dateien mit 25 neuen und 3 gelöschten Zeilen
  1. 3 0
      registry/registry.go
  2. 22 3
      server.go

+ 3 - 0
registry/registry.go

@@ -205,15 +205,18 @@ func (r *Registry) GetRemoteHistory(imgID, registry string, token []string) ([]s
 }
 
 // Check if an image exists in the Registry
+// TODO: This method should return the errors instead of masking them and returning false
 func (r *Registry) LookupRemoteImage(imgID, registry string, token []string) bool {
 
 	req, err := r.reqFactory.NewRequest("GET", registry+"images/"+imgID+"/json", nil)
 	if err != nil {
+		utils.Errorf("Error in LookupRemoteImage %s", err)
 		return false
 	}
 	setTokenAuth(req, token)
 	res, err := doWithCookies(r.client, req)
 	if err != nil {
+		utils.Errorf("Error in LookupRemoteImage %s", err)
 		return false
 	}
 	res.Body.Close()

+ 22 - 3
server.go

@@ -1263,15 +1263,34 @@ func (srv *Server) pushRepository(r *registry.Registry, out io.Writer, localName
 	var repoData *registry.RepositoryData
 	var imageIndex []*registry.ImgData
 
-	for imgId, tags := range tagsByImage {
-		for _, tag := range tags {
+	for _, imgId := range imgList {
+		if tags, exists := tagsByImage[imgId]; exists {
+			// If an image has tags you must add an entry in the image index
+			// for each tag
+			for _, tag := range tags {
+				imageIndex = append(imageIndex, &registry.ImgData{
+					ID:  imgId,
+					Tag: tag,
+				})
+			}
+		} else {
+			// If the image does not have a tag it still needs to be sent to the
+			// registry with an empty tag so that it is accociated with the repository
 			imageIndex = append(imageIndex, &registry.ImgData{
 				ID:  imgId,
-				Tag: tag,
+				Tag: "",
 			})
+
 		}
 	}
 
+	utils.Debugf("Preparing to push %s with the following images and tags\n", localRepo)
+	for _, data := range imageIndex {
+		utils.Debugf("Pushing ID: %s with Tag: %s\n", data.ID, data.Tag)
+	}
+
+	// Register all the images in a repository with the registry
+	// If an image is not in this list it will not be associated with the repository
 	repoData, err = r.PushImageJSONIndex(remoteName, imageIndex, false, nil)
 	if err != nil {
 		return err