Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix: add platform value to container image list #2254

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion cmd/sealer/cmd/image/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 9 additions & 1 deletion pkg/image/save/save.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,22 @@ 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, "")
if err != nil {
return fmt.Errorf("failed to parse image name:: %v", err)
}

//check if image exist
//check if image is duplicate
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This judgment may be redundant, as the OCI pull process itself checks for the presence of the image layer.

In addition, there is a risk of misjudgment here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. i wonder there is not redundant.
    for example: input images["nginx:latest","docker.io/library/nginx:latest"], will be transformed ["docker.io/library/nginx:latest","docker.io/library/nginx:latest"], so we need to do deduplication,nothing to do with pull process logic.

  2. what risks here ? sorry i dont understand?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I thought we were doing the duplicate removal in the step of pulling image. Currently, it seems that only for the image name, which is OK

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
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/imagedistributor/scp_distributor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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
}
}
Expand Down