Skip to content

Commit

Permalink
saving container image optional
Browse files Browse the repository at this point in the history
Signed-off-by: HIHIA <283304489@qq.com>
  • Loading branch information
YTGhost committed Nov 12, 2022
1 parent f9cc112 commit a834725
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 23 deletions.
21 changes: 14 additions & 7 deletions cmd/sealer/cmd/image/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ func NewBuildCmd() *cobra.Command {
buildCmd.Flags().StringSliceVar(&buildFlags.Annotations, "annotation", []string{}, "add annotations for image. Format like --annotation key=[value]")
buildCmd.Flags().StringSliceVar(&buildFlags.Labels, "label", []string{getSealerLabel()}, "add labels for image. Format like --label key=[value]")
buildCmd.Flags().BoolVar(&buildFlags.NoCache, "no-cache", false, "do not use existing cached images for building. Build from the start with a new set of cached layers.")
buildCmd.Flags().BoolVarP(&buildFlags.DownloadContainerImage, "download-container-image", "d", true, "save the container image generated during the build process.")

supportedImageType := map[string]struct{}{v12.KubeInstaller: {}, v12.AppInstaller: {}}
if _, ok := supportedImageType[buildFlags.ImageType]; !ok {
Expand Down Expand Up @@ -160,13 +161,15 @@ func buildSealerImage() error {
}

defer func() {
for _, m := range []string{tempTag} {
// the above image is intermediate image, we need to remove it when the build ends.
if err := engine.RemoveImage(&bc.RemoveImageOptions{
ImageNamesOrIDs: []string{m},
Force: true,
}); err != nil {
logrus.Debugf("failed to remove image %s, you need to remove it manually: %v", m, err)
if !buildFlags.DownloadContainerImage {
for _, m := range []string{tempTag} {
// the above image is intermediate image, we need to remove it when the build ends.
if err := engine.RemoveImage(&bc.RemoveImageOptions{
ImageNamesOrIDs: []string{m},
Force: true,
}); err != nil {
logrus.Debugf("failed to remove image %s, you need to remove it manually: %v", m, err)
}
}
}
}()
Expand Down Expand Up @@ -229,6 +232,10 @@ func commitSingleImage(iid string, tag string, engine imageengine.Interface) err
}

func applyRegistryToImage(imageID, tag, manifest string, platform v1.Platform, engine imageengine.Interface) error {
if !buildFlags.DownloadContainerImage {
return nil
}

_os, arch, variant := platform.OS, platform.Architecture, platform.Variant
// this temporary file is used to execute image pull, and save it to /registry.
// engine.BuildRootfs will generate an image rootfs, and link the rootfs to temporary dir(temp sealer rootfs).
Expand Down
33 changes: 17 additions & 16 deletions pkg/define/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,23 @@ package options

// BuildOptions should be out of buildah scope.
type BuildOptions struct {
Kubefile string
ContextDir string
PullPolicy string
ImageType string
Manifest string
Tag string
BuildArgs []string
Platforms []string
Labels []string
Annotations []string
NoCache bool
Base bool
Tags []string
Platform string
ImageList string
ImageListWithAuth string
Kubefile string
ContextDir string
PullPolicy string
ImageType string
Manifest string
Tag string
BuildArgs []string
Platforms []string
Labels []string
Annotations []string
NoCache bool
Base bool
Tags []string
Platform string
ImageList string
ImageListWithAuth string
DownloadContainerImage bool
}

type FromOptions struct {
Expand Down

0 comments on commit a834725

Please sign in to comment.