Skip to content

Commit

Permalink
saving container image optional
Browse files Browse the repository at this point in the history
  • Loading branch information
YTGhost committed Nov 11, 2022
1 parent f9cc112 commit 23dcc5a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 23 deletions.
17 changes: 10 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", "lite", 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
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 23dcc5a

Please sign in to comment.