From 1eb801b3786b0591a7fabc22f3951122604bf7e1 Mon Sep 17 00:00:00 2001 From: kakzhou719 Date: Mon, 26 Jun 2023 18:55:14 +0800 Subject: [PATCH] bugfix: add platform to container image list; skip download duplicate container image;add some debug logs Signed-off-by: kakzhou719 --- cmd/sealer/cmd/image/build.go | 10 +++++++++- pkg/image/save/save.go | 10 +++++++++- pkg/imagedistributor/scp_distributor.go | 2 ++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/cmd/sealer/cmd/image/build.go b/cmd/sealer/cmd/image/build.go index 1d2d4a205df..f2d35df6c63 100644 --- a/cmd/sealer/cmd/image/build.go +++ b/cmd/sealer/cmd/image/build.go @@ -323,7 +323,15 @@ func applyRegistryToImage(engine imageengine.Interface, imageID string, platform if err != nil { return "", nil, errors.Wrap(err, "failed to parse container image list") } - containerImageList = append(containerImageList, parsedContainerImageList...) + for _, image := range parsedContainerImageList { + logrus.Debugf("get container image(%s) with platform(%s) from build context", + image.Image, platform.ToString()) + containerImageList = append(containerImageList, &v12.ContainerImage{ + Image: image.Image, + AppName: image.AppName, + Platform: &platform, + }) + } // ignored image list if buildFlags.IgnoredImageList != "" && osi.IsFileExist(buildFlags.IgnoredImageList) { diff --git a/pkg/image/save/save.go b/pkg/image/save/save.go index 86f10398bee..072ce8906d7 100644 --- a/pkg/image/save/save.go +++ b/pkg/image/save/save.go @@ -71,6 +71,7 @@ func (is *DefaultImageSaver) SaveImages(images []string, dir string, platform v1 } }() + existFlag := make(map[string]struct{}) //handle image name for _, image := range images { named, err := ParseNormalizedNamed(image, "") @@ -78,7 +79,14 @@ func (is *DefaultImageSaver) SaveImages(images []string, dir string, platform v1 return fmt.Errorf("failed to parse image name:: %v", err) } - //check if image exist + //check if image is duplicate + if _, exist := existFlag[named.FullName()]; exist { + continue + } else { + existFlag[named.FullName()] = struct{}{} + } + + //check if image exist in disk if err := is.isImageExist(named, dir, platform); err == nil { continue } diff --git a/pkg/imagedistributor/scp_distributor.go b/pkg/imagedistributor/scp_distributor.go index e0e5938f6c1..f3032b0f088 100644 --- a/pkg/imagedistributor/scp_distributor.go +++ b/pkg/imagedistributor/scp_distributor.go @@ -67,6 +67,7 @@ func (s *scpDistributor) DistributeRegistry(deployHosts []net.IP, dataDir string } if existed { + logrus.Debugf("cache %s hits on: %s, skip to do distribution", info.ImageID, tmpDeployHost.String()) return nil } } @@ -121,6 +122,7 @@ func (s *scpDistributor) Distribute(hosts []net.IP, dest string) error { } if existed { + logrus.Debugf("cache %s hits on: %s, skip to do distribution", info.ImageID, host.String()) return nil } }