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

saving container image optional #1851

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
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.")
Copy link
Collaborator

@starnop starnop Nov 15, 2022

Choose a reason for hiding this comment

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

how about adding a new flag like buildMode?

And different build mode means different logic of execution


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