mirror of
				https://github.com/linuxkit/linuxkit.git
				synced 2025-10-30 16:40:25 +00:00 
			
		
		
		
	Merge pull request #3810 from giggsoff/do-not-pull-another-arch
Do not pull another arch and index cleanup
This commit is contained in:
		
							
								
								
									
										15
									
								
								src/cmd/linuxkit/cache/pull.go
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										15
									
								
								src/cmd/linuxkit/cache/pull.go
									
									
									
									
										vendored
									
									
								
							| @@ -54,12 +54,15 @@ func (p *Provider) ValidateImage(ref *reference.Spec, architecture string) (lkts | |||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			return ImageSource{}, fmt.Errorf("could not get index manifest: %v", err) | 			return ImageSource{}, fmt.Errorf("could not get index manifest: %v", err) | ||||||
| 		} | 		} | ||||||
| 		// we found a local index, just make sure it is up to date and, if not, download it |  | ||||||
| 		if err := validate.Index(imageIndex); err != nil { |  | ||||||
| 			return ImageSource{}, errors.New("invalid index") |  | ||||||
| 		} |  | ||||||
| 		for _, m := range im.Manifests { | 		for _, m := range im.Manifests { | ||||||
| 			if m.Platform != nil && m.Platform.Architecture == architecture && m.Platform.OS == "linux" { | 			if m.Platform != nil && m.Platform.Architecture == architecture && m.Platform.OS == linux { | ||||||
|  | 				img, err := imageIndex.Image(m.Digest) | ||||||
|  | 				if err != nil { | ||||||
|  | 					return ImageSource{}, fmt.Errorf("unable to get image: %v", err) | ||||||
|  | 				} | ||||||
|  | 				if err := validate.Image(img); err != nil { | ||||||
|  | 					return ImageSource{}, fmt.Errorf("invalid image: %s", err) | ||||||
|  | 				} | ||||||
| 				return p.NewSource( | 				return p.NewSource( | ||||||
| 					ref, | 					ref, | ||||||
| 					architecture, | 					architecture, | ||||||
| @@ -71,7 +74,7 @@ func (p *Provider) ValidateImage(ref *reference.Spec, architecture string) (lkts | |||||||
| 	case image != nil: | 	case image != nil: | ||||||
| 		// we found a local image, make sure it is up to date, and that it matches our platform | 		// we found a local image, make sure it is up to date, and that it matches our platform | ||||||
| 		if err := validate.Image(image); err != nil { | 		if err := validate.Image(image); err != nil { | ||||||
| 			return ImageSource{}, errors.New("invalid image") | 			return ImageSource{}, fmt.Errorf("invalid image, %s", err) | ||||||
| 		} | 		} | ||||||
| 		return p.NewSource( | 		return p.NewSource( | ||||||
| 			ref, | 			ref, | ||||||
|   | |||||||
							
								
								
									
										6
									
								
								src/cmd/linuxkit/cache/push.go
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										6
									
								
								src/cmd/linuxkit/cache/push.go
									
									
									
									
										vendored
									
									
								
							| @@ -6,6 +6,7 @@ import ( | |||||||
| 	"github.com/google/go-containerregistry/pkg/authn" | 	"github.com/google/go-containerregistry/pkg/authn" | ||||||
| 	namepkg "github.com/google/go-containerregistry/pkg/name" | 	namepkg "github.com/google/go-containerregistry/pkg/name" | ||||||
| 	"github.com/google/go-containerregistry/pkg/v1/remote" | 	"github.com/google/go-containerregistry/pkg/v1/remote" | ||||||
|  | 	"github.com/google/go-containerregistry/pkg/v1/validate" | ||||||
| 	"github.com/linuxkit/linuxkit/src/cmd/linuxkit/registry" | 	"github.com/linuxkit/linuxkit/src/cmd/linuxkit/registry" | ||||||
| 	imagespec "github.com/opencontainers/image-spec/specs-go/v1" | 	imagespec "github.com/opencontainers/image-spec/specs-go/v1" | ||||||
| 	log "github.com/sirupsen/logrus" | 	log "github.com/sirupsen/logrus" | ||||||
| @@ -98,6 +99,11 @@ func (p *Provider) Push(name string) error { | |||||||
| 					return fmt.Errorf("could not find or create arch-specific image for %s: %v", archTag, err) | 					return fmt.Errorf("could not find or create arch-specific image for %s: %v", archTag, err) | ||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
|  | 			if err := validate.Image(img); err != nil { | ||||||
|  | 				// skip arch we did not build/pull locally | ||||||
|  | 				log.Debugf("could not validate arch-specific image for %s: %v", archTag, err) | ||||||
|  | 				continue | ||||||
|  | 			} | ||||||
| 			log.Debugf("pushing image %s", tag) | 			log.Debugf("pushing image %s", tag) | ||||||
| 			if err := remote.Tag(tag, img, options...); err != nil { | 			if err := remote.Tag(tag, img, options...); err != nil { | ||||||
| 				return fmt.Errorf("error creating tag %s: %v", archTag, err) | 				return fmt.Errorf("error creating tag %s: %v", archTag, err) | ||||||
|   | |||||||
							
								
								
									
										31
									
								
								src/cmd/linuxkit/cache/write.go
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										31
									
								
								src/cmd/linuxkit/cache/write.go
									
									
									
									
										vendored
									
									
								
							| @@ -28,9 +28,14 @@ const ( | |||||||
| 	linux = "linux" | 	linux = "linux" | ||||||
| ) | ) | ||||||
|  |  | ||||||
| // ImagePull takes an image name and pulls it down, writing it locally. It should be | // ImagePull takes an image name and ensures that the image manifest or index to which it refers | ||||||
| // efficient and only write missing blobs, based on their content hash. If the ref already | // exists in local cache and, if not, pulls it from the registry and writes it locally. It should be | ||||||
| // exists in the cache, it will niot pull anything, unless alwaysPull is set to true. | // efficient and only write missing blobs, based on their content hash. | ||||||
|  | // It will only pull the actual blobs, config and manifest for the requested architectures, even if ref | ||||||
|  | // points to an index with multiple architectures. If the ref and all of the content for the requested | ||||||
|  | // architectures already exist in the cache, it will not pull anything, unless alwaysPull is set to true. | ||||||
|  | // If you call it multiple times, even with different architectures, the ref will continue to point to the same index. | ||||||
|  | // Only the underlying content will be added. | ||||||
| func (p *Provider) ImagePull(ref *reference.Spec, trustedRef, architecture string, alwaysPull bool) (lktspec.ImageSource, error) { | func (p *Provider) ImagePull(ref *reference.Spec, trustedRef, architecture string, alwaysPull bool) (lktspec.ImageSource, error) { | ||||||
| 	image := ref.String() | 	image := ref.String() | ||||||
| 	pullImageName := image | 	pullImageName := image | ||||||
| @@ -69,7 +74,25 @@ func (p *Provider) ImagePull(ref *reference.Spec, trustedRef, architecture strin | |||||||
| 	ii, err := desc.ImageIndex() | 	ii, err := desc.ImageIndex() | ||||||
| 	if err == nil { | 	if err == nil { | ||||||
| 		log.Debugf("ImageWrite retrieved %s is index, saving", pullImageName) | 		log.Debugf("ImageWrite retrieved %s is index, saving", pullImageName) | ||||||
| 		err = p.cache.ReplaceIndex(ii, match.Name(image), layout.WithAnnotations(annotations)) | 		im, err := ii.IndexManifest() | ||||||
|  | 		if err != nil { | ||||||
|  | 			return ImageSource{}, fmt.Errorf("unable to get IndexManifest: %v", err) | ||||||
|  | 		} | ||||||
|  | 		_, err = p.IndexWrite(ref, im.Manifests...) | ||||||
|  | 		if err == nil { | ||||||
|  | 			for _, m := range im.Manifests { | ||||||
|  | 				if m.MediaType.IsImage() && (m.Platform == nil || m.Platform.Architecture == architecture) { | ||||||
|  | 					img, err := ii.Image(m.Digest) | ||||||
|  | 					if err != nil { | ||||||
|  | 						return ImageSource{}, fmt.Errorf("unable to get image: %v", err) | ||||||
|  | 					} | ||||||
|  | 					err = p.cache.WriteImage(img) | ||||||
|  | 					if err != nil { | ||||||
|  | 						return ImageSource{}, fmt.Errorf("unable to write image: %v", err) | ||||||
|  | 					} | ||||||
|  | 				} | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
| 	} else { | 	} else { | ||||||
| 		var im v1.Image | 		var im v1.Image | ||||||
| 		// try an image | 		// try an image | ||||||
|   | |||||||
| @@ -231,15 +231,18 @@ func (p Pkg) Build(bos ...BuildOpt) error { | |||||||
|  |  | ||||||
| 	skipBuild := bo.skipBuild | 	skipBuild := bo.skipBuild | ||||||
| 	if !bo.force { | 	if !bo.force { | ||||||
|  | 		notFound := false | ||||||
| 		fmt.Fprintf(writer, "checking for %s in local cache, fallback to remote registry...\n", ref) | 		fmt.Fprintf(writer, "checking for %s in local cache, fallback to remote registry...\n", ref) | ||||||
| 		if _, err := c.ImagePull(&ref, "", arch, false); err == nil { | 		for _, platform := range bo.platforms { | ||||||
| 			fmt.Fprintf(writer, "%s found or pulled\n", ref) | 			if _, err := c.ImagePull(&ref, "", platform.Architecture, false); err == nil { | ||||||
| 			skipBuild = true | 				fmt.Fprintf(writer, "%s found or pulled\n", ref) | ||||||
| 		} else { | 				skipBuild = true | ||||||
| 			fmt.Fprintf(writer, "%s not found\n", ref) | 			} else { | ||||||
|  | 				fmt.Fprintf(writer, "%s not found: %s\n", ref, err) | ||||||
|  | 				notFound = true | ||||||
|  | 			} | ||||||
| 		} | 		} | ||||||
| 		if bo.targetDocker { | 		if bo.targetDocker { | ||||||
| 			notFound := false |  | ||||||
| 			for _, platform := range bo.platforms { | 			for _, platform := range bo.platforms { | ||||||
| 				archRef, err := reference.Parse(fmt.Sprintf("%s-%s", p.FullTag(), platform.Architecture)) | 				archRef, err := reference.Parse(fmt.Sprintf("%s-%s", p.FullTag(), platform.Architecture)) | ||||||
| 				if err != nil { | 				if err != nil { | ||||||
| @@ -250,7 +253,7 @@ func (p Pkg) Build(bos ...BuildOpt) error { | |||||||
| 					fmt.Fprintf(writer, "%s found or pulled\n", archRef) | 					fmt.Fprintf(writer, "%s found or pulled\n", archRef) | ||||||
| 					skipBuild = true | 					skipBuild = true | ||||||
| 				} else { | 				} else { | ||||||
| 					fmt.Fprintf(writer, "%s not found\n", archRef) | 					fmt.Fprintf(writer, "%s not found: %s\n", archRef, err) | ||||||
| 					notFound = true | 					notFound = true | ||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user