mirror of
				https://github.com/linuxkit/linuxkit.git
				synced 2025-10-31 01:37:42 +00:00 
			
		
		
		
	do not push if the tag and digest are identical
Signed-off-by: Avi Deitcher <avi@deitcher.net>
This commit is contained in:
		
							
								
								
									
										22
									
								
								src/cmd/linuxkit/cache/push.go
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										22
									
								
								src/cmd/linuxkit/cache/push.go
									
									
									
									
										vendored
									
									
								
							| @@ -29,16 +29,38 @@ func (p *Provider) Push(name string) error { | |||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
| 	options = append(options, remote.WithAuthFromKeychain(authn.DefaultKeychain)) | 	options = append(options, remote.WithAuthFromKeychain(authn.DefaultKeychain)) | ||||||
|  |  | ||||||
| 	img, err1 := root.Image() | 	img, err1 := root.Image() | ||||||
| 	ii, err2 := root.ImageIndex() | 	ii, err2 := root.ImageIndex() | ||||||
|  | 	// before we even try to push, let us see if it exists remotely | ||||||
|  | 	remoteOptions := []remote.Option{remote.WithAuthFromKeychain(authn.DefaultKeychain)} | ||||||
|  |  | ||||||
| 	switch { | 	switch { | ||||||
| 	case err1 == nil: | 	case err1 == nil: | ||||||
|  | 		dig, err := img.Digest() | ||||||
|  | 		if err != nil { | ||||||
|  | 			return fmt.Errorf("could not get digest for image %s: %v", name, err) | ||||||
|  | 		} | ||||||
|  | 		desc, err := remote.Get(ref, remoteOptions...) | ||||||
|  | 		if err == nil && desc != nil && dig == desc.Digest { | ||||||
|  | 			fmt.Printf("%s image already available on remote registry, skipping push", name) | ||||||
|  | 			return nil | ||||||
|  | 		} | ||||||
| 		log.Debugf("pushing image %s", name) | 		log.Debugf("pushing image %s", name) | ||||||
| 		if err := remote.Write(ref, img, options...); err != nil { | 		if err := remote.Write(ref, img, options...); err != nil { | ||||||
| 			return err | 			return err | ||||||
| 		} | 		} | ||||||
| 		fmt.Printf("Pushed image %s\n", name) | 		fmt.Printf("Pushed image %s\n", name) | ||||||
| 	case err2 == nil: | 	case err2 == nil: | ||||||
|  | 		dig, err := ii.Digest() | ||||||
|  | 		if err != nil { | ||||||
|  | 			return fmt.Errorf("could not get digest for index %s: %v", name, err) | ||||||
|  | 		} | ||||||
|  | 		desc, err := remote.Get(ref, remoteOptions...) | ||||||
|  | 		if err == nil && desc != nil && dig == desc.Digest { | ||||||
|  | 			fmt.Printf("%s index already available on remote registry, skipping push", name) | ||||||
|  | 			return nil | ||||||
|  | 		} | ||||||
| 		log.Debugf("pushing index %s", name) | 		log.Debugf("pushing index %s", name) | ||||||
| 		// this is an index, so we not only want to write the index, but tags for each arch-specific image in it | 		// this is an index, so we not only want to write the index, but tags for each arch-specific image in it | ||||||
| 		if err := remote.WriteIndex(ref, ii, options...); err != nil { | 		if err := remote.WriteIndex(ref, ii, options...); err != nil { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user