Skip to content

Commit 8e41a35

Browse files
committed
saving container image optional
Signed-off-by: HIHIA <[email protected]>
1 parent f9cc112 commit 8e41a35

File tree

2 files changed

+27
-23
lines changed

2 files changed

+27
-23
lines changed

Diff for: cmd/sealer/cmd/image/build.go

+10-7
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ func NewBuildCmd() *cobra.Command {
9292
buildCmd.Flags().StringSliceVar(&buildFlags.Annotations, "annotation", []string{}, "add annotations for image. Format like --annotation key=[value]")
9393
buildCmd.Flags().StringSliceVar(&buildFlags.Labels, "label", []string{getSealerLabel()}, "add labels for image. Format like --label key=[value]")
9494
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.")
95+
buildCmd.Flags().BoolVarP(&buildFlags.DownloadContainerImage, "download-container-image", "lite", true, "save the container image generated during the build process.")
9596

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

162163
defer func() {
163-
for _, m := range []string{tempTag} {
164-
// the above image is intermediate image, we need to remove it when the build ends.
165-
if err := engine.RemoveImage(&bc.RemoveImageOptions{
166-
ImageNamesOrIDs: []string{m},
167-
Force: true,
168-
}); err != nil {
169-
logrus.Debugf("failed to remove image %s, you need to remove it manually: %v", m, err)
164+
if buildFlags.DownloadContainerImage {
165+
for _, m := range []string{tempTag} {
166+
// the above image is intermediate image, we need to remove it when the build ends.
167+
if err := engine.RemoveImage(&bc.RemoveImageOptions{
168+
ImageNamesOrIDs: []string{m},
169+
Force: true,
170+
}); err != nil {
171+
logrus.Debugf("failed to remove image %s, you need to remove it manually: %v", m, err)
172+
}
170173
}
171174
}
172175
}()

Diff for: pkg/define/options/options.go

+17-16
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,23 @@ package options
1616

1717
// BuildOptions should be out of buildah scope.
1818
type BuildOptions struct {
19-
Kubefile string
20-
ContextDir string
21-
PullPolicy string
22-
ImageType string
23-
Manifest string
24-
Tag string
25-
BuildArgs []string
26-
Platforms []string
27-
Labels []string
28-
Annotations []string
29-
NoCache bool
30-
Base bool
31-
Tags []string
32-
Platform string
33-
ImageList string
34-
ImageListWithAuth string
19+
Kubefile string
20+
ContextDir string
21+
PullPolicy string
22+
ImageType string
23+
Manifest string
24+
Tag string
25+
BuildArgs []string
26+
Platforms []string
27+
Labels []string
28+
Annotations []string
29+
NoCache bool
30+
Base bool
31+
Tags []string
32+
Platform string
33+
ImageList string
34+
ImageListWithAuth string
35+
DownloadContainerImage bool
3536
}
3637

3738
type FromOptions struct {

0 commit comments

Comments
 (0)