diff --git a/cmd/sealer/cmd/image/build.go b/cmd/sealer/cmd/image/build.go index ecf85837d21..aab2e2d400f 100644 --- a/cmd/sealer/cmd/image/build.go +++ b/cmd/sealer/cmd/image/build.go @@ -27,13 +27,16 @@ import ( "github.com/pkg/errors" "github.com/sealerio/sealer/build/buildimage" "github.com/sealerio/sealer/build/kubefile/parser" + "github.com/sealerio/sealer/common" version2 "github.com/sealerio/sealer/pkg/define/application/version" v12 "github.com/sealerio/sealer/pkg/define/image/v1" bc "github.com/sealerio/sealer/pkg/define/options" + "github.com/sealerio/sealer/pkg/image/save" "github.com/sealerio/sealer/pkg/imageengine" "github.com/sealerio/sealer/pkg/imageengine/buildah" "github.com/sealerio/sealer/pkg/rootfs" v1 "github.com/sealerio/sealer/types/api/v1" + osi "github.com/sealerio/sealer/utils/os" "github.com/sealerio/sealer/version" "github.com/sirupsen/logrus" "github.com/spf13/cobra" @@ -238,7 +241,7 @@ func applyRegistryToImage(imageID, tag, manifest string, platform v1.Platform, e } defer func() { - err = os.RemoveAll(tmpDir) + err := os.RemoveAll(tmpDir) if err != nil { logrus.Warnf("failed to rm link dir to rootfs: %v : %v", tmpDir, err) } @@ -253,6 +256,24 @@ func applyRegistryToImage(imageID, tag, manifest string, platform v1.Platform, e return errors.Wrapf(err, "failed to create working container, imageid: %s", imageID) } + // download container image form `imageList` + if buildFlags.ImageList != "" && osi.IsFileExist(buildFlags.ImageList) { + images, err := osi.NewFileReader(buildFlags.ImageList).ReadLines() + if err != nil { + return err + } + formatImages := buildimage.FormatImages(images) + ctx := context.Background() + imageSave := save.NewImageSaver(ctx) + if err := imageSave.SaveImages(formatImages, filepath.Join(tmpDirForLink, common.RegistryDirName), v1.Platform{ + Architecture: arch, + OS: _os, + Variant: variant, + }); err != nil { + return err + } + } + differ := buildimage.NewRegistryDiffer(v1.Platform{ Architecture: arch, OS: _os, @@ -260,12 +281,12 @@ func applyRegistryToImage(imageID, tag, manifest string, platform v1.Platform, e }) // TODO optimize the differ. - if err = differ.Process(tmpDirForLink, tmpDirForLink); err != nil { + if err := differ.Process(tmpDirForLink, tmpDirForLink); err != nil { return errors.Wrap(err, "failed to download container images") } // download container image form `imageListWithAuth.yaml` - if err = buildimage.NewMiddlewarePuller(v1.Platform{ + if err := buildimage.NewMiddlewarePuller(v1.Platform{ Architecture: arch, OS: _os, Variant: variant,